我得到了以下 sql_buildup_method... 代码有点脏,但事实并非如此
char *build_up_sql(char *inputName,char *inputMessage)
{
char firstPartStatement[1064] ="INSERT INTO User (name, msg) VALUES (";
char *endPartStatement =");";
char *lightener = "'";
char *statement;
strcat(firstPartStatement,lightener);
strcat(firstPartStatement,inputName);
strcat(firstPartStatement,lightener);
strcat(firstPartStatement,",");
strcat(firstPartStatement,lightener);
strcat(firstPartStatement,inputMessage);
strcat(firstPartStatement,lightener);
strcat(firstPartStatement,endPartStatement);
statement = firstPartStatement;
return statement;
}
void create_input(sqlite3 *handler,char *inputName,char *inputMessage)
{
char *sql;
sql = build_up_sql(inputName,inputMessage);
// sql ="INSERT INTO User (name, msg) VALUES ('Susanne','hi all');";
printf("%s\n",sql);
sqlite3_exec(handler,sql, NULL, NULL, NULL);
}
printf 给出输出: INSERT INTO User (name, msg) VALUES ('Susanne','hi all'); 这完全没问题......但是 sqlite3_exec 忽略它并且没有生成新的数据库输入......如果我离开这条线sql ="INSERT INTO User (name, msg) VALUES ('Susanne','hi all' );"; 在代码中 sqlite3_exec 工作正常....也将所有内容放在一个函数中也解决了问题,但这不应该是一种选择.....