For example,assume the string variable zText contains text as follows:
char *zText = "It's a happy day!";
One can use this text in an sql statement as follows:
char *zsql = sqlite3_mprintf("INSERT INTO table VALUES('%q')",zText);sqlite3_exec(db,zsql,0);sqlite3_free(zsql);
Because the %q format string is used,the '\'' character in zText is escaped and the sql generated is as follows:
INSERT INTO table1 VALUES('It''s a happy day!')
This is correct. Had we used %s instead of %q,the generated sql would have looked like this:
INSERT INTO table1 VALUES('It's a happy day!')
总结 以上是内存溢出为你收集整理的Sqlite SQL格式化输入函数splite3_mprintf全部内容,希望文章能够帮你解决Sqlite SQL格式化输入函数splite3_mprintf所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)