Assigning value to BLOB parameter (IB vs mssql vs Oracle)
Posted: Wed 28 Sep 2011 17:43
Background:
We are moving a suite of tools from D7 to D2010 and changing from dbexpress connections to unidac-based connections.
With the same software we support IB, FB, MSSQL & Oracle.
The bear is dealing with all the datatype differences and trying to
how to write code that works for all the dbs.
------------------------------
q: tuniquery;
s: string;
First just want to fill a BLOB with the contents of a string var
s:='hello to the entire world.';
q.SQL.add('update email_pending set body_data= :data where id=10');
q.parambyname('data').asblob:= bytesof(s);
q.ExecSQL;
//Interbase WORKS
//sql server WORKS
//oracle DOESNT WORK - EMPTIES THE BLOB
--(try again)
s:='hello to the entire world.';
q.SQL.add('update email_pending set body_data= :data where id=10');
q.parambyname('data').asblob:= bytesof(s);
q.parambyname('data').paramtype:=ptInput;
q.ExecSQL;
//Interbase WORKS
//sql server WORKS
//oracle WORKS only if the paramtype is set
> I am looking for the most consistent code across databases.
> Is this the accepted method? Using bytesof() and having
> to add an additional line in the Oracle case?
------------------------------------------------
Now filling the BLOB with the contents of a file
s:='C:\bd\delphi2010\work\myimages\cash.bmp';
q.SQL.add('update email_pending set body_data= :data where id=10');
q.parambyname('data').loadfromfile(s,ftblob);
q.parambyname('data').paramtype:=ptInput;
q.ExecSQL;
//Interbase WORKS
//sql server WORKS
//oracle DOESNT WORK field still empty
--(try again)
s:='C:\bd\delphi2010\work\myimages\cash.bmp';
q.SQL.add('update email_pending set body_data= :data where id=10');
q.parambyname('data').loadfromfile(s,ftORAblob);
q.parambyname('data').paramtype:=ptInput;
q.ExecSQL;
//Interbase DOESNT WORK
//sql server DOESNT WORK
//oracle WORKS only if paramtype is manually set
> Again I am looking for the most consistent code across databases.
> Is this the accepted method? Literally Coding a different datatype
> when connected to an Oracle db?
> In the past, With the dbexpress tsqlquery and such we would
> use xxx.asblob:= 'anystringatall' for all three cases,
> and ftorablob was not needed for oracle file load.
Thank you for your knowledge and time,
tonyM
We are moving a suite of tools from D7 to D2010 and changing from dbexpress connections to unidac-based connections.
With the same software we support IB, FB, MSSQL & Oracle.
The bear is dealing with all the datatype differences and trying to
how to write code that works for all the dbs.
------------------------------
q: tuniquery;
s: string;
First just want to fill a BLOB with the contents of a string var
s:='hello to the entire world.';
q.SQL.add('update email_pending set body_data= :data where id=10');
q.parambyname('data').asblob:= bytesof(s);
q.ExecSQL;
//Interbase WORKS
//sql server WORKS
//oracle DOESNT WORK - EMPTIES THE BLOB
--(try again)
s:='hello to the entire world.';
q.SQL.add('update email_pending set body_data= :data where id=10');
q.parambyname('data').asblob:= bytesof(s);
q.parambyname('data').paramtype:=ptInput;
q.ExecSQL;
//Interbase WORKS
//sql server WORKS
//oracle WORKS only if the paramtype is set
> I am looking for the most consistent code across databases.
> Is this the accepted method? Using bytesof() and having
> to add an additional line in the Oracle case?
------------------------------------------------
Now filling the BLOB with the contents of a file
s:='C:\bd\delphi2010\work\myimages\cash.bmp';
q.SQL.add('update email_pending set body_data= :data where id=10');
q.parambyname('data').loadfromfile(s,ftblob);
q.parambyname('data').paramtype:=ptInput;
q.ExecSQL;
//Interbase WORKS
//sql server WORKS
//oracle DOESNT WORK field still empty
--(try again)
s:='C:\bd\delphi2010\work\myimages\cash.bmp';
q.SQL.add('update email_pending set body_data= :data where id=10');
q.parambyname('data').loadfromfile(s,ftORAblob);
q.parambyname('data').paramtype:=ptInput;
q.ExecSQL;
//Interbase DOESNT WORK
//sql server DOESNT WORK
//oracle WORKS only if paramtype is manually set
> Again I am looking for the most consistent code across databases.
> Is this the accepted method? Literally Coding a different datatype
> when connected to an Oracle db?
> In the past, With the dbexpress tsqlquery and such we would
> use xxx.asblob:= 'anystringatall' for all three cases,
> and ftorablob was not needed for oracle file load.
Thank you for your knowledge and time,
tonyM