sqlite3

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')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值