📄 capi3ref.html
字号:
when SQLite is in the middle of a large transaction where all thechanges will not fit into the in-memory cache. SQLite willalready hold a RESERVED lock on the database file, but it needsto promote this lock to EXCLUSIVE so that it can spill cachepages into the database file without harm to concurrentreaders. If it is unable to promote the lock, then the in-memorycache will be left in an inconsistent state and so the errorcode is promoted from the relatively benign <a href="#SQLITE_ABORT">SQLITE_BUSY</a> tothe more severe <a href="#SQLITE_IOERR_BLOCKED">SQLITE_IOERR_BLOCKED</a>. This error code promotionforces an automatic rollback of the changes. See the<a href="http://www.sqlite.org/cvstrac/wiki?p=CorruptionFollowingBusyError">CorruptionFollowingBusyError</a> wiki page for a discussion of whythis is important.</p><p>There can only be a single busy handler defined for each databaseconnection. Setting a new busy handler clears any previous one.Note that calling <a href="#sqlite3_busy_timeout">sqlite3_busy_timeout()</a> will also set or clearthe busy handler.</p><p><h3>Invariants:</h3><table border="0" cellpadding="5" cellspacing="0"><tr><td valign="top">F12311</td> <td valign="top">The <a href="#sqlite3_busy_handler">sqlite3_busy_handler()</a> function replaces the busy handlercallback in the database connection identified by the 1stparameter with a new busy handler identified by the 2nd and 3rdparameters.</td></tr><tr><td valign="top">F12312</td> <td valign="top">The default busy handler for new database connections is NULL.</td></tr><tr><td valign="top">F12314</td> <td valign="top">When two or more database connection share a common cache,the busy handler for the database connection currently usingthe cache is invoked when the cache encounters a lock.</td></tr><tr><td valign="top">F12316</td> <td valign="top">If a busy handler callback returns zero, then the SQLiteinterface that provoked the locking event will return<a href="#SQLITE_ABORT">SQLITE_BUSY</a>.</td></tr><tr><td valign="top">F12318</td> <td valign="top">SQLite will invokes the busy handler with two argument whichare a copy of the pointer supplied by the 3rd parameter to<a href="#sqlite3_busy_handler">sqlite3_busy_handler()</a> and a count of the number of priorinvocations of the busy handler for the same locking event.</td></tr></table></p><p><h3>Limitations:</h3><table border="0" cellpadding="5" cellspacing="0"><tr><td valign="top">U12319</td> <td valign="top">A busy handler should not call close the database connectionor prepared statement that invoked the busy handler.</td></tr></table></p><hr><a name="sqlite3_busy_timeout"></a><h2>Set A Busy Timeout</h2><blockquote><pre>int sqlite3_busy_timeout(sqlite3*, int ms);</pre></blockquote><p>This routine sets a <a href="#sqlite3_busy_handler">busy handler</a>that sleeps for a while when atable is locked. The handler will sleep multiple times untilat least "ms" milliseconds of sleeping have been done. After"ms" milliseconds of sleeping, the handler returns 0 whichcauses <a href="#sqlite3_step">sqlite3_step()</a> to return <a href="#SQLITE_ABORT">SQLITE_BUSY</a> or <a href="#SQLITE_IOERR_BLOCKED">SQLITE_IOERR_BLOCKED</a>.</p><p>Calling this routine with an argument less than or equal to zeroturns off all busy handlers.</p><p>There can only be a single busy handler for a particular databaseconnection. If another busy handler was defined(using <a href="#sqlite3_busy_handler">sqlite3_busy_handler()</a>) prior to callingthis routine, that other busy handler is cleared.</p><p><h3>Invariants:</h3><table border="0" cellpadding="5" cellspacing="0"><tr><td valign="top">F12341</td> <td valign="top">The <a href="#sqlite3_busy_timeout">sqlite3_busy_timeout()</a> function overrides any prior<a href="#sqlite3_busy_timeout">sqlite3_busy_timeout()</a> or <a href="#sqlite3_busy_handler">sqlite3_busy_handler()</a> settingon the same database connection.</td></tr><tr><td valign="top">F12343</td> <td valign="top">If the 2nd parameter to <a href="#sqlite3_busy_timeout">sqlite3_busy_timeout()</a> is less thanor equal to zero, then the busy handler is cleared so thatall subsequent locking events immediately return <a href="#SQLITE_ABORT">SQLITE_BUSY</a>.</td></tr><tr><td valign="top">F12344</td> <td valign="top">If the 2nd parameter to <a href="#sqlite3_busy_timeout">sqlite3_busy_timeout()</a> is a positivenumber N, then a busy handler is set that repeatedly callsthe xSleep() method in the VFS interface until either thelock clears or until the cumulative sleep time reported backby xSleep() exceeds N milliseconds.</td></tr></table></p><hr><a name="sqlite3_changes"></a><h2>Count The Number Of Rows Modified</h2><blockquote><pre>int sqlite3_changes(sqlite3*);</pre></blockquote><p>This function returns the number of database rows that were changedor inserted or deleted by the most recently completed SQL statementon the connection specified by the first parameter. Onlychanges that are directly specified by the INSERT, UPDATE, orDELETE statement are counted. Auxiliary changes caused bytriggers are not counted. Use the <a href="#sqlite3_total_changes">sqlite3_total_changes()</a> functionto find the total number of changes including changes caused by triggers.</p><p>A "row changes" is a change to a single row of a single tablecaused by an INSERT, DELETE, or UPDATE statement. Rows thatare changed as side effects of REPLACE constraint resolution,rollback, ABORT processing, DROP TABLE, or by any othermechanisms do not count as direct row changes.</p><p>A "trigger context" is a scope of execution that begins andends with the script of a trigger. Most SQL statements areevaluated outside of any trigger. This is the "top level"trigger context. If a trigger fires from the top level, anew trigger context is entered for the duration of that onetrigger. Subtriggers create subcontexts for their duration.</p><p>Calling <a href="#sqlite3_exec">sqlite3_exec()</a> or <a href="#sqlite3_step">sqlite3_step()</a> recursively doesnot create a new trigger context.</p><p>This function returns the number of direct row changes in themost recent INSERT, UPDATE, or DELETE statement within the sametrigger context.</p><p>So when called from the top level, this function returns thenumber of changes in the most recent INSERT, UPDATE, or DELETEthat also occurred at the top level.Within the body of a trigger, the sqlite3_changes() interfacecan be called to find the number ofchanges in the most recently completed INSERT, UPDATE, or DELETEstatement within the body of the same trigger.However, the number returned does not include in changescaused by subtriggers since they have their own context.</p><p>SQLite implements the command "DELETE FROM table" withouta WHERE clause by dropping and recreating the table. (This is muchfaster than going through and deleting individual elements from thetable.) Because of this optimization, the deletions in"DELETE FROM table" are not row changes and will not be countedby the sqlite3_changes() or <a href="#sqlite3_total_changes">sqlite3_total_changes()</a> functions.To get an accurate count of the number of rows deleted, use"DELETE FROM table WHERE 1" instead.</p><p><h3>Invariants:</h3><table border="0" cellpadding="5" cellspacing="0"><tr><td valign="top">F12241</td> <td valign="top">The <a href="#sqlite3_changes">sqlite3_changes()</a> function returns the number ofrow changes caused by the most recent INSERT, UPDATE,or DELETE statement on the same database connection andwithin the same trigger context, or zero if there havenot been any qualifying row changes.</td></tr></table></p><p><h3>Limitations:</h3><table border="0" cellpadding="5" cellspacing="0"><tr><td valign="top">U12252</td> <td valign="top">If a separate thread makes changes on the same database connectionwhile <a href="#sqlite3_changes">sqlite3_changes()</a> is running then the value returnedis unpredictable and unmeaningful.</td></tr></table></p><hr><a name="sqlite3_clear_bindings"></a><h2>Reset All Bindings On A Prepared Statement</h2><blockquote><pre>int sqlite3_clear_bindings(sqlite3_stmt*);</pre></blockquote><p>Contrary to the intuition of many, <a href="#sqlite3_reset">sqlite3_reset()</a> does notreset the <a href="#sqlite3_bind_blob">bindings</a> on a<a href="#sqlite3_stmt">prepared statement</a>. Use this routine toreset all host parameters to NULL.</p><p><h3>Invariants:</h3><table border="0" cellpadding="5" cellspacing="0"><tr><td valign="top">F13661</td> <td valign="top">The <a href="#sqlite3_clear_bindings">sqlite3_clear_bindings(S)</a> interface resets allSQL parameter bindings in <a href="#sqlite3_stmt">prepared statement</a> Sback to NULL.</td></tr></table></p><hr><a name="sqlite3_close"></a><h2>Closing A Database Connection</h2><blockquote><pre>int sqlite3_close(sqlite3 *);</pre></blockquote><p>This routine is the destructor for the <a href="#sqlite3">sqlite3</a> object.</p><p>Applications should <a href="#sqlite3_finalize">finalize</a> all<a href="#sqlite3_stmt">prepared statements</a> and<a href="#sqlite3_blob_close">close</a> all <a href="#sqlite3_blob">BLOBs</a>associated with the <a href="#sqlite3">sqlite3</a> object priorto attempting to close the <a href="#sqlite3">sqlite3</a> object.</p><p><font color="red">(TODO: What happens to pending transactions? Are theyrolled back, or abandoned?)</font></p><p><h3>Invariants:</h3><table border="0" cellpadding="5" cellspacing="0"><tr><td valign="top">F12011</td> <td valign="top">The <a href="#sqlite3_close">sqlite3_close()</a> interface destroys an <a href="#sqlite3">sqlite3</a> objectallocated by a prior call to <a href="#sqlite3_open">sqlite3_open()</a>,<a href="#sqlite3_open">sqlite3_open16()</a>, or <a href="#sqlite3_open">sqlite3_open_v2()</a>.</td></tr><tr><td valign="top">F12012</td> <td valign="top">The <a href="#sqlite3_close">sqlite3_close()</a> function releases all memory used by theconnection and closes all open files.</td></tr><tr><td valign="top">F12013</td> <td valign="top">If the database connection contains<a href="#sqlite3_stmt">prepared statements</a> that have not beenfinalized by <a href="#sqlite3_finalize">sqlite3_finalize()</a>, then <a href="#sqlite3_close">sqlite3_close()</a>returns <a href="#SQLITE_ABORT">SQLITE_BUSY</a> and leaves the connection open.</td></tr><tr><td valign="top">F12014</td> <td valign="top">Giving sqlite3_close() a NULL pointer is a harmless no-op.</td></tr></table></p><p><h3>Limitations:</h3><table border="0" cellpadding="5" cellspacing="0"><tr><td valign="top">U12015</td> <td valign="top">The parameter to <a href="#sqlite3_close">sqlite3_close()</a> must be an <a href="#sqlite3">sqlite3</a> objectpointer previously obtained from <a href="#sqlite3_open">sqlite3_open()</a> or theequivalent, or NULL.</td></tr><tr><td valign="top">U12016</td> <td valign="top">The parameter to <a href="#sqlite3_close">sqlite3_close()</a> must not have been previouslyclosed.</td></tr></table></p><hr><a name="sqlite3_column_count"></a><h2>Number Of Columns In A Result Set</h2><blockquote><pre>int sqlite3_column_count(sqlite3_stmt *pStmt);</pre></blockquote><p>Return the number of columns in the result set returned by the<a href="#sqlite3_stmt">prepared statement</a>. This routine returns 0if pStmt is an SQL statement that does not return data (forexample an UPDATE).</p><p><h3>Invariants:</h3><table border="0" cellpadding="5" cellspacing="0"><tr><td valign="top">F13711</td> <td valign="top">The <a href="#sqlite3_column_count">sqlite3_column_count(S)</a> interface returns the number ofcolumns in the result set generated by the<a href="#sqlite3_stmt">prepared statement</a> S, or 0 if S does not generatea result set.</td></tr></table></p><hr><a name="sqlite3_data_count"></a><h2>Number of columns in a result set</h2><blockquote><pre>int sqlite3_data_count(sqlite3_stmt *pStmt);</pre></blockquote><p>Return the number of values in the current row of the result set.</p><p><h3>Invariants:</h3><table border="0" cellpadding="5" cellspacing="0"><tr><td valign="top">F13771</td> <td valign="top">After a call to <a href="#sqlite3_step">sqlite3_step(S)</a> that returns<a href="#SQLITE_ABORT">SQLITE_ROW</a>, the <a href="#sqlite3_data_count">sqlite3_data_count(S)</a> routinewill return the same value as the<a href="#sqlite3_column_count">sqlite3_column_count(S)</a> function.</td></tr><tr><td valign="top">F13772</td> <td valign="top">After <a href="#sqlite3_step">sqlite3_step(S)</a> has returned any value other than<a href="#SQLITE_ABORT">SQLITE_ROW</a> or before <a href="#sqlite3_step">sqlite3_step(S)</a> has beencalled on the <a href="#sqlite3_stmt">prepared statement</a> forthe first time since it was <a href="#sqlite3_prepare">prepared</a>or <a href="#sqlite3_reset">reset</a>, the <a href="#sqlite3_data_count">sqlite3_data_count(S)</a>routine returns zero.</td></tr></table></p><hr><a name="sqlite3_db_handle"></a><h2>Find The Database Handle Of A Prepared Statement</h2><blockquote><pre>sqlite3 *sqlite3_db_handle(sqlite3_stmt*);</pre></blockquote><p> The sqlite3_db_handle interfacereturns the <a href="#sqlite3">sqlite3*</a> database handle to which a<a href="#sqlite3_stmt">prepared statement</a> belongs. th
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -