Subject
Author Maik Wojcieszak
Hi,

This is the first time I'm writing a function using the interbase api
data structures directly and have some trouble putting the xsqlda
together correctly for the Integer datatype.

The following error occurs not everytime I use the function but
sometimes it pops up without a reason I can reproduce at the moment.

SQL Error -303

I cannot find this number in my interbase documentation.

ISC ERROR CODE:335544569 - dynamic sql error

ISC ERROR CODE:335544436 - sql error code <long>

can anyone give me a hint what I do wrong ?

thanks in advance
maik



The error is reported as:

2003 Jan 08 10:33:34:WPS:CTL:SQL Error: -303
2003 Jan 08 10:33:34:WPS:--- ISC ERROR CODE:335544569
2003 Jan 08 10:33:34:WPS:---
2003 Jan 08 10:33:34:WPS:--- ISC ERROR MESSAGE:
2003 Jan 08 10:33:34:WPS:--- Dynamic SQL Error
2003 Jan 08 10:33:34:WPS:--- SQL error code = -303
2003 Jan 08 10:33:34:WPS:--- arithmetic exception, numeric overflow, or string truncation
2003 Jan 08 10:33:34:WPS:---
STATEMENT:
TIB_DSQL: "<TIB_DSQL>."

2003 Jan 08 10:33:34:WPS:CTL:Error Codes : 335544569
2003 Jan 08 10:33:34:WPS:--- 335544569
2003 Jan 08 10:33:34:WPS:--- 1
2003 Jan 08 10:33:34:WPS:--- 335544436
2003 Jan 08 10:33:34:WPS:--- 4
2003 Jan 08 10:33:34:WPS:CTL:SQL Message :
2003 Jan 08 10:33:34:WPS:--- SQL ERROR CODE:-303
2003 Jan 08 10:33:34:WPS:---
2003 Jan 08 10:33:34:WPS:--- SQL ERROR MESSAGE:
2003 Jan 08 10:33:34:WPS:--- Incompatible column/host variable data type
2003 Jan 08 10:33:34:WPS:CTL:SQL :

The function reporting this error declares the variable XSQLDA and
sql as.

var
imageid : longint;
datid : longint;
list_id : longint;
ImgFile : TFileStream;
mdsql : TIB_DSQL;
sqlt : string;
blob_id : ISC_QUAD;
index : integer;
in_sqlda : PXSQLDA;
nullind : smallint;
_fname,_ext : string;
begin

// the query
sqlt := 'UPDATE ORIG_FILE_TAB SET OFILE_DATA = ?,FILE_NAME = ?,FILE_EXT = ?,INPUT_LIST_ID = ? WHERE OFILEID = ?';
nullind := 0;

// open FileTab
ImgFile := TFileStream.Create(FileName, fmOpenRead);
imageid := ResolveObjImageID(CurrentObject);
datid := ResolveOrgImageID(imageid);
list_id := plist;

// inialize dsql object
mdsql := TIB_DSQL.Create(nil);

with mdsql do begin
IB_Connection := _ProdBase;
IB_Transaction := _ScriptTransaction;
OnError := _OnIBError;

try
GetMem(in_sqlda, XSQLDA_LENGTH( 5 ));
blob_id := WriteBlobToDB(ImgFile,mdsql);

in_sqlda.version := SQLDA_VERSION1;
in_sqlda.sqln := 5;
in_sqlda.sqld := 5;

// set the parameters
index := 0;
with in_sqlda.sqlvar[ index ] do begin
sqltype := SQL_BLOB+1;
sqldata := @blob_id;
sqlsubtype := 0;
sqllen := sizeof(ISC_QUAD);
sqlind := @nullind;
end;

index := 1;
_fname := ExtractFileName(filename);
with in_sqlda.sqlvar[index] do begin
sqltype := SQL_TEXT+1;
sqldata := PCHAR(_fname);
sqllen := Length(_fname);
sqlind := @nullind;
end;

index := 2;
_ext := ExtractFileExt(filename);
with in_sqlda.sqlvar[index] do begin
sqltype := SQL_TEXT+1;
sqldata := PCHAR(_ext);
sqllen := Length(_ext);
sqlind := @nullind;
end;

index := 3;
with in_sqlda.sqlvar[index] do begin
sqltype := SQL_LONG+1;
sqldata := @list_id;
sqllen := 4;
sqlind := @nullind;
end;

index := 4;
with in_sqlda.sqlvar[index] do begin
sqltype := SQL_LONG+1;
sqldata := @datid;
sqllen := 4;
sqlind := @nullind;
end;

ExecuteImmediate(sqlt,in_sqlda);
finally
ImgFile.Free;
FreeMem(in_sqlda);
mdsql.Destroy;
end;

end;
end;