[Database]Sqlite中常用資料、方法與Error Codes..

來源:互聯網
上載者:User
sqlite3*           // A session of database connectionsqlite3_stmt*  // SQL Statement Object>> Supported Data Types of Column似乎SQLite2僅僅支援TEXT類型,在SQLite3中大大豐富了。TEXT NUMERIC INTEGER REAL NONE>> Methods:Sqlite3有82個函數,但是常用的也就那麼幾個:// LibraryInitialization/Shutdownint sqlite3_initialize(void);int sqlite3_shutdown(void);// Database Modify/Queryint sqlite3_open(const char*, sqlite3**);int sqlite3_close(sqlite3*);int sqlite3_exec(sqlite3*, const char *sql, sqlite_callback, void*, char**);int sqlite3_prepare( sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **ppStmt, const char **pzTail);int sqlite3_step(sqlite3_stmt *pStmt);int sqlite3_finalize(sqlite3_stmt *pStmt)int sqlite3_reset(sqlite3_stmt *pStmt);// Bindingsqlite3_bind_blob(sqlite3_stmt *pStmt, int i, const void *zData, int nData, void (*xDel)(void*));int sqlite3_bind_xxx(sqlite3_stmt *pStmt, int i, xxx rValue)int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName);int sqlite3_clear_bindings(sqlite3_stmt *pStmt);// Get dataint sqlite3_get_table(sqlite3*, const char *sql,char***result, int *nrow,int *ncolumn ,char **errmsg );const unsigned char* sqlite3_column_text(sqlite3_stmt *pStmt, int i);const void* sqlite3_column_blob(sqlite3_stmt *pStmt, int i);sqlite3_column_int(sqlite3_stmt *pStmt, int i);// Error Handlingint sqlite3_busy_handler(sqlite3 *db, int (*xBusy)(void*,int), void *pArg)sqlite3_errcode() sqlite3_errmsg() SQLite3好些函數屁股後面帶著16或者v2,前者表示為UTF16編碼,後者則為該函數的增強版,頗有些Windows API中EX的味道。 >> Error Codes:----------------------------------------------------------#define SQLITE_OK              0   /* Successful result */#define SQLITE_ERROR        1   /* SQL error or missing database */#define SQLITE_INTERNAL    2   /* Internal logic error in SQLite */#define SQLITE_PERM         3   /* Access permission denied */#define SQLITE_ABORT        4   /* Callback routine requested an abort */#define SQLITE_BUSY         5   /* The database file is locked */#define SQLITE_LOCKED       6   /* A table in the database is locked */#define SQLITE_NOMEM        7   /* A malloc() failed */#define SQLITE_READONLY     8   /* Attempt to write a readonly database */#define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite3_interrupt()*/#define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */#define SQLITE_CORRUPT     11   /* The database disk image is malformed */#define SQLITE_NOTFOUND    12   /* Unknown opcode in sqlite3_file_control() */#define SQLITE_FULL        13   /* Insertion failed because database is full */#define SQLITE_CANTOPEN    14   /* Unable to open the database file */#define SQLITE_PROTOCOL    15   /* Database lock protocol error */#define SQLITE_EMPTY       16   /* Database is empty */#define SQLITE_SCHEMA      17   /* The database schema changed */#define SQLITE_TOOBIG      18   /* String or BLOB exceeds size limit */#define SQLITE_CONSTRAINT  19   /* Abort due to constraint violation */#define SQLITE_MISMATCH    20   /* Data type mismatch */#define SQLITE_MISUSE      21   /* Library used incorrectly */#define SQLITE_NOLFS       22   /* Uses OS features not supported on host */#define SQLITE_AUTH        23   /* Authorization denied */#define SQLITE_FORMAT      24   /* Auxiliary database format error */#define SQLITE_RANGE       25   /* 2nd parameter to sqlite3_bind out of range */#define SQLITE_NOTADB      26   /* File opened that is not a database file */#define SQLITE_ROW         100  /* sqlite3_step() has another row ready */#define SQLITE_DONE        101  /* sqlite3_step() has finished executing */----------------------------------------------------------------->> Transaction(交易處理) sqlite支援Transaction,為了提高Performance,有必要盡量把同類操作搞成一個Transaction,一次刪除1W條資料與分1W次刪除資料的效能絕對不是一樣的。這種情況下,做成統一事務吧,而且還便於Rollback。 >> Thread SafeSQLite 是安全執行緒的,但在編譯時間必須將 SQLITE_THREADSAFE 預先處理宏置為1。在 3.3.1 版本之前,一個 sqlite3 結構只能被用於調用 sqlite3_open 建立的同一線程。你不能在一個線程中開啟資料庫, 然後將資料庫控制代碼傳遞給另外一個進程使用。在3.3.1以後的版本中,只要串連沒有持有 fcntl() 鎖,線上程間移動控制代碼是安全的。 >> SQLite pragmaThe PRAGMA statement is an SQL extension specific to SQLite and used to modify the operation of the SQLite library or to query the SQLite library for internal (non-table) data.PRAGMA command 是一個特殊的命令。它用於修改 SQLite 庫操作或查詢庫以取得內部(非表)資料•    auto_vacuum •    automatic_index •    cache_size •    case_sensitive_like •    checkpoint_fullfsync •    collation_list •    compile_options     •    database_list     •    encoding •    foreign_key_list •    foreign_keys •    freelist_count •    fullfsync •    ignore_check_constraints •    incremental_vacuum •    index_info •    index_list •    integrity_check •    journal_mode •    journal_size_limit •    legacy_file_format •    locking_mode •    max_page_count •    page_count •    page_size •    parser_trace•    quick_check •    read_uncommitted •    recursive_triggers •    reverse_unordered_selects •    schema_version •    secure_delete •    synchronous •    table_info •    temp_store     •    user_version •    vdbe_listing •    vdbe_trace •    wal_autocheckpoint •    wal_checkpoint •    writable_schema

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.