OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
RE: How to insert binary data into LONG column ?

From: Schroeder, Alexander (alexander.schroedersap.com)
Date: Tue Jan 11 2005 - 07:50:33 CST


Hello Claus,

you have to use odbc_prepare/odbc_execute for any LONG data of
serious length. There are limitation in the length of LONG
literals.

Aside from this, literals for BYTE columns are specified like
x'0023AABB' (see the hex literal definition at
http://dev.mysql.com/doc/maxdb/en/64/e90daaa60f11d2a97100a0c9449261/content.htm).

And, finally, if you use MaxDB with PHP, I have to endorse the new
PHP interface for MaxDB. See the interface page at
http://dev.mysql.com/doc/maxdb/interfaces.html , in the section
PHP. It is designed to be compatible with the 'mysqli'
PHP extension.

Regards
Alexander Schröder
SAP DB, SAP Labs Berlin

> -----Original Message-----
> From: Claus Windeler [mailto:cwnwt.de]
> Sent: Tuesday, January 11, 2005 1:14 PM
> To: maxdblists.mysql.com
> Subject: How to insert binary data into LONG column ?
>
>
> Hello!
>
> I already spend several days to solve maybe a very simple
> problem. I just want
> to insert the binary data of a file into a LONG column of my database.
>
> I am working on Windows 2003 Server with PHP 5.0.3 and ODBC.
>
> MaxDB version: 7.5.0.19
> MaxDB Windows-ODBC driver version: 7.5.0.19
>
> I tried the following:
>
> $filedata = file_get_contents('test.data');
>
> $query = 'INSERT INTO myfiles (id, filetype, filecontent,
> filesize) VALUES( 23,
> \'test\', \''.base64_encode($filedata).'\', 299939)';
>
> odbc_exec($connection, $query);
>
> with the result
>
> MySQL MaxDB][SQLOD32 DLL][MaxDB] General error;-7032 POS(1)
> SQL statement not
> allowed for column of data type LONG
>
> What is wrong with my SQL statement ?? Maybe the '' before
> and after the
> filedata is not allowed, but what must I use ?? I can't find
> anything in the
> documentation.
>
>
> Later I tried the following
>
> $stmt = odbc_prepare($connection, "INSERT INTO myfiles (id, filetype,
> filecontent, filesize) VALUES( ?, ?, ?, ?)" );
> $parms = array($id,$filetype,"'c:/temp/test.data'", $filesize);
> $exec = odbc_execute($stmt, $parms);
>
> This time I don't get any error messages, but only a few
> bytes of the file are
> stored into the database ... not the complete file.
>
> Here is the trace from the last example
>
> INSERT INTO MYFILES (id, filetype, filecontent, filesize)
> VALUES( ?, ?, ?, ?)
> EXECUTE: CMD :
> PARSEID: INPUT : 000101B3 00004001 23000000 01000000
> INPUT : 1: COLUMN1 : 2319
> INPUT : 2: COLUMN2 : original
> INPUT : 3: COLUMN3 : LONGVARCHAR-DESC
> INPUT : 4: COLUMN4 : 12369440
> LONGVAR: 3: PARAMETER :
> HOSTVAR LENGTH : 131 LONGVAR LENGTH : 131
> VALUE :FIRST PART :
> 4D4D002A00000008001100FE000400
> ... : 0000010000
> INPUT : LONG VARCHAR FROM TO POSITION : 1 - 131
> SQLERRD(INDEX_3) : 1
> START : DATE : 2004-12-20 TIME : 0015:37:00
> END : DATE : 2004-12-20 TIME : 0015:37:00
> PUTLONG: CMD :
> PARSEID: : 000101B3 00004001 23000000 01000000
> LONGVAR: 3: PARAMETER :
> HOSTVAR LENGTH : 0 LONGVAR LENGTH : 131
> START : DATE : 2004-12-20 TIME : 0015:37:00
> END : DATE : 2004-12-20 TIME : 0015:37:00
>
> SUBTRANS END
> START : DATE : 2004-12-20 TIME : 0015:37:00
> END : DATE : 2004-12-20 TIME : 0015:37:00
>
> PARSEID: DROP : 000101B3 00003D01 23000000 01000000
> START : DATE : 2004-12-20 TIME : 0015:37:00
> END : DATE : 2004-12-20 TIME : 0015:37:00
>
> SQCDROPPARSID
> PARSEID: : 000101B3 00003D01 23000000 01000000
>
> PARSEID: DROP : 000101B3 00004001 23000000 01000000
> START : DATE : 2004-12-20 TIME : 0015:37:00
> END : DATE : 2004-12-20 TIME : 0015:37:00
>
> SQCDROPPARSID
> PARSEID: : 000101B3 00004001 23000000 01000000
>
>
>
> It would be very nice if someone can help me to get the file
> into the database.
>
>
> Bye
> Claus Windeler
>
>
>
>
>
>
>
>
>
>
>
>
> -------------------------------------------------
> This mail sent through IMP: http://horde.org/imp/
>
>
> --
> MaxDB Discussion Mailing List
> For list archives: http://lists.mysql.com/maxdb
> To unsubscribe:
> http://lists.mysql.com/maxdb?unsub=alexander.schroedersap.com
>
>
>

--
MaxDB Discussion Mailing List
For list archives: http://lists.mysql.com/maxdb