I have a MaxDb database with a table, that contains binary data as Varchar/Byte ( equivalent to Ado type adVarBinary). Unfortunately I can not find the right way to pass this data in a OdbcPreparedStatement. If I bind as ODBC_TYPE_STRING, the field will contain all 0-Bytes, if a bind as ODBC_TYPE_BINARY the app will hang when the statement gets executed.
What does work, is using the BlobColumn property of DatabaseRecord, however I can not find an equivalent for ODBC_TYPEs.
I pasted some sample code below.
This is Xojo 2014R3.2 on Windows7 64-Bit.
Thanks in advance for any help in this matter,
Silke
[code] // MyTable:
// SomeField Varchar(20), Ascii, not null, primary key,
// BinField Varchar(480), Byte, not null
//
dim conDb as new ODBCDatabase
conDb.DataSource = “UID=;PWD=;SERVERDB=MYDB;SERVERNODE=MYNODE;DRIVER=MaxDB;”
conDb.ScrollableCursor = True
if conDb.Connect then
if not conDb.Error then conDb.SetConnectionAttribute ODBCConstant.SQL_AUTOCOMMIT, ODBCConstant.SQL_AUTOCOMMIT_OFF
end if
if conDb.Error then
msgbox "DB Error: " + conDb.ErrorMessage
return
end if
dim aMem as new MemoryBlock( 480)
aMem.DoubleValue( 0 ) = 1.0
for idx as integer = 1 to 59
aMem.DoubleValue( 8 * idx ) = 2.0 ^ 0.5
next idx
dim strSql as string = "Insert into MyTable( SomeField, BinField) Values(?, ?) "
dim Stmt as ODBCPreparedStatement = conDb.Prepare( strSql )
if not conDb.Error then Stmt.BindType(0, ODBCPreparedStatement.ODBC_TYPE_STRING)
if not conDb.Error then Stmt.BindType(1, ODBCPreparedStatement.ODBC_TYPE_STRING)
if not conDb.Error then Stmt.SQLExecute( “Hello”, aMem.StringValue( 0, aMem.Size) )
if not conDb.Error then
conDb.Commit
else
msgbox "DB Error: " + condb.ErrorMessage
conDb.Rollback
end if
strSql = “Select * from MyTable where SomeField=‘Hello’”
dim rs as recordset = conDb.SQLSelect( strSql )
if not conDb.Error and not rs.EOF then
aMem.StringValue(0, aMem.Size) = rs.Field(“BinField”).StringValue
Msgbox “Value#1=” + str(aMem.DoubleValue(0)) + “, Value#2=” + str(aMem.DoubleValue(8))
else
msgbox "Either no Data or DB Error: " + condb.ErrorMessage
end if
rs.Close
conDb.Close
[/code]