C++/MySQL insert syntax issue

109 Views Asked by At

I am attempting to build an insert statement within a C++ application to push records to a MariaDB server, but am getting a generic error back from the database citing MySQL syntax errors.

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NSERT INTO test_data (cid,ch1,ch2,ch3,ch4,..' at line1

The code is as follows:

insertString = "INSERT INTO test_data (cid,ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9,ch10,ch11,ch12,ch13,ch14,ch15,ch16,value_type) VALUES ('"+cid;"', '"+di_ch[0];"', '"+di_ch[1];"', '"+di_ch[2];"', '"+di_ch[3];"', '"+di_ch[4];"', '"+di_ch[5];"', '"+di_ch[6];"', '"+di_ch[7];"', '"+di_ch[8];"', '"+di_ch[9];"', '"+di_ch[10];"', '"+di_ch[11];"', '"+di_ch[12];"', '"+di_ch[13];"', '"+di_ch[14];"', '"+di_ch[15];"', '"+value_type;"')";

mysql_query_status=mysql_query(connect,insertString.c_str());

The code wouldn't compile without formatting the values with the "+" and ";" preceding and following the variable reference. It still doesn't quite make sense to me why this is required, but then again, I still need to find a good reference document for using this connector, which would also be appreciated. There is a lot of material on installing, configuring and building the connector and its applications, but not many code examples. Of what I've found, I've read I may need to try using a PreparedStatement next.

Table schema here

0

There are 0 best solutions below