`
happmaoo
  • 浏览: 4338447 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

SQLITE3 学习笔记

 
阅读更多


输出结果:SQLiteHeaderVersion:3.6.21 SQLiteLibraryVersion:3.6.22 SQLiteLibraryVersionNumber:3006022 SQLiteVersion:3.6.21



执行SQL语言

db.execDML("Create table");


插入SQL记录

int rows = db.execDML("insert into table ");
返回值为插入的记录条数;

int id = db.lastRowId();
获取最后一次的插入记录ID,适用于自动增长的主键。


删除SQL记录

int irows = db.execDML("delete * from table ");

返回值是删除的记录条数;


更新SQL记录

int rows = db.execDML("update table set rowid = 1");

返回值是更新的记录条数


使用事务控制

db.execDML("begin Transaction;");
db.execDML("insert into table .......");

db.execDML("commit Transaction;");


返回计算值

int iCount = db.execScalar("select count(*) from table;");


查询结果集

CppSqlite3Query q = db.execQuery("select * From table "); //查询


取结果集的字段信息
int iFiles = q.numFields() ;//总字段数

q.fieldName(1);//字段名称

q.fieldType(1);//字段类型


遍历结果集中的记录
while( !q.eof())
{
int id = q.fieldValue(0) ;//取字段值
q.nextRow();
}


格式化查询
可以格式条件以及插入NULL值

CppSqlite3Buff buffSQL;
buffSQL.format("insert into table(id,value) values(%Q,%Q)",NULL,"what's is it ?");
db.execDML(buffSQL);


按表查询

CppSqlite3Table t = db.getTable("select * From table ");

取表字段信息:
t.numFields();//总字段数
t.fieldName(0);//字段名称
t.fieldType(0);//字段类型


遍历表格结果

for(int row = 0 ;i<t.numRows();row ++)
{
t.setRow(row);//定位表格中的行
//取行信息
int (int i=0;i<t.numFields();i++){
if( !t.fieldIsNull(i))//判断空值
int id = t.fieldValue(i);//取字段值
}

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics