📄 capi3.html
字号:
</p><p>After an SQL statement has been prepared (and optionally bound), itis executed using:</p><blockquote><pre> int sqlite3_step(sqlite3_stmt*);</pre></blockquote><p>The sqlite3_step() routine return SQLITE_ROW if it is returning a singlerow of the result set, or SQLITE_DONE if execution has completed, eithernormally or due to an error. It might also return SQLITE_BUSY if it isunable to open the database file. If the return value is SQLITE_ROW, thenthe following routines can be used to extract information about that rowof the result set:</p><blockquote><pre> 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); int sqlite3_column_count(sqlite3_stmt*); const char *sqlite3_column_decltype(sqlite3_stmt *, int iCol); const void *sqlite3_column_decltype16(sqlite3_stmt *, int iCol); double sqlite3_column_double(sqlite3_stmt*, int iCol); int sqlite3_column_int(sqlite3_stmt*, int iCol); long long int sqlite3_column_int64(sqlite3_stmt*, int iCol); const char *sqlite3_column_name(sqlite3_stmt*, int iCol); const void *sqlite3_column_name16(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);</pre></blockquote><p>The <a href="c3ref/column_count.html">sqlite3_column_count()</a>function returns the number of columns inthe results set. sqlite3_column_count() can be called at any time after<a href="c3ref/prepare.html">sqlite3_prepare_v2()</a>. <a href="c3ref/data_count.html">sqlite3_data_count()</a> works similarly to<a href="c3ref/column_count.html">sqlite3_column_count()</a> except that it only works following <a href="c3ref/step.html">sqlite3_step()</a>.If the previous call to <a href="c3ref/step.html">sqlite3_step()</a> returned SQLITE_DONE or an error code,then <a href="c3ref/data_count.html">sqlite3_data_count()</a> will return 0 whereas <a href="c3ref/column_count.html">sqlite3_column_count()</a> willcontinue to return the number of columns in the result set.</p><p>Returned data is examined using the other <a href="c3ref/column_blob.html">sqlite3_column_***()</a> functions, all of which take a column number as their second parameter. Columns arezero-indexed from left to right. Note that this is different to parameters,which are indexed starting at one.</p><p>The <a href="c3ref/column_blob.html">sqlite3_column_type()</a> function returns thedatatype for the value in the Nth column. The return value is oneof these:</p><blockquote><pre> #define SQLITE_INTEGER 1 #define SQLITE_FLOAT 2 #define SQLITE_TEXT 3 #define SQLITE_BLOB 4 #define SQLITE_NULL 5</pre></blockquote><p>The sqlite3_column_decltype() routine returns text which is thedeclared type of the column in the CREATE TABLE statement. For anexpression, the return type is an empty string. sqlite3_column_name()returns the name of the Nth column. sqlite3_column_bytes() returnsthe number of bytes in a column that has type BLOB or the number of bytesin a TEXT string with UTF-8 encoding. sqlite3_column_bytes16() returnsthe same value for BLOBs but for TEXT strings returns the number of bytesin a UTF-16 encoding.sqlite3_column_blob() return BLOB data. sqlite3_column_text() return TEXT data as UTF-8.sqlite3_column_text16() return TEXT data as UTF-16.sqlite3_column_int() return INTEGER data in the host machines nativeinteger format.sqlite3_column_int64() returns 64-bit INTEGER data.Finally, sqlite3_column_double() return floating point data.</p><p>It is not necessary to retrieve data in the format specify bysqlite3_column_type(). If a different format is requested, the datais converted automatically.</p><p>Data format conversions can invalidate the pointer returned byprior calls to sqlite3_column_blob(), sqlite3_column_text(), and/orsqlite3_column_text16(). Pointers might be invalided in the followingcases:</p><ul><li><p>The initial content is a BLOB and sqlite3_column_text() or sqlite3_column_text16()is called. A zero-terminator might need to be added to the string.</p></li><li><p>The initial content is UTF-8 text and sqlite3_column_bytes16() orsqlite3_column_text16() is called. The content must be converted to UTF-16.</p></li><li><p>The initial content is UTF-16 text and sqlite3_column_bytes() orsqlite3_column_text() is called. The content must be converted to UTF-8.</p></li></ul><p>Note that conversions between UTF-16be and UTF-16le are always done in place and donot invalidate a prior pointer, though of course the content of the bufferthat the prior pointer points to will have been modified. Other kindsof conversion are done in place when it is possible, but sometime it isnot possible and in those cases prior pointers are invalidated. </p><p>The safest and easiest to remember policy is this: assume that anyresult from<ul><li>sqlite3_column_blob(),</li><li>sqlite3_column_text(), or</li><li>sqlite3_column_text16()</li></ul>is invalided by subsequent calls to <ul><li>sqlite3_column_bytes(),</li><li>sqlite3_column_bytes16(),</li><li>sqlite3_column_text(), or</li><li>sqlite3_column_text16().</li></ul>This means that you should always call sqlite3_column_bytes() orsqlite3_column_bytes16() <u>before</u> calling sqlite3_column_blob(),sqlite3_column_text(), or sqlite3_column_text16().</p><h4>2.3 User-defined functions</h4><p>User defined functions can be created using the following routine:</p><blockquote><pre> typedef struct sqlite3_value sqlite3_value; int sqlite3_create_function( sqlite3 *, const char *zFunctionName, int nArg, int eTextRep, void*, void (*xFunc)(sqlite3_context*,int,sqlite3_value**), void (*xStep)(sqlite3_context*,int,sqlite3_value**), void (*xFinal)(sqlite3_context*) ); int sqlite3_create_function16( sqlite3*, const void *zFunctionName, int nArg, int eTextRep, void*, void (*xFunc)(sqlite3_context*,int,sqlite3_value**), void (*xStep)(sqlite3_context*,int,sqlite3_value**), void (*xFinal)(sqlite3_context*) ); #define SQLITE_UTF8 1 #define SQLITE_UTF16 2 #define SQLITE_UTF16BE 3 #define SQLITE_UTF16LE 4 #define SQLITE_ANY 5</pre></blockquote><p>The nArg parameter specifies the number of arguments to the function.A value of 0 indicates that any number of arguments is allowed. TheeTextRep parameter specifies what representation text values are expectedto be in for arguments to this function. The value of this parameter shouldbe one of the parameters defined above. SQLite version 3 allows multipleimplementations of the same function using different text representations.The database engine chooses the function that minimization the numberof text conversions required.</p><p>Normal functions specify only xFunc and leave xStep and xFinal set to NULL.Aggregate functions specify xStep and xFinal and leave xFunc set to NULL.There is no separate sqlite3_create_aggregate() API.</p><p>The function name is specified in UTF-8. A separate sqlite3_create_function16()API works the same as sqlite_create_function()except that the function name is specified in UTF-16 host byte order.</p><p>Notice that the parameters to functions are now pointers to sqlite3_valuestructures instead of pointers to strings as in SQLite version 2.X.The following routines are used to extract useful information from these"values":</p><blockquote><pre> const void *sqlite3_value_blob(sqlite3_value*); int sqlite3_value_bytes(sqlite3_value*); int sqlite3_value_bytes16(sqlite3_value*); double sqlite3_value_double(sqlite3_value*); int sqlite3_value_int(sqlite3_value*); long long int sqlite3_value_int64(sqlite3_value*); const unsigned char *sqlite3_value_text(sqlite3_value*); const void *sqlite3_value_text16(sqlite3_value*); int sqlite3_value_type(sqlite3_value*);</pre></blockquote><p>Function implementations use the following APIs to acquire context andto report results:</p><blockquote><pre> void *sqlite3_aggregate_context(sqlite3_context*, int nbyte); void *sqlite3_user_data(sqlite3_context*); void sqlite3_result_blob(sqlite3_context*, const void*, int n, void(*)(void*)); void sqlite3_result_double(sqlite3_context*, double); void sqlite3_result_error(sqlite3_context*, const char*, int); void sqlite3_result_error16(sqlite3_context*, const void*, int); void sqlite3_result_int(sqlite3_context*, int); void sqlite3_result_int64(sqlite3_context*, long long int); void sqlite3_result_null(sqlite3_context*); void sqlite3_result_text(sqlite3_context*, const char*, int n, void(*)(void*)); void sqlite3_result_text16(sqlite3_context*, const void*, int n, void(*)(void*)); void sqlite3_result_value(sqlite3_context*, sqlite3_value*); void *sqlite3_get_auxdata(sqlite3_context*, int); void sqlite3_set_auxdata(sqlite3_context*, int, void*, void (*)(void*));</pre></blockquote><h4>2.4 User-defined collating sequences</h4><p>The following routines are used to implement user-definedcollating sequences:</p><blockquote><pre> sqlite3_create_collation(sqlite3*, const char *zName, int eTextRep, void*, int(*xCompare)(void*,int,const void*,int,const void*)); sqlite3_create_collation16(sqlite3*, const void *zName, int eTextRep, void*, int(*xCompare)(void*,int,const void*,int,const void*)); sqlite3_collation_needed(sqlite3*, void*, void(*)(void*,sqlite3*,int eTextRep,const char*)); sqlite3_collation_needed16(sqlite3*, void*, void(*)(void*,sqlite3*,int eTextRep,const void*));</pre></blockquote><p>The sqlite3_create_collation() function specifies a collating sequence nameand a comparison function to implement that collating sequence. Thecomparison function is only used for comparing text values. The eTextRepparameter is one of SQLITE_UTF8, SQLITE_UTF16LE, SQLITE_UTF16BE, orSQLITE_ANY to specify which text representation the comparison function workswith. Separate comparison functions can exist for the same collatingsequence for each of the UTF-8, UTF-16LE and UTF-16BE text representations.The sqlite3_create_collation16() works like sqlite3_create_collation() exceptthat the collation name is specified in UTF-16 host byte order instead ofin UTF-8.</p><p>The sqlite3_collation_needed() routine registers a callback which thedatabase engine will invoke if it encounters an unknown collating sequence.The callback can lookup an appropriate comparison function and invokesqlite_3_create_collation() as needed. The fourth parameter to the callbackis the name of the collating sequence in UTF-8. For sqlite3_collation_need16()the callback sends the collating sequence name in UTF-16 host byte order.</p><hr><small<i>This page last modified 2007/12/19 13:42:44 UTC</i></small></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -