查询中的多个字段在C ++ Builder 6中不起作用 [英] Multiple fields in query don't work in C++ Builder 6

查看:96
本文介绍了查询中的多个字段在C ++ Builder 6中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 C ++ Builder 6 ,并且要查询MySQL数据库表中的多个字段/列。



比方说,我有一个名为 users的表,并且我的表具有 id, name, username和 password字段。请检查以下示例:

  query = SELECT name FROM users;; // WORKS 

query = SELECT名称,用户名FROM users;; //仅适用于第一个字段 name

query = SELECT * FROM users;; // //不起作用:给我EAccessViolation

query =从用户中选择名称UNION从用户中选择用户名;; //但这不是解决方案

到目前为止,我其余的代码几乎是我在指南中找到的。。 p>

我可以同时查询多个字段吗?



完整代码:

 字符串查询; 

outputMemo-> ClearSelection();


//问题查询!!!
query = SELECT * FROM users;;


试试{
SQLQuery1-> SQL-> Text =查询;
SQLQuery1-> Active = true;
}
catch(Exception& E){
outputMemo-> Text =消息引发异常 + E.Message;
}


//在TMemo控件中显示查询结果。

TStringList *列表;
TField * currentField;
字符串currentLine;

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

而(!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 =消息引发异常 + E.Message;
}

list-> Free();
}

在此先感谢您的帮助和时间。

解决方案

我发现问题是MySQL的dbExpress驱动程序错误。 Dll dbxopenmysql50.dll 可能仅适用于MySQL v5.0。 用于MySQL的DevArt dbExpress驱动程序可用于高于MySQL v5.0的版本。


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

Let's say, I have a table named "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 I found in this guide.

Could I query more than 1 field at the same 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.

解决方案

I found that the problem was the wrong dbExpress Driver for MySQL. Dll dbxopenmysql50.dll might work right only with MySQL v5.0. DevArt dbExpress Driver for MySQL could be used for higher versions than v5.0 of MySQL.

这篇关于查询中的多个字段在C ++ Builder 6中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆