📄 bind_blob.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>Binding Values To Prepared Statements</title><style type="text/css">body { margin: auto; font-family: "Verdana" "sans-serif"; padding: 8px 1%;}a { color: #45735f }a:visited { color: #734559 }.logo { position:absolute; margin:3px; }.tagline { float:right; text-align:right; font-style:italic; width:240px; margin:12px; margin-top:58px;}.toolbar { font-variant: small-caps; text-align: center; line-height: 1.6em; margin: 0; padding:1px 8px;}.toolbar a { color: white; text-decoration: none; padding: 6px 12px; }.toolbar a:visited { color: white; }.toolbar a:hover { color: #80a796; background: white; }.content { margin: 5%; }.content dt { font-weight:bold; }.content dd { margin-bottom: 25px; margin-left:20%; }.content ul { padding:0px; padding-left: 15px; margin:0px; }/* rounded corners */.se { background: url(../images/se.png) 100% 100% no-repeat #80a796}.sw { background: url(../images/sw.png) 0% 100% no-repeat }.ne { background: url(../images/ne.png) 100% 0% no-repeat }.nw { background: url(../images/nw.png) 0% 0% no-repeat }</style><meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head><body><div><!-- container div to satisfy validator --><a href="../index.html"><img class="logo" src="../images/SQLite.gif" alt="SQLite Logo" border="0"></a><div><!-- IE hack to prevent disappearing logo--></div><div class="tagline">Small. Fast. Reliable.<br>Choose any three.</div><table width=100% style="clear:both"><tr><td> <div class="se"><div class="sw"><div class="ne"><div class="nw"> <div class="toolbar"> <a href="../about.html">About</a> <a href="../sitemap.html">Sitemap</a> <a href="../docs.html">Documentation</a> <a href="../download.html">Download</a> <a href="../copyright.html">License</a> <a href="../news.html">News</a> <a href="http://www.sqlite.org/cvstrac/index">Developers</a> <a href="../support.html">Support</a> </div></div></div></div></div></td></tr></table> <a href="intro.html"><h2>SQLite C Interface</h2></a><h2>Binding Values To Prepared Statements</h2><blockquote><pre>int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));int sqlite3_bind_double(sqlite3_stmt*, int, double);int sqlite3_bind_int(sqlite3_stmt*, int, int);int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);int sqlite3_bind_null(sqlite3_stmt*, int);int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);</pre></blockquote><p>In the SQL strings input to <a href="../c3ref/prepare.html">sqlite3_prepare_v2()</a> and its variants,literals may be replaced by a parameter in one of these forms:</p><p><ul><li> ?<li> ?NNN<li> :VVV<li> @VVV<li> $VVV</ul></p><p>In the parameter forms shown above NNN is an integer literal,and VVV is an alpha-numeric parameter name. The values of theseparameters (also called "host parameter names" or "SQL parameters")can be set using the sqlite3_bind_*() routines defined here.</p><p>The first argument to the sqlite3_bind_*() routines is alwaysa pointer to the <a href="../c3ref/stmt.html">sqlite3_stmt</a> object returned from<a href="../c3ref/prepare.html">sqlite3_prepare_v2()</a> or its variants.</p><p>The second argument is the index of the SQL parameter to be set.The leftmost SQL parameter has an index of 1. When the same namedSQL parameter is used more than once, second and subsequentoccurrences have the same index as the first occurrence.The index for named parameters can be looked up using the<a href="../c3ref/bind_parameter_index.html">sqlite3_bind_parameter_index()</a> API if desired. The indexfor "?NNN" parameters is the value of NNN.The NNN value must be between 1 and the <a href="../c3ref/limit.html">sqlite3_limit()</a>parameter <a href="../c3ref/c_limit_attached.html">SQLITE_LIMIT_VARIABLE_NUMBER</a> (default value: 999).</p><p>The third argument is the value to bind to the parameter.</p><p>In those routines that have a fourth argument, its value is thenumber of bytes in the parameter. To be clear: the value is thenumber of <u>bytes</u> in the value, not the number of characters.If the fourth parameter is negative, the length of the string isthe number of bytes up to the first zero terminator.</p><p>The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), andsqlite3_bind_text16() is a destructor used to dispose of the BLOB orstring after SQLite has finished with it. If the fifth argument isthe special value <a href="../c3ref/c_static.html">SQLITE_STATIC</a>, then SQLite assumes that theinformation is in static, unmanaged space and does not need to be freed.If the fifth argument has the value <a href="../c3ref/c_static.html">SQLITE_TRANSIENT</a>, thenSQLite makes its own private copy of the data immediately, beforethe sqlite3_bind_*() routine returns.</p><p>The sqlite3_bind_zeroblob() routine binds a BLOB of length N thatis filled with zeroes. A zeroblob uses a fixed amount of memory(just an integer to hold its size) while it is being processed.Zeroblobs are intended to serve as placeholders for BLOBs whosecontent is later written using<a href="../c3ref/blob_open.html">incremental BLOB I/O</a> routines.A negative value for the zeroblob results in a zero-length BLOB.</p><p>The sqlite3_bind_*() routines must be called after<a href="../c3ref/prepare.html">sqlite3_prepare_v2()</a> (and its variants) or <a href="../c3ref/reset.html">sqlite3_reset()</a> andbefore <a href="../c3ref/step.html">sqlite3_step()</a>.Bindings are not cleared by the <a href="../c3ref/reset.html">sqlite3_reset()</a> routine.Unbound parameters are interpreted as NULL.</p><p>These routines return <a href="../c3ref/c_abort.html">SQLITE_OK</a> on success or an error code ifanything goes wrong. <a href="../c3ref/c_abort.html">SQLITE_RANGE</a> is returned if the parameterindex is out of range. <a href="../c3ref/c_abort.html">SQLITE_NOMEM</a> is returned if malloc() fails.<a href="../c3ref/c_abort.html">SQLITE_MISUSE</a> might be returned if these routines are called on avirtual machine that is the wrong state or which has already been finalized.Detection of misuse is unreliable. Applications should not dependon SQLITE_MISUSE returns. SQLITE_MISUSE is intended to indicate aa logic error in the application. Future versions of SQLite mightpanic rather than return SQLITE_MISUSE.</p><p>See also: <a href="../c3ref/bind_parameter_count.html">sqlite3_bind_parameter_count()</a>,<a href="../c3ref/bind_parameter_name.html">sqlite3_bind_parameter_name()</a>, and <a href="../c3ref/bind_parameter_index.html">sqlite3_bind_parameter_index()</a>.</p><p><h3>Invariants:</h3><table border="0" cellpadding="5" cellspacing="0"><tr><td valign="top">H13506</td> <td valign="top">The <a href="../c3ref/prepare.html">SQL statement compiler</a> recognizes tokens of the forms"?", "?NNN", "$VVV", ":VVV", and "@VVV" as SQL parameters,where NNN is any sequence of one or more digitsand where VVV is any sequence of one or more alphanumericcharacters or "::" optionally followed by a string containingno spaces and contained within parentheses.</td></tr><tr><td valign="top">H13509</td> <td valign="top">The initial value of an SQL parameter is NULL.</td></tr><tr><td valign="top">H13512</td> <td valign="top">The index of an "?" SQL parameter is one larger than thelargest index of SQL parameter to the left, or 1 ifthe "?" is the leftmost SQL parameter.</td></tr><tr><td valign="top">H13515</td> <td valign="top">The index of an "?NNN" SQL parameter is the integer NNN.</td></tr><tr><td valign="top">H13518</td> <td valign="top">The index of an ":VVV", "$VVV", or "@VVV" SQL parameter isthe same as the index of leftmost occurrences of the sameparameter, or one more than the largest index over allparameters to the left if this is the first occurrenceof this parameter, or 1 if this is the leftmost parameter.</td></tr><tr><td valign="top">H13521</td> <td valign="top">The <a href="../c3ref/prepare.html">SQL statement compiler</a> fails with an <a href="../c3ref/c_abort.html">SQLITE_RANGE</a>error if the index of an SQL parameter is less than 1or greater than the compile-time SQLITE_MAX_VARIABLE_NUMBERparameter.</td></tr><tr><td valign="top">H13524</td> <td valign="top">Calls to <a href="../c3ref/bind_blob.html">sqlite3_bind(S,N,V,...)</a>associate the value V with all SQL parameters having anindex of N in the <a href="../c3ref/stmt.html">prepared statement</a> S.</td></tr><tr><td valign="top">H13527</td> <td valign="top">Calls to <a href="../c3ref/bind_blob.html">sqlite3_bind(S,N,...)</a>override prior calls with the same values of S and N.</td></tr><tr><td valign="top">H13530</td> <td valign="top">Bindings established by <a href="../c3ref/bind_blob.html">sqlite3_bind(S,...)</a>persist across calls to <a href="../c3ref/reset.html">sqlite3_reset(S)</a>.</td></tr><tr><td valign="top">H13533</td> <td valign="top">In calls to <a href="../c3ref/bind_blob.html">sqlite3_bind_blob(S,N,V,L,D)</a>,<a href="../c3ref/bind_blob.html">sqlite3_bind_text(S,N,V,L,D)</a>, or<a href="../c3ref/bind_blob.html">sqlite3_bind_text16(S,N,V,L,D)</a> SQLite binds the first Lbytes of the BLOB or string pointed to by V, when Lis non-negative.</td></tr><tr><td valign="top">H13536</td> <td valign="top">In calls to <a href="../c3ref/bind_blob.html">sqlite3_bind_text(S,N,V,L,D)</a> or<a href="../c3ref/bind_blob.html">sqlite3_bind_text16(S,N,V,L,D)</a> SQLite binds charactersfrom V through the first zero character when L is negative.</td></tr><tr><td valign="top">H13539</td> <td valign="top">In calls to <a href="../c3ref/bind_blob.html">sqlite3_bind_blob(S,N,V,L,D)</a>,<a href="../c3ref/bind_blob.html">sqlite3_bind_text(S,N,V,L,D)</a>, or<a href="../c3ref/bind_blob.html">sqlite3_bind_text16(S,N,V,L,D)</a> when D is the specialconstant <a href="../c3ref/c_static.html">SQLITE_STATIC</a>, SQLite assumes that the value Vis held in static unmanaged space that will not changeduring the lifetime of the binding.</td></tr><tr><td valign="top">H13542</td> <td valign="top">In calls to <a href="../c3ref/bind_blob.html">sqlite3_bind_blob(S,N,V,L,D)</a>,<a href="../c3ref/bind_blob.html">sqlite3_bind_text(S,N,V,L,D)</a>, or<a href="../c3ref/bind_blob.html">sqlite3_bind_text16(S,N,V,L,D)</a> when D is the specialconstant <a href="../c3ref/c_static.html">SQLITE_TRANSIENT</a>, the routine makes aprivate copy of the value V before it returns.</td></tr><tr><td valign="top">H13545</td> <td valign="top">In calls to <a href="../c3ref/bind_blob.html">sqlite3_bind_blob(S,N,V,L,D)</a>,<a href="../c3ref/bind_blob.html">sqlite3_bind_text(S,N,V,L,D)</a>, or<a href="../c3ref/bind_blob.html">sqlite3_bind_text16(S,N,V,L,D)</a> when D is a pointer toa function, SQLite invokes that function to destroy thevalue V after it has finished using the value V.</td></tr><tr><td valign="top">H13548</td> <td valign="top">In calls to <a href="../c3ref/bind_blob.html">sqlite3_bind_zeroblob(S,N,V,L)</a> the value boundis a BLOB of L bytes, or a zero-length BLOB if L is negative.</td></tr><tr><td valign="top">H13551</td> <td valign="top">In calls to <a href="../c3ref/bind_blob.html">sqlite3_bind_value(S,N,V)</a> the V argument maybe either a <a href="../c3ref/value.html">protected sqlite3_value</a> object or an<a href="../c3ref/value.html">unprotected sqlite3_value</a> object.</td></tr></table></p><p>See also lists of <a href="objlist.html">Objects</a>, <a href="constlist.html">Constants</a>, and <a href="funclist.html">Functions</a>.</p><hr><small><i>This page last modified 2008/12/09 18:44:04 UTC</i></small></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -