Subject Re: [ib-support] Re: dsql error using execute_Immediate
Author Maik Wojcieszak
Thanks for that help. I found the solution for my problem.
Your code was helpfull for me to see If what I did was not
that wrong.

Indeed it was the memory handling GetMem did not
work - it produced that error sometimes I changed it
to AllocMem that seems to work.

regards,
maik

--Original Message Text---
From: "nitaligavino"
Date: Thu, 09 Jan 2003 15:41:00 -0000

Hello:

I looked for error 303 also and, like you said, did not find any
information on this. I hope this information is not not to much out
of context!

What does the SQL statement look like that you are passing to
isc_dsql_execute_immediate( )? Also, how many parameters are you
passing and do the types match with the column types? e.g., parameter
1 is an integer, column 1 is an integer.

Is your XSQLDA structure being allocated correctly?
Here is a function that I use to allocate an XSQLDA object:

bool IBDatabase::Helper_AllocCS(XSQLDA **pDataObj, AT_CUSHORT
usFields)
{
// Allocate control storage in bytes
if(usFields > 0 && (*pDataObj = (XSQLDA *)new char
[XSQLDA_LENGTH(usFields)]))
{
// Fill in the version and size
(*pDataObj)->version = SQLDA_VERSION1;
(*pDataObj)->sqln = usFields; // Number of
elements in sqlvar array
(*pDataObj)->sqld = usFields; // Number of
parameters pointed to

// Clear the sql variants being pointed to so we have
a known state
memset((void *)(*pDataObj)->sqlvar, 0, (usFields *
sizeof(XSQLVAR)));
return(true);
}

return(false);
}

If my SQL statement has say, two parameters, then I would call this
function like:

XSQLDA *pParam = 0;
const unsigned short usParamCount(2);
Helper_AllocCS(&pParam, usParamCount);


Also how are you formatting your XSQLVAR structures?
Here is an example of how I set and XSQLVAR object to represent an
integer, SQL_LONG:

const AT_SqlVariantIf &IBVariant::SetAsInteger(AT_CLONG lValue)
{
// Just delete any memory previously allocated
Helper_FreeVS();

// Allocate and set the data
if((m_ibData.sqldata = new char[sizeof(long)]))
{
m_ibData.sqltype = AT_SQLVAR_INTEGER; //
defined as SQL_LONG
m_ibData.sqllen = sizeof(long);

// Cast the char * to a type
*(long *)m_ibData.sqldata = lValue;
}

return(*this);
}

m_ibData is of type XSQLVAR.

If I needed to set the SQL_LONG as NULL then I would do:

m_ibData.sqltype = AT_SQLVAR_INTEGER + 1;
m_ibData.sqllen = sizeof(long);
m_ibData.sqlind = new short;
*m_ibData.sqlind = -1;

Dan


--- In ib-support@yahoogroups.com, "Maik Wojcieszak" <mw@w...> wrote:
> 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;
>
>
>
>
>
>
>
> -------------------------------------------------
> Maik Wojcieszak
>
> wobe-team (http://www.wobe-team.com)


To unsubscribe from this group, send an email to:
ib-support-unsubscribe@egroups.com



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.





[Non-text portions of this message have been removed]