长度超过 255 个字节的字符串可以用作 ODBC 准备语句参数值吗?
我正在使用 C++ 的 libodbc++
ODBC 包装器,其设计类似于 JDBC。我有一个准备好的语句 “INSERT INTO t1 (col1) VALUES (?)”
,其中 t1.col1
定义为 VARCHAR(500)
。
当我调用 statement->setString(1, s)
时,s
的值被截断为 255
。我怀疑 libodbc++ 库,但由于我对 ODBC 不太熟悉,我想确保包装器不仅仅暴露了底层 ODBC 的限制。 ODBC API 参考太复杂,无法快速浏览,坦率地说,我真的不想这样做,所以请原谅我问一个基本问题。
注意:通过同一库的未准备和未参数化的 insert
语句可以插入一个长值,因此这不是 MySql DB 的问题。
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->setString(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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于长字符串,请使用
PreparedStatement::setAsciiStream()
而不是PreparedStatement::setString()
。但是在使用流时,我经常遇到错误“HY104 Invalid Precision Value”,这很烦人,因为我不知道如何解决它,但是我通过以下步骤解决它:
1,
对 SQL 中的列进行排序语句,非流列先行;
2,
如果这不起作用,请将语句拆分为多个语句,更新或查询每个语句的单个列。
但是(再次),为了先插入一行,然后以流方式更新一些列,可能必须获取最后一个插入ID,这结果是另一个挑战,我现在再次未能正面解决......
For long string, use
PreparedStatement::setAsciiStream()
instead ofPreparedStatement::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...
我不知道
libodbc++
,但通过 ODBC API 提供的PreparedStatements 可以存储更多字符。我将它与 Delphi/Kylix ODBC 包装器一起使用。也许
libodbc++
中有一些配置来设置值长度限制?我的 Delphi 库中有这样的设置。如果您使用PreparedStatement,那么您可以分配大块内存,将其划分为字段,并通过SQLBindParameter()
函数向ODBC显示每列的块开始位置以及长度。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 viaSQLBindParameter()
function.