gpt4 book ai didi

mysql - Delphi EDataBaseError - 不支持的操作。我该如何解决?

转载 作者:行者123 更新时间:2023-11-29 06:14:56 25 4
gpt4 key购买 nike

我正在尝试从 MySQL5 数据库查询数据,但是当我使用 SQL 代码中的一些其他功能时,返回以下错误:[0x0005]:不支持操作。

我的SQL代码查询:

Select 
s.nome, s.id_sistema, s.st_sis
from
perm_usuar as p
inner join
sistemas as s
on
s.id_sistema = p.id_sistema
where
p.id_usuario = "' + idusuario + '"'

当我不使用这些功能时,它也能正常工作:

Select 
sistemas.nome, sistemas.id_sistema, sistemas.st_sis
from
perm_usuar
inner join
sistemas
on
sistemas.id_sistema = perm_usuar.id_sistema
where
perm_usuar.id_usuario = "' + idusuario + '"'

此外,如果我尝试使用连接表的 WHERE,我会得到同样的错误...我在 Delphi XE8 上使用 DBExpress,具有以下组件:SQLConnection、SQLDataSet 和 SQLQuery。

当我直接在 MySQL 上使用代码时,它工作正常。

为什么会被退回,有什么解决办法?

最佳答案

我找到了解决方案!问题出在 SQLQuery1.RecordCount 上。据我所知,dbExpress 是单向的,因此 RecordCount 为它带来了资源,但也有其局限性(您可以在此处查看:http://edn.embarcadero.com/ru/article/28494)

之前(返回错误):

 SQL1.SQL.Clear;
SQL1.SQL.Add(CodigoMYSQL);
SQL1.Open;
SQL1.First;
cont := SQL1.RecordCount; //have limitations
if cont > 0 then // check
begin
for i := 1 to cont do //loop in
begin
for ii := 0 to NValue do
result[ii].Add(SQL1.Fields[ii].AsString);
SQL1.Next;
end;
end;
SQL1.Close;

** SQL1 = SQLQuery1

之后(解决):

 SQL1.SQL.Clear;
SQL1.SQL.Add(CodigoMYSQL);
SQL1.Open;
SQL1.First;
if not SQL1.IsEmpty then //check
begin
ii := 0;
while not SQL1.Eof do //till the end
begin
for ii := 0 to NValue do
result[ii].Add(SQL1.Fields[ii].AsString);
SQL1.Next;
inc(ii);
end;
end;
SQL1.Close;

现在我可以使用更复杂的 SQL 代码和函数。

关于mysql - Delphi EDataBaseError - 不支持的操作。我该如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36405599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com