首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

mysql 2035错误

2012-03-31 
mysql 2035异常bcb6.0 mysql5.0C/C++ codevoid TMain::InsertPhoto(int id, TJPEGImage *image){char * p

mysql 2035异常
bcb6.0 mysql5.0

C/C++ code
void TMain::InsertPhoto(int id, TJPEGImage *image){        char * p = NULL;        MYSQL_BIND bind[1];        unsigned long length;        MYSQL_STMT * stmt;        AnsiString sql = "Insert into `photo` (`member`,`photo`) values ("+AnsiString(id)+",?)";        stmt = mysql_stmt_init(mysql);        TMemoryStream * stream = new TMemoryStream();        stream->Position = 0;        image->SaveToStream(stream);        unsigned long psize = stream->Size;        p = new char [psize+1];        stream->Read(p,psize);        if(!stmt)        {                ShowMessage("Stmt failed to Create!");        }        if(mysql_stmt_prepare(stmt,sql.c_str(),sql.Length()))        {                ShowMessage(mysql_stmt_error(stmt));        }        memset(bind,0,sizeof(bind));        bind[0].buffer = p;        bind[0].buffer_type = MYSQL_TYPE_LONG_BLOB;        bind[0].is_null = 0;        if(mysql_stmt_bind_param(stmt,bind))        {                ShowMessage(mysql_stmt_error(stmt));        }        if(mysql_stmt_send_long_data(stmt,0,p,psize))        {                ShowMessage(mysql_stmt_error(stmt));        }        if(mysql_stmt_execute(stmt))        {                ShowMessage(mysql_stmt_error(stmt));        }        mysql_stmt_close(stmt);        delete p;        delete stream;}

在存入图片出现2035错误,怎么办?

[解决办法]
没研究过mysql
但是你的语句中有几个明显的问题,需要提醒
C/C++ code
 
    TMemoryStream * stream = new TMemoryStream();
    stream->Position = 0;//这条语句应该放到后面
    image->SaveToStream(stream);
    unsigned long psize = stream->Size;
    p = new char [psize+1];//内存申请可能会失败,而且大图片申请失败的概率非常大,
//失败以后,经常会出现存取违规错误,导致未定义的行为发生。
    stream->Read(p,psize);

热点排行