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);
    原文作者:sqlite
    原文地址: https://www.cnblogs.com/hushaojun/p/5261334.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞