Forum > Databases
SQL query to ODBC fails from my application, while fine from ODBC query tool
Vodnik:
Hello,
This fragment of code cause exception:
try
FormDB.DBquery.Close;
FormDB.DBquery.SQL.text:='select (INTERVAL(0:0:0) HOUR TO second + callend UNITS second) from callrecord;';
FormDB.DBquery.Open;
StatusBar.SimpleText:='Data read from DB';
except
on E: Exception do begin
FormDB.DBquery.Close;
CheckBoxConnected.Checked:=False;
StatusBar.SimpleText:=E.message;
ShowMessage(E.message);
end;
end;
while the same SQL query
select (INTERVAL(0:0:0) HOUR TO second + callend UNITS second) from callrecord;
works fine from SQL query tool with the same DSN.
Error text:
Could not prepare statement. ODBC error details: LastReturnCode: SQL_ERROR; Could not get error message: An invalid parameter was passed to SQLGetDiagRec/Field
Lazarus 1.8.0, FPC 3.0.4 x32, Windows 7, DB Informix via ODBC.
rvk:
Did you setup the TODBCConnection correctly?
Could you press "Connected" in the object inspector of that ODBCConnection1 and make it active?
Vodnik:
Yes, it work fine with other SQL queries, e.g.
FormDB.DBquery.SQL.text:='select callid as Call_ID, callstart as Call_Start, callend as Duration, origin as Calling_Num, origindestination as Called_Num, (callstart + sitetzoffset units minute) as Call_Start, callend as Duration from callrecord';
successfully produce output for DBGrid
rvk:
Ok, then it must be the statement.
I find INTERVAL(0:0:0) a really strange SQL-term (but I'm not familiar with DB Informix).
If FPC is trying to parse that, it could stumble too.
You could try setting ParseSQL to false.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---FormDB.DBquery.ParseSQL := false;FormDB.DBquery.Open;
taazz:
--- Quote from: rvk on March 06, 2018, 04:37:32 pm ---Ok, then it must be the statement.
I find INTERVAL(0:0:0) a really strange SQL-term (but I'm not familiar with DB Informix).
If FPC is trying to parse that, it could stumble too.
You could try setting ParseSQL to false.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---FormDB.DBquery.ParseSQL := false;FormDB.DBquery.Open;
--- End quote ---
+1
The colon character <:> is used to define parameters in sql by SQLDB is it possible to enclose the 0:0:0 in quotes or something along those lines? Setting ParseSQL to false might help but I'm not sure.
Navigation
[0] Message Index
[#] Next page