第三篇 FMDB的使用

使用第三方FMDB 应用内嵌sqlite

首先初始化数据库

#define DATABASENAME  @"*******.sqlite3"

static NSString * dataBaseFilePath = nil;
static FMDatabase *db = nil;
{
    if (!dataBaseFilePath)
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString * documentDirectory = [paths objectAtIndex:0];
        dataBaseFilePath = [documentDirectory stringByAppendingPathComponent:DATABASENAME];
    }
    return dataBaseFilePath;
}

然后建表

    if(![db tableExists:@"orderTable"])
    {
        [db executeUpdate:@"CREATE TABLE IF NOT EXISTS orderTable(_id INTEGER PRIMARY KEY AUTOINCREMENT,productGuid TEXT,  goldCount TEXT ,theUsd TEXT , theState TEXT );"];
    }

然后 操作

{
    if (!db)
    {
        db = [self getDataBase];
    }
    [db open];
    [self createTable];
    [db beginTransaction]; //与commit 成对出现。查询时候不需要

//增

//  [db executeUpdate:@"INSERT INTO orderTable(productGuid, goldCount,theUsd,theState) VALUES(?,?,?,?)",prductGuid,goldCount,usd,state];


//删

//       [db executeUpdate:@"DELETE from orderTable WHERE productGuid = ? ",pGuid];

//改

//   [db executeUpdate:@"UPDATE orderTable SET goldCount = ? WHERE theUsd = ?",gold,usd];

//查

//    FMResultSet *rs=[db executeQuery:@"select * from orderTable"];
//    while ([rs next])
//    {
                   //查处结果以后的操作
//    }

//  [rs close];


    [db commit];
    [db close];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值