当前位置: 代码迷 >> 其他数据库 >> sqlite插入数据的有关问题
  详细解决方案

sqlite插入数据的有关问题

热度:3458   发布时间:2013-02-26 00:00:00.0
sqlite插入数据的问题
void func(char * cardtype,char * cardsn){
  /*省略不重要的内容*/

  sql = "insert into \"time\" VALUES(null,---,---)"
}

本人想在那个sql语句的---处动态地插入cardtype和cardsn两个字符串,无论是用 cardsn和*cardsn都不行。本程序是用C语言实现的,请问高手应该怎么办呢?本程序要实现把这两个参数写到数据库里面。



------解决方案--------------------------------------------------------
C/C++ code
char szcharSql[MAX_PATH];sprintf(szcharSql,        "Insert Into t_Table1(FCardType, FCardSN)VALUES(%s, %s)",        cardtype,        cardsn);              Excute SQL...
------解决方案--------------------------------------------------------
Formatted String Printing Functions
char *sqlite3_mprintf(const char*,...);
char *sqlite3_vmprintf(const char*, va_list);
char *sqlite3_snprintf(int,char*,const char*, ...);
char *sqlite3_vsnprintf(int,char*,const char*, va_list);


These routines are work-alikes of the "printf()" family of functions from the standard C library.

The sqlite3_mprintf() and sqlite3_vmprintf() routines write their results into memory obtained from sqlite3_malloc(). The strings returned by these two routines should be released by sqlite3_free().
  相关解决方案