sqlite3 sqlite3_prepare、sqlite3_step使用

void select_by_prepare (sqlite3* pDB){
 51     int i;
 52     int ret = 0;
 53     int time;
 54     char* pdu;
 55     int pdu_size;
 56     int flag;
 57     sqlite3_stmt *statement;
 58 
 59     ret = sqlite3_prepare (pDB, "SELECT * FROM content", -1, &statement, NULL);
 60     if(ret != SQLITE_OK){
 61         printf("prepare error ret : %d\n", ret);
 62         return;
 63     }
 64 
 65     while (sqlite3_step(statement) == SQLITE_ROW) {
 66         time = sqlite3_column_int(statement, 0);
 67         pdu = (char *)sqlite3_column_text(statement, 1);
 68         pdu_size = sqlite3_column_int (statement, 2);
 69         flag = sqlite3_column_int (statement, 3);
 70 
 71         printf("step row num : %d, %s, %d, %d\n", time, pdu, pdu_size, flag);
 72     }
 73 
 74     sqlite3_finalize(statement);
75 }

 

 

 

int sqlite3_step(sqlite3_stmt*);
the return value will be either SQLITE_BUSYSQLITE_DONESQLITE_ROWSQLITE_ERROR, or SQLITE_MISUSE

SQLITE_BUSY means that the database engine was unable to acquire the database locks it needs to do its job. If the statement is a COMMIT or occurs outside of an explicit transaction, then you can retry the statement. If the statement is not a COMMIT and occurs within an explicit transaction then you should rollback the transaction before continuing.

SQLITE_DONE means that the statement has finished executing successfully. sqlite3_step() should not be called again on this virtual machine without first callingsqlite3_reset() to reset the virtual machine back to its initial state.

If the SQL statement being executed returns any data, then SQLITE_ROW is returned each time a new row of data is ready for processing by the caller. The values may be accessed using the column access functions. sqlite3_step() is called again to retrieve the next row of data.

SQLITE_ERROR means that a run-time error (such as a constraint violation) has occurred. sqlite3_step() should not be called again on the VM. More information may be found by calling sqlite3_errmsg(). With the legacy interface, a more specific error code (for example, SQLITE_INTERRUPTSQLITE_SCHEMASQLITE_CORRUPT, and so forth) can be obtained by calling sqlite3_reset() on the prepared statement. In the "v2" interface, the more specific error code is returned directly by sqlite3_step().

SQLITE_MISUSE means that the this routine was called inappropriately. Perhaps it was called on a prepared statement that has already been finalized or on one that had previously returned SQLITE_ERROR or SQLITE_DONE. Or it could be the case that the same database connection is being used by two or more threads at the same moment in time.


 

 

const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
double sqlite3_column_double(sqlite3_stmt*, int iCol);
int sqlite3_column_int(sqlite3_stmt*, int iCol);
sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
int sqlite3_column_type(sqlite3_stmt*, int iCol);
sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值