I have not done much database programming at all. I am working from some example code for using MySQL Connector/C++.
When I run the following code I get a crash on the last line in some std::string code - but it ONLY crashes when the table is not empty. If the table is empty, it inserts the row and works fine. If the table is non empty it crashes. I am pretty confused. Is there something I am doing wrong with the primary key or the other values? (the column names have been changed here, but otherwise the code is verbatim)
When I look at the variable in the std::string template code (what little I can see) I don't see any familiar values of data that I was attempting to insert - so that was no help at all. I see something like "HY000" as a string value, but I am not certain where that is coming from.
Initially i thought it might be the date string, but the code works fine with an empty table and then crashes when non-empty. That indicates the date string works fine.
prep_stmt = con->prepareStatement("INSERT INTO
sometable(val1, val2, val3, Date, val5, val6, val7)
VALUES (?, ?, ?, ?, ?, ?, ?)");
/*
`idLicenses` INT NOT NULL ,
`val1` VARCHAR(45) NOT NULL ,
`val2` INT NOT NULL ,
`val3` INT ZEROFILL NULL ,
`Date` DATETIME NOT NULL ,
`val5` VARCHAR(45) NOT NULL ,
`val6` VARCHAR(45) NOT NULL ,
`val7` VARCHAR(45) NOT NULL ,
*/
// val1, val5, val6 and val7 are std::strings, val2 and val3 are ints.
prep_stmt->setString(1, val1);
prep_stmt->setInt(2, val2);
prep_stmt->setInt(3, 0);
prep_stmt->setDateTime(4, /* I created some date string here*/);
prep_stmt->setString(5, val5);
prep_stmt->setString(6, val6);
prep_stmt->setString(7, val7);
prep_stmt->execute();
This is on a MS platform using Visual Studio 2008.
The database is up and running and I can use other database query tools to see the tables, etc.
EDIT:
I see looking at the mysql exception that I get:
"Using unsupported buffer type: 4191960 (parameter: 3)" errno 2036
EDIT:
I am not sure if the accepted answer was exactly the right answer, but it helped me get to a solution. Basically I removed all non-null attributes, took out zero fill and set the primary key to auto-increment. Now it works fine