Subject Re: [IBO] ExecuteImmediate
Author Maik Wojcieszak
The examples in the ib API Reference did not say anything
about setting the sqld value ;-(

Thanks for that hint - now my function work in a way
but I have an dsql error wich sometimes apear sometimes not.
I cannot see at the moment why this happens.

does somebody know about this ?

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;

On Mon, 6 Jan 2003 13:39:44 -0700, Jason Wharton wrote:

>You need to set the sqld value as well as the sqln.
>In fact, I think sqld is more important.
>
>sqln is to track how many columns are in the structure and sqld tells how
>many are actually intended for use in the execute. This would allow you to
>have a structure defined with more column places but separately tell that
>only some of them are intended for use.
>
>Regards,
>Jason Wharton
>CPS - Mesa AZ
>http://www.ibobjects.com
>
>-- We may not have it all together --
>-- But together we have it all --
>
>
>----- Original Message -----
>From: "Maik Wojcieszak" <mw@...>
>To: <IBObjects@yahoogroups.com>
>Sent: Monday, January 06, 2003 12:16 PM
>Subject: [IBO] ExecuteImmediate
>
>
>> Hi,
>>
>> can anyone give me an example using IBStatement.ExecuteImmediate
>> with input parameters ?
>>
>> in_sqlda := AllocMem( XSQLDA_LENGTH( 1 ));
>> in_sqlda.version := SQLDA_VERSION1;
>> in_sqlda.sqln := 1;
>>
>> val := 'Blah';
>> in_sqlda.sqlvar[0].sqldata := PChar(Val);
>> in_sqlda.sqlvar[0].sqltype := SQL_TEXT;
>> in_sqlda.sqlvar[0].sqllen := Length(val);
>>
>> dsql.ExecuteImmediate('INSERT INTO FILE_BENCHMARK_TAB (TEST) VALUES
>( ? )',
>> in_sqlda);
>>
>> does not work ( invalid type or number of parameters)
>>
>> thanks,
>> maik
>>
>> -------------------------------------------------
>> Maik Wojcieszak
>>
>> wobe-team (http://www.wobe-team.com)
>>
>
>
>
>___________________________________________________________________________
>IB Objects - direct, complete, custom connectivity to Firebird or InterBase
> without the need for BDE, ODBC or any other layer.
>___________________________________________________________________________
>http://www.ibobjects.com - your IBO community resource for Tech Info papers,
>keyword-searchable FAQ, community code contributions and more !
>
>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


-------------------------------------------------
Maik Wojcieszak

wobe-team (http://www.wobe-team.com)