开发者

can string longer than 255 bytes be used as ODBC prepared statement parameter value?

开发者 https://www.devze.com 2023-02-08 01:50 出处:网络
I am using the libodbc++ ODBC wrapper for C++, designed similar to JDBC. I have a prepared statement \"INSERT INTO t1 (col1) VALUES (?)\", where t1.col1 is defined as VARCHAR(500).

I am using the libodbc++ ODBC wrapper for C++, designed similar to JDBC. I have a prepared statement "INSERT INTO t1 (col1) VALUES (?)", where t1.col1 is defined as VARCHAR(500).

When I call statement->setSt开发者_如何学JAVAring(1, s), the value of s is truncated to 255. I suspect the libodbc++ library, but as I am not very familiar with ODBC I'd like to be sure that the wrapper doesn't just expose a restriction of the underlying ODBC. The ODBC API reference is too complicated to be skimmed quickly and frankly I really don't want to do that, so pardon me for asking a basic question.

NOTE: an un-prepared and un-parameterized insert statement via the same library inserts a long value ok, so it isn't a problem of the MySql DB.


For long string, use PreparedStatement::setAsciiStream() instead of PreparedStatement::setString().

But when use stream, I often encounter error "HY104 Invalid Precision Value", which is annoying because I have no idea how to tackle it head on, however I work around it with following steps:

1, order the columns in SQL statement, non-stream columns go first;

2, if that doesn't work, split the statement to multiple ones, update or query a single column per statement.

But(again), in order to insert a row first and then update some columns in stream manner, one may have to get the last insert id, which turns out to be another challenge which I again failed to tackle head on for now...


I don't know libodbc++, but PreparedStatements available via ODBC API can store more characters. I use it with Delphi/Kylix ODBC wrapper.

Maybe there is some configuration in libodbc++ to set value length limit? I have such setting in my Delphi library. If you use PreparedStatement then you can allocate big chunk of memory, divide it into fields and show ODBC where block for each column starts and how long is it via SQLBindParameter() function.

0

精彩评论

暂无评论...
验证码 换一张
取 消