PDA

View Full Version : Mysql Insert errorr


zT KiNgKoNg
30/10/2013, 10:25 AM
Having a little issue while trying to insert some data.

Code

format(qq,sizeof(qq),"INSERT INTO `atm_data` (AtmExists,Charge,ATM_X,ATM_Y,ATM_Z,ATM_Rot_X,ATM_ Rot_Y,ATM_Rot_Z) VALUES ('1','5','%f','%f','%f','%f','%f','%f')",x,y,z,rx,ry,rz);
mysql_query(qq);
mysql_free_result();

Problem

[10:33:11] >> mysql_query( Connection handle: 1 )

[10:33:11] CMySQLHandler::Query(SELECT * FROM `atm_data`) - Successfully executed.

[10:33:11] >> mysql_store_result( Connection handle: 1 )

[10:33:11] CMySQLHandler::StoreResult() - Result was stored.

[10:33:11] >> mysql_num_rows( Connection handle: 1 )

[10:33:11] CMySQLHandler::NumRows() - Returned 1 row(s)

[10:33:11] >> mysql_fetch_row_format( Connection handle: 1 )

[10:33:11] CMySQLHandler::FetchRow() - Return: 1|1|7|15.4374|1186.98|19.1082|0|0|90

[10:33:11] >> mysql_fetch_row_format( Connection handle: 1 )

[10:33:30] >> mysql_query( Connection handle: 1 )

[10:33:30] CMySQLHandler::Query(INSERT INTO `atm_data` (AtmExists,Charge,ATM_X,ATM_Y,ATM_Z,ATM_Rot_X,ATM_ Rot_Y,ATM_Rot_Z) VALUES ('1','5','19.256700','1191.1) - An error has occured. (Error ID: 1064, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1191.1' at line 1)

[10:33:30] >> mysql_free_result( Connection handle: 1 )

[10:33:30] CMySQLHandler::FreeResult() - Result was successfully free'd.

DanishHaq
30/10/2013, 10:27 AM
Make sure the array for qq is large enough.

Ballu Miaa
30/10/2013, 10:31 AM
printf("[DEBUG] Values: %f,%f,%f,%f,%f,%f",x,y,z,rx,ry,rz);
format(qq,sizeof(qq),"INSERT INTO `atm_data` (AtmExists,Charge,ATM_X,ATM_Y,ATM_Z,ATM_Rot_X,ATM_ Rot_Y,ATM_Rot_Z) VALUES ('1','5','%f','%f','%f','%f','%f','%f')",x,y,z,rx,ry,rz);
mysql_query(qq);
mysql_free_result();


See what the printf will print out. Let me know the output.

zT KiNgKoNg
30/10/2013, 10:37 AM
Output

[DEBUG] Values: 19.256700,1191.121337,19.150520,0.000000,0.000000, 0.000000


Mysql Debug

[10:47:24] ---------------------------

[10:47:24] MySQL Debugging activated (10/30/13)

[10:47:24] ---------------------------

[10:47:24]

[10:47:24] >> mysql_query( Connection handle: 1 )

[10:47:24] CMySQLHandler::Query(SELECT * FROM `atm_data`) - Successfully executed.

[10:47:24] >> mysql_store_result( Connection handle: 1 )

[10:47:24] CMySQLHandler::StoreResult() - Result was stored.

[10:47:24] >> mysql_num_rows( Connection handle: 1 )

[10:47:24] CMySQLHandler::NumRows() - Returned 1 row(s)

[10:47:24] >> mysql_fetch_row_format( Connection handle: 1 )

[10:47:24] CMySQLHandler::FetchRow() - Return: 1|1|7|15.4374|1186.98|19.1082|0|0|90

[10:47:24] >> mysql_fetch_row_format( Connection handle: 1 )

[10:47:48] >> mysql_query( Connection handle: 1 )

[10:47:48] CMySQLHandler::Query(INSERT INTO `atm_data` (AtmExists,Charge,ATM_X,ATM_Y,ATM_Z,ATM_Rot_X,ATM_ Rot_Y,ATM_Rot_Z) VALUES ('1','5','19.256700','1191.1) - An error has occured. (Error ID: 1064, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1191.1' at line 1)

[10:47:48] >> mysql_free_result( Connection handle: 1 )

[10:47:48] CMySQLHandler::FreeResult() - Result was successfully free'd.

Ballu Miaa
30/10/2013, 10:39 AM
Output

[DEBUG] Values: 19.256700,1191.121337,19.150520,0.000000,0.000000, 0.000000



SQL will assume 0.000 zero's as a NULL Value. If your table's fields are set to NOT NULL. Maybe thats why the query is not INSERT'ing correctly.

Konstantinos
30/10/2013, 10:43 AM
qq stored only this "INSERT INTO `atm_data` (AtmExists,Charge,ATM_X,ATM_Y,ATM_Z,ATM_Rot_X,ATM_ Rot_Y,ATM_Rot_Z) VALUES ('1','5','19.256700','1191.1".

So like DanishHaq said, make the size of qq greater.

Ballu Miaa
30/10/2013, 10:58 AM
qq stored only this "INSERT INTO `atm_data` (AtmExists,Charge,ATM_X,ATM_Y,ATM_Z,ATM_Rot_X,ATM_ Rot_Y,ATM_Rot_Z) VALUES ('1','5','19.256700','1191.1".

So like DanishHaq said, make the size of qq greater.

Yup. Thanks. That worked for him. We just realized it on skype. LOL XD