SQLite的sqlite3_prepare_v2

 original SQL text---<sqlite3_prepare_v2>--->sqlite3_stmt--<sqlite3_reset>-->clear sqlite3_stmt --<sqlite3_bind_*(stmt,1,*)>--> configed sqlite3_stmt

--<sqlite3_step()>--->run sqlite3_stmt---<sqlite3_column_*(statement, N)>--->查询输出----<sqlite3_finalize()>--->释放语句

/*

** CAPI3REF: Prepared Statement Object

** KEYWORDS: {prepared statement} {prepared statements}

**

** An instance of this object represents a single SQL statement that

** has been compiled into binary form and is ready to be evaluated.

**

** Think of each SQL statement as a separate computer program.  The

** original SQL text is source code.  A prepared statement object 

** is the compiled object code.  All SQL must be converted into a

** prepared statement before it can be run.

**

** The life-cycle of a prepared statement object usually goes like this:

**

** <ol>

** <li> Create the prepared statement object using [sqlite3_prepare_v2()].

** <li> Bind values to [parameters] using the sqlite3_bind_*()

**      interfaces.

** <li> Run the SQL by calling [sqlite3_step()] one or more times.

** <li> Reset the prepared statement using [sqlite3_reset()] then go back

**      to step 2.  Do this zero or more times.

** <li> Destroy the object using [sqlite3_finalize()].

** </ol>

 

 

-(void)select{

 

    NSString * sqlString = @"select * from person";

    

    //准备sql语句

    sqlite3_stmt * stmt = nil;

    sqlite3_prepare(db, sqlString.UTF8String, -1, &stmt, nil);

    //单步执行语句

    while (sqlite3_step(stmt) == SQLITE_ROW) {

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

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

        int age = sqlite3_column_int(stmt, 1);

        

        NSLog(@"name:::%@ and age:::%d",nameStr,age);

        

    }

    //释放

    sqlite3_finalize(stmt);

    

}

 

转载于:https://www.cnblogs.com/feng9exe/p/10685312.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值