http://www.runoob.com/sqlite/sqlite-commands.html
https://www.cnblogs.com/frankliiu-java/archive/2010/05/18/1738144.html
c++编程
#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>
static int testCallback(void* message,int argc,char** argv,char** columnName)
{
printf("the message is %s\n",(const char*)message);
for(int i = 0;i < argc;i++)
{
printf("%s = %s\n",columnName[i],argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
int main()
{
sqlite3* db;
int rc = sqlite3_open("test.db",&db);
if(rc)
{
printf("create database error:%s\n",sqlite3_errmsg(db));
exit(0);
}
else
{
printf("create database success\n");
}
const char* sql;
sql = "create table testBook(id integer primary key autoincrement,name text);";
// sql = "insert into testBook "\
// "values(1,'testBook1');"\
// "insert into testBook "\
// "values(2,'testBook2');";
// sql = "update testBook set name='testBook3' where id==1; "\
// "select * from testBook;";
// sql = "delete from testBook where id=1; "\
// "select * from testBook;";
const char* message = "my test callback";
char* errorMsg = 0;
rc = sqlite3_exec(db,sql,testCallback,(void*)message,&errorMsg);
if(rc == SQLITE_OK)
{
printf("sqlite3_exec success\n");
}
else
{
printf("sqlite3_exec failed,the msg is %s\n",errorMsg);
sqlite3_free(errorMsg);
}
sqlite3_close(db);
return 0;
}
此外
1.创建数据库表的语句
"create table 'tablename' ('key' TEXT, 'value' BLOB DEFAULT NULL)"
或
"create table 'tablename' ('key' TEXT, 'value' BLOB DEFAULT NULL,'value2' BLOB DEFAULT NULL,'value3' BLOB DEFAULT NULL)"
并
"CREATE UNIQUE INDEX 'idx_xxx' ON 'tablename' (key)"
2.通过一个数据库表拷贝成另一个数据库表
"create table 'newTableName' as select * from 'oldTableName'"
并
"CREATE UNIQUE INDEX 'idx_yyy' ON 'newTableName' (key)"
(前提是表newTableName的primary key的名字叫'key')