There char * sql;
char * sql2;
sql2 = "INSERT INTO appdata (name, time) VALUES ('new', 1)";
printf ("% s,% d \ n", sql, strlen (sql));
printf ("% s,% d \ n", sql2, strlen (sql2));
res = mysql_real_query (& mysql, sql, strlen (sql));
sql is a sprintf (sql, "INSERT INTO appdata (% s) VALUES (% s,% s)") created out of the same character and sql2 string , sprintf print length is the same , but the resulting output is
INSERT INTO appdata (name, time) VALUES ('new', 1), 50
INSERT INTO appdata (name, time) VALUES ('new', 1), 50
Insert error 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'' neq 'at line 1
and put res = mysql_real_query (& mysql, sql, strlen (sql)); the sql replaced sql2, will be able to properly insert
If the new replaced neww, but also the normal insert, which is why ? And character sets may have a relationship , but the character set has been used
mysql_set_character_set (& mysql, "utf8")
set over, puzzled ...
------ Solution ------------------------------------ --------
char * sql;
sprintf (sql, "INSERT INTO appdata (% s) VALUES (% s,% s)")
how the sql space allocation ? malloc?
------ For reference only ---------------------------------- -----
ah , yes , malloc completely memset 0 of
------ For reference only ------------------- --------------------
Thank you for giving me a direction to solve the problem , the problem has been resolved , malloc space allocated char * sql process only added when calculating the length of the length of the two parameters , missing the table name plus the length of the string , leading character end portion of the string is truncated .
没有评论:
发表评论