IOS数据库学习心得

常见的几种数据库

SQL ,  MY SQL,Oracle;

什么是数据库

1)以一定方式存储一起;
2)能为多个用户共享;
3)具有尽可能小的冗余度
4)与程序彼此独立的数据集合

SQL语句

1.数据插入命令(Insert)
2.数据更新命令(Update)
3.数据删除命令(Delete)
4.数据检索命令(Select)

Insert:


 Update:

Delete:

Select:

+ (NSArray *)searchAllNovel

{

    sqlite3 *dbPoint = [DB openDB];

    //第二步,获得数据库指针的替身

    sqlite3_stmt *stmt = nil;

    //第三步:sql语句

    NSString *sqlStr = @"select novel_id,novel_name,novel_author,novel_date,novel_paice from novel";

    //检查数据库语句是否正确,并将替身中填写查找的内容

    int result = sqlite3_prepare_v2(dbPoint, [sqlStr UTF8String], -1, &stmt, nil);

    NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease];

    if (result == SQLITE_OK) {

        //获得每一条查找到的数据的内容

        while (sqlite3_step(stmt) == SQLITE_ROW) {

            int nid = sqlite3_column_int(stmt, 0);

            const unsigned char *name = sqlite3_column_text(stmt, 1);

            const unsigned char *author = sqlite3_column_text(stmt, 2);

            const unsigned char *date = sqlite3_column_text(stmt, 3);

            double price = sqlite3_column_double(stmt, 4);

            

            NSString *novelName = [NSString stringWithUTF8String:(const char *)name];

            NSString *novelauther = [NSString stringWithUTF8String:(const char *)author];

            NSString *novelDate = [NSString stringWithUTF8String:(const char *)date];

            NovelModel *model = [NovelModel novelModelWithNovel_id:nid name:novelName auther:novelauther date:novelDate price:price];

            [array addObject:model];

            }

        }

    sqlite3_finalize(stmt);

    return array;

}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值