1.场景
1.1 程序环境:MySQL 5.0/MySQL ODBC 3.51 Driver/ADO
1.2.测试表
CREATE TABLE `tb_test_12` (
`f1` int(11) NOT NULL auto_increment,
`f2` blob NOT NULL,
`f3` int(11) default NULL,
PRIMARY KEY (`f1`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=gbk;
1.3 测试代码
int CXBox::OnTest666() {
GETDBC(pdbor,this->local_dbc_.c_str());
CRecordset *prs = pdbor->Query(adCmdTable,"tb_test_12");
bool br;
br = prs->AddNew();
br = prs->PutCollect("f3",10l);
char buffer[32]="sssssss";
unsigned long len = strlen(buffer);
br = prs->AppendChunk("f2",(void*)buffer,len);
///< @note 到此为止,前面的操作都指示执行成功
br = prs->Update();
///< Update失败,错误为:
///< [MySQL][ODBC 5.1 Driver][mysqld-5.0.45-community-nt-log]Column 'f2' cannot be null
const char *err = pdbor->GetLastError();
return 0;
}
2.解决
2.1使用客户端游标,代码如下:
GET_CURSOR_DBC(pdbor,this->local_dbc_.c_str(),CLIENT_CURSOR);
其理由见http://dev.mysql.com/doc/refman/5.1/en/connector-odbc-errors.html#qandaitem-21-1-7-3-1-10
21.1.7.3.10: Using the AppendChunk() or GetChunk() ADO methods, the Multiple-step operation generated errors. Check each status value error is returned.
The GetChunk() and AppendChunk() methods from ADO doesn't work as expected when the cursor location is specified as adUseServer. On the other hand, you can overcome this error by using adUseClient.
对应中文页面
http://dev.mysql.com/doc/refman/5.1/zh/connectors.html#chunk
存疑:
.“不能按预期的方式工作”: 是必然得不到预期的结果,还是不能确定得到预期的结果.
.我所见的代码里面有用adUseServer的AppendChunk,从上下文看似乎它应该在实际运行时是工作的,为什么没有暴露问题
.使用GetChunk的代码也未见得使用客户端游标
2.2hotfox.conf配置
<database encrypted_password="false">
<conn constr="DRIVER={MySQL ODBC 3.51 Driver};SERVER=127.0.0.1;;OPTION=3;charset=gbk" count="25:2" name="LATON" db_ext="mysql_ext.dll"/>
<count>属性设置采用服务端和客户端游标的连接个数,两者之间用":"分隔。