Multiple fields in request do not work in C ++ Builder 6

I am using C ++ Builder 6 and I want to query more than one field / column in my query on the table of my MySQL database.

Let's say I have a table called "users" and my table has the fields "id", "name", "username" and "password". Please check the following examples:

query = "SELECT name FROM users;";  // WORKS

query = "SELECT name, username FROM users;";  // WORKS ONLY FOR THE 1ST FIELD "name"

query = "SELECT * FROM users;";  // DOESN'T WORK: GIVES ME EAccessViolation

query = "SELECT name FROM users UNION SELECT username FROM users;";  // WORKS BUT IT ISN'T A SOLUTION

So far, the rest of my code is almost the same as in this guide .

Can I request more than one field at a time?

FULL CODE:

String query;

outputMemo->ClearSelection();


// PROBLEMATIC QUERY !!!
query = "SELECT * FROM users;";


try {
  SQLQuery1->SQL->Text = query;
  SQLQuery1->Active = true;
}
catch (Exception& E) {
  outputMemo->Text = "Exception raised with message" + E.Message;
}


// Show the results of the query in a TMemo control.

TStringList *list;
TField      *currentField;
String      currentLine;

if (!SQLQuery1->IsEmpty()) {
  SQLQuery1->First();
  list = new TStringList;
  __try {
    SQLQuery1->GetFieldNames(list);

    while (!SQLQuery1->Eof) {
      currentLine = "";
      for (int i=0; i<list->Count; i++) {
        currentField = SQLQuery1->FieldByName(list->Strings[i]);
        currentLine = currentLine + " " + currentField->AsString;
      }

      outputMemo->Lines->Add( currentLine.c_str() );
      SQLQuery1->Next();
    }
  }
  catch (Exception& E) {
    outputMemo->Text = "Exception raised with message" + E.Message;
  }

  list->Free();
}

Thank you in advance for your help and your time.

0
source share
2 answers

, dbExpress MySQL. Dll dbxopenmysql50.dll MySQL v5.0. DevArt dbExpress MySQL , 5.0 MySQL.

0

, , SQLite, MySQL, .

, .

MySQL , MySQL api, ODBC MySQL .

0

All Articles