就直接从sqlite3的官网https://www.sqlite.org/download.html下载最新版本的源码
sqlite-amalgamation-3240000.zip
里面几个文件:shell.c sqlite3.c sqlite3.h sqlite3ext.h
c++builder的项目中在菜单: 工程->添加到工程吧 sqlite3.c添加进去
uint1.cpp中包含h文件 #include "sqlite3.h" (不能包含sqlite3ext.h文件,要不然编译不过的).
程序中的代码片段:
//sqlite 数据库操作
sqlite3* sl3 = NULL;
int ret;
int nrow;
int ncolumn;
char **Result = NULL;
char *errmsg = NULL;
char sql[128] = {0};
sprintf(sql, "select * from idcard");
sqlite3_open("idcard.db",&sl3);
ret = sqlite3_get_table(sl3, sql, &Result, &nrow, &ncolumn, &errmsg);
sqlite3_close(sl3);
得到的查询结果都放在Result数组中。
另外sqlite3是utf8存储信息的,所以中文需要转换,
BCB下GBKUnicodeUtf8编码转换:
AnsiString x; //GBK
WideString y; //unicode
UTF8String z; //utf8
x=y; //自动
y=x; //自动
z=AnsiToUtf8(x);
x=Utf8ToAnsi(z);
unicode的好像只能转little endian的
UTF8的转换需要去掉BOM转