我得开发平台是windows+mysql+vc++
表中有一blob字段,想将二进制文件保存在该字段中
代码如下:
table.m_data.m_hData= GlobalAlloc(GPTR,file.GetLength());
LPVOID pMemBlob=::GlobalLock(table.m_data.m_hData);
file.ReadHuge(pMemBlob,file.GetLength());
table.Update();
其中table为一crecordset对象,对应mysql中该表
而table.m_data为CLongBinary,对应表中的那个blob字段;
语句file.ReadHuge(pMemBlob,file.GetLength());将文件file中数据读入到pMemBlob中,pMemBlob是内存句柄table.m_data对应的指针,这句执行后,内存中的内容是对的
然后table.Update();也可以成功执行,但更新后数据库中确实添加了一条记录,其他字段都是正确的,唯有这个blob字段内容为NULL
为什么呢?大家帮帮忙,集思广益了,谢谢
表中有一blob字段,想将二进制文件保存在该字段中
代码如下:
table.m_data.m_hData= GlobalAlloc(GPTR,file.GetLength());
LPVOID pMemBlob=::GlobalLock(table.m_data.m_hData);
file.ReadHuge(pMemBlob,file.GetLength());
table.Update();
其中table为一crecordset对象,对应mysql中该表
而table.m_data为CLongBinary,对应表中的那个blob字段;
语句file.ReadHuge(pMemBlob,file.GetLength());将文件file中数据读入到pMemBlob中,pMemBlob是内存句柄table.m_data对应的指针,这句执行后,内存中的内容是对的
然后table.Update();也可以成功执行,但更新后数据库中确实添加了一条记录,其他字段都是正确的,唯有这个blob字段内容为NULL
为什么呢?大家帮帮忙,集思广益了,谢谢
table.m_data.m_hData= GlobalAlloc(GPTR,file.GetLength());
LPVOID pMemBlob=::GlobalLock(table.m_data.m_hData);
file.ReadHuge(pMemBlob,file.GetLength());
table.SetFieldDirty(&(table.m_data));
table.SetFieldNull(&(table.m_data),false);
table.Update();
在外面用try捕获错误,每次在table.Update();执行时就捕获到错误,错误e的内容如下
e.m_strError为”Memory allocation error“
e.m_strStateNativeOrigin为"State:S1001,Native:4001,Origin:[MySQL][ODBC 3.51 Driver][mysqld-5.0.0-alpha-nt]
到底怎么回事啊?