简体   繁体   English

Delphi / Query组件-将长字符串(800个字符)分配给sql.text属性,将SQL修剪为仅326个字符

[英]Delphi/Query component - assign a long string (800 char) to a sql.text property trim the sql to 326 char only

I use Delphi/NexusDB and I build SQL (about 800 char long) at run time then I pass it to the nexusdb query.sql.text property to execute it but I found error of invalid token on execution. 我使用Delphi / NexusDB,并在运行时构建SQL(大约800个字符长),然后将其传递给nexusdb query.sql.text属性以执行它,但执行时发现无效令牌的错误。

I pass SQL like this 我这样传递SQL

Query.SQL.Text := VarStrSQL; // <<---- string variable holding the SQL

when I traced I found SQL string in the Query.SQL.Text is trimmed to 326 character !! 当我跟踪时,我发现Query.SQL.Text中的SQL字符串被修剪为326个字符! While the string variable that hold the SQL is complete and fine but when I assign that variable to query.sql.text only 326 character passed and of course this result in an error for invalid SQL syntax 虽然保存SQL的字符串变量是完整且正常的,但是当我将该变量分配给query.sql.text时,仅传递了326个字符,这当然会导致无效的SQL语法错误

Please advise why the SQL string trimmed like that ? 请告知为什么要像这样修剪SQL字符串?

Update: * I tried memo1.lines.text := VarStrSQL and the memo component also display the string trimmed !! 更新: * 我试过memo1.lines.text:= VarStrSQL,备忘录组件也显示修剪过的字符串! is it possible a character in my string cause that !! 我的字符串中的一个字符有可能导致!! a bug in Delphi 2010 that cause TStrings to trim my string ? Delphi 2010中的错误导致TStrings修剪我的字符串? * *

Thanks 谢谢

Sounds like a bug in DB provider itself. 听起来像数据库提供程序本身中的错误。 There is no such limitation in TQuery . TQuery没有这样的限制。

My advice shall be to use small SQL, but bound parameters to set the data. 我的建议是使用小型SQL,但使用绑定参数来设置数据。

Instead of 代替

Query.SQL.Text := 'INSERT INTO Store_Information (store_name, Sales, Date)
VALUES ('Los Angeles ... ... ...', 900, '10-Jan-1999')';

code

Query.FieldByName('store').AsString := 'Los Angeles ... ... ...'; // here you should have no limitation
Query.FieldByName('sales').AsInteger := 900;
Query.FIeldByName('Date').AsDAteTime := Now;
Query.SQL.Text := 'INSERT INTO Store_Information (store_name, Sales, Date)
VALUES (:store,:sales,:date)';

And your request will be faster, since the statement could be preparated by the engine, then reused. 而且您的请求将更快,因为该语句可以由引擎准备,然后再使用。

I found the problem: It is nxtChar Fields when they are null they have the value #0 and that cause string trimming 我发现了问题:nxtChar字段为空时它们的值为#0并导致字符串修剪

however although I check for null like this varisnull() the char fields was able to skip this trap function !!! 但是,尽管我像varisnull()一样检查null,但是char字段能够跳过此陷阱函数! which makes me go around myself for hours finally I now check them like this 终于让我自己绕了几个小时,现在我像这样检查他们

If <nxtChar field> = #0 then <nxtChar field> = '' (or <nxtChar field> = null)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM