Discussion:
[SQLQuery]Error while running Query!?
(too old to reply)
Ahmadi
2008-07-17 19:00:39 UTC
Permalink
Hi
Im trying to insert a big string to my table:
var Value:String;
begin
...
Value:='My Big String, It Dont contain character 39 or other control
characters, but it contain characters between 150..255';
SQLQuery.SQL.Add('insert into mytable(a) values('+value+');');
SQLQuery.ExecSQL(true);
...
end;
I have access violation error !!! i don't know why? however if i run the
query command directly in my DMBS Manager, the insert command have no error
and can run successfully.

Thanks for any help
--
~~~~~~~~~~~
Best Regards
H.Ahmadi
Bill Todd [TeamB]
2008-07-17 21:51:11 UTC
Permalink
Post by Ahmadi
SQLQuery.SQL.Add('insert into mytable(a) values('+value+');');
SQLQuery.SQL.Add('insert into mytable(a) values('+ QuotedStr(value) +
');');
--
Bill Todd (TeamB)
Ahmadi
2008-07-17 22:29:44 UTC
Permalink
Post by Bill Todd [TeamB]
SQLQuery.SQL.Add('insert into mytable(a) values('+ QuotedStr(value) +
');');
Im sorry "Bill Todd [TeamB]" , i only forgot to write in my post QuotedStr,
however in my code QuotedStr exists, and with it i have the error .
Here is a pure copy of my code:

procedure TCEngineForm.runQuery(command:string);
var SQLQuery:TSQLQuery;
kind:string;
function firstToken(s:string):String;
var t:string;
i: Integer;
begin
t:='';
for i := 1 to length(s) do
if s[i]=' ' then
break
else
t:=t+s[i];
result:=t;
end;
begin
SQLQuery:=TSQLQuery.Create(nil);
SQLQuery.SQLConnection:=CEngineForm.SQLConnection1;
try
SQLQuery.SQL.add(command);
addLineToFile('c:\a.txt',command);
kind:=firstToken(command);
try
SQLQuery.ExecSQL(true);
except
on e:exception do log('Error while running '+kind+' query
('+e.message+')');
end;
finally
SQLQuery.Free;
end;
end;
Ahmadi
2008-07-17 22:32:19 UTC
Permalink
Here is my caller sample code:
...
values:=QuotedStr(myID)+',getDate()'+','+QuotedStr('My Big String that
generated by one function');
command:='insert into ClientsChanges(ID,ChangeTime,Changes)
Values('+values+');';
CEngineForm.runQuery(command);
...
--
~~~~~~~~~~~
Best Regards
H.Ahmadi
Post by Ahmadi
Post by Bill Todd [TeamB]
SQLQuery.SQL.Add('insert into mytable(a) values('+ QuotedStr(value) +
');');
Im sorry "Bill Todd [TeamB]" , i only forgot to write in my post
QuotedStr, however in my code QuotedStr exists, and with it i have the
error .
procedure TCEngineForm.runQuery(command:string);
var SQLQuery:TSQLQuery;
kind:string;
function firstToken(s:string):String;
var t:string;
i: Integer;
begin
t:='';
for i := 1 to length(s) do
if s[i]=' ' then
break
else
t:=t+s[i];
result:=t;
end;
begin
SQLQuery:=TSQLQuery.Create(nil);
SQLQuery.SQLConnection:=CEngineForm.SQLConnection1;
try
SQLQuery.SQL.add(command);
addLineToFile('c:\a.txt',command);
kind:=firstToken(command);
try
SQLQuery.ExecSQL(true);
except
on e:exception do log('Error while running '+kind+' query
('+e.message+')');
end;
finally
SQLQuery.Free;
end;
end;
Bill Todd [TeamB]
2008-07-18 00:18:09 UTC
Permalink
I assume that somewhere there is a call to ExecSQL and it is that line
that causes the AV.
--
Bill Todd (TeamB)
Ahmadi
2008-07-18 10:05:48 UTC
Permalink
However problem solved, Thanks for your attention.
--
~~~~~~~~~~~
Best Regards
H.Ahmadi
Post by Bill Todd [TeamB]
I assume that somewhere there is a call to ExecSQL and it is that line
that causes the AV.
--
Bill Todd (TeamB)
Ahmadi
2008-07-18 00:22:22 UTC
Permalink
Problem solved,
If anyone have the same error same as me, read following line, im success to
solve the error after some hours ! :
Please check your string that you are adding to SQLQuery.SQL lines, because
if it contain #0, SQLQuery will throw error!
In my situation, the data loaded from external resources and for this reason
i did not detect that #0 is in my field value string that im trying to
insert to mytable.
--
~~~~~~~~~~~
Best Regards
H.Ahmadi
Post by Ahmadi
Hi
var Value:String;
begin
...
Value:='My Big String, It Dont contain character 39 or other control
characters, but it contain characters between 150..255';
SQLQuery.SQL.Add('insert into mytable(a) values('+value+');');
SQLQuery.ExecSQL(true);
...
end;
I have access violation error !!! i don't know why? however if i run the
query command directly in my DMBS Manager, the insert command have no
error and can run successfully.
Thanks for any help
--
~~~~~~~~~~~
Best Regards
H.Ahmadi
Loading...