Quantcast
Channel: MySQL Forums - Connector/C++
Viewing all articles
Browse latest Browse all 527

MySQL C++ Connector crashes executing INSERT with BLOB (no replies)

$
0
0
I've stuck with a problem, trying to insert text as blob value, MySQL C++ connector crashed with exception: "Access violation reading location". I've seen questions like this here, but none has been answered. Here is a code sample:

#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>

#include <string>
#include <iostream>
#include <sstream>

using namespace sql;

void main(){
Connection *dbConnection;
Driver *driver;
Connection *con;

driver = get_driver_instance();
con = driver->connect("localhost", "root", "");
Statement *stmt = con->createStatement();
try{
stmt->execute("USE test");
stmt->execute("DROP TABLE blob_test");
stmt->execute("CREATE TABLE blob_test("
"id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,"
"original BLOB NOT NULL);");
char smallBlob[32];

for (char i = 0; i < sizeof(smallBlob); ++i)
{
smallBlob = i;
}
std::istringstream str(smallBlob);
PreparedStatement *pstmt = con->prepareStatement("INSERT INTO blob_test(id, original) VALUES (1, ?)");

pstmt->setBlob( 1, &str);
pstmt->executeUpdate();
}catch(sql::SQLException &e){
std::cerr << "# ERR: " << e.what();
std::cerr << " (MySQL error code: " << e.getErrorCode();
std::cerr << ", SQLState: " << e.getSQLState() << " )" << std::endl;
}
}

Thanks in advance!

Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>