0x00 byte problem while storing binary data to MySQL BLOB via ODBC (C API)
-
Have a data truncation problem at NULL byte, while trying to store binary array to BLOB Table 'major' structure is: (smallint) Frame_number|(longblob) ch1|(longblob) ch2|(longblob) ch3|(longblob) ch4|(smallint) frame_size
Connection to base is done, memory for all necessary handles is allocated. 1. Prepare statemtSQLPrepare(sql_hStmt,_T("INSERT INTO major(Frame_number,CH1,CH2,CH3,CH4,frame_size) VALUES(?,?,?,?,?,?)"),SQL_NTS);
2. Binding params
SQLBindParameter(sql_hStmt, 1, SQL_PARAM_INPUT, SQL_INTEGER, SQL_INTEGER, 0,0, &frames_parsed, 0, 0);
SQLBindParameter(sql_hStmt, 2, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_VARBINARY, 0,0, v, bufsz, 0);
SQLBindParameter(sql_hStmt, 3, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_VARBINARY, 0,0, v, bufsz, 0);
SQLBindParameter(sql_hStmt, 4, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_VARBINARY, 0,0, v, bufsz, 0);
SQLBindParameter(sql_hStmt, 5, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_VARBINARY, 0,0, v, bufsz, 0);
SQLBindParameter(sql_hStmt, 6, SQL_PARAM_INPUT, SQL_INTEGER, SQL_INTEGER, 0,0, &datasize, 0, 0);where v - array holding data to be stored to DB. bufsz - its size 3. Cycle execution
SQLExecute(sql_hStmt);
Ant suggestion would be great, thanks. ver MySQL - 5.5, ver OBDC - Mysql ODBC 5.1
-
Have a data truncation problem at NULL byte, while trying to store binary array to BLOB Table 'major' structure is: (smallint) Frame_number|(longblob) ch1|(longblob) ch2|(longblob) ch3|(longblob) ch4|(smallint) frame_size
Connection to base is done, memory for all necessary handles is allocated. 1. Prepare statemtSQLPrepare(sql_hStmt,_T("INSERT INTO major(Frame_number,CH1,CH2,CH3,CH4,frame_size) VALUES(?,?,?,?,?,?)"),SQL_NTS);
2. Binding params
SQLBindParameter(sql_hStmt, 1, SQL_PARAM_INPUT, SQL_INTEGER, SQL_INTEGER, 0,0, &frames_parsed, 0, 0);
SQLBindParameter(sql_hStmt, 2, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_VARBINARY, 0,0, v, bufsz, 0);
SQLBindParameter(sql_hStmt, 3, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_VARBINARY, 0,0, v, bufsz, 0);
SQLBindParameter(sql_hStmt, 4, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_VARBINARY, 0,0, v, bufsz, 0);
SQLBindParameter(sql_hStmt, 5, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_VARBINARY, 0,0, v, bufsz, 0);
SQLBindParameter(sql_hStmt, 6, SQL_PARAM_INPUT, SQL_INTEGER, SQL_INTEGER, 0,0, &datasize, 0, 0);where v - array holding data to be stored to DB. bufsz - its size 3. Cycle execution
SQLExecute(sql_hStmt);
Ant suggestion would be great, thanks. ver MySQL - 5.5, ver OBDC - Mysql ODBC 5.1
First check parameter value for null or empty content, if is null then send DBNull value (in .NET is
DBNull.Value
) , if is not null then send value of array. Hope this will help you :)
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
-
First check parameter value for null or empty content, if is null then send DBNull value (in .NET is
DBNull.Value
) , if is not null then send value of array. Hope this will help you :)
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
Hi! Thanks, that was helpful, but only partly, since passing SQL_NULL_DATA (-1) instead of 0x00, I get 0xFF value in the base field.
if (v[i] == 0x00) v[i] = SQL_NULL_DATA;
How do I later distingush real FF bytes from wraped null data? :sigh: Still many thanks for help