我收到“node.exe 中 0x0369AF03 (libmysql.dll) 处的未处理异常:0xC0000005:访问冲突写入位置 0x00000008。” 在循环中使用 mysql C API 时出现错误消息。
环境:Windows 7 32bit,Mysql 5.6
该错误只发生在Debug模式,在发布模式下,它传递并获取结果,这很奇怪。
我用谷歌搜索,并设置了STMT_ATTR_CURSOR_TYPE,但它是一样的
请指教,谢谢!
代码:
准备声明
static const char *sql_odb_read =
"SELECT `type`, `size`, UNCOMPRESS(`data`) FROM GIT_ODB WHERE `repo` = ? AND `oid` = ?;";
mysql->odb_read = mysql_stmt_init(mysql->db);
if (mysql->odb_read == NULL)
return GIT_ERROR;
if (mysql_stmt_prepare(mysql->odb_read, sql_odb_read, strlen(sql_odb_read)) != 0)
return GIT_ERROR;
if (mysql_stmt_attr_set(mysql->odb_read, STMT_ATTR_UPDATE_MAX_LENGTH, &truth) != 0)
return GIT_ERROR;
if (mysql_stmt_attr_set(mysql->odb_read, STMT_ATTR_CURSOR_TYPE, (const void *)&type) != 0)
return GIT_ERROR;
执行语句
// bind the repo passed to the statement
bind_buffers[0].buffer = &(backend->mysql->repo);
bind_buffers[0].buffer_length = sizeof(backend->mysql->repo);
bind_buffers[0].length = &bind_buffers[0].buffer_length;
bind_buffers[0].buffer_type = MYSQL_TYPE_LONGLONG;
// bind the oid passed to the statement
bind_buffers[1].buffer = (void*)oid->id;
bind_buffers[1].buffer_length = 20;
bind_buffers[1].length = &bind_buffers[1].buffer_length;
bind_buffers[1].buffer_type = MYSQL_TYPE_BLOB;
if (mysql_stmt_bind_param(backend->mysql->odb_read, bind_buffers) != 0)
return GIT_ERROR;
// execute the statement
if (mysql_stmt_execute(backend->mysql->odb_read) != 0)
return GIT_ERROR;
if (mysql_stmt_num_rows(backend->mysql->odb_read) == 1) {
result_buffers[0].buffer_type = MYSQL_TYPE_TINY;
result_buffers[0].buffer = type_p;
result_buffers[0].buffer_length = sizeof(type_p); //sizeof(signed char);
result_buffers[0].is_null = 0;
result_buffers[0].length = &type_len;
memset(type_p, 0, sizeof(type_p));
result_buffers[1].buffer_type = MYSQL_TYPE_LONGLONG;
result_buffers[1].buffer = len_p;
result_buffers[1].buffer_length = sizeof(len_p);
result_buffers[1].is_null = 0;
result_buffers[1].length = &len_len;
memset(len_p, 0, sizeof(len_p));
result_buffers[2].buffer_type = MYSQL_TYPE_LONG_BLOB;
result_buffers[2].buffer = 0;
result_buffers[2].is_null = 0;
result_buffers[2].buffer_length = 0;
result_buffers[2].length = &data_len;
if (mysql_stmt_bind_result(backend->mysql->odb_read, result_buffers) != 0)
return GIT_ERROR;
error = mysql_stmt_fetch(backend->mysql->odb_read);