⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 capi3.html

📁 这是sqlite3.56的文档。拿来给大家阅读使用
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>C/C++ Interface For SQLite Version 3</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>  <h2>C/C++ Interface For SQLite Version 3</h2><h3>1.0 Overview</h3><p>SQLite version 3.0 is a new version of SQLite, derived fromthe SQLite 2.8.13 code base, but with an incompatible file formatand API.SQLite version 3.0 was created to answer demand for the following features:</p><ul><li>Support for UTF-16.</li><li>User-definable text collating sequences.</li><li>The ability to store BLOBs in indexed columns.</li></ul><p>It was necessary to move to version 3.0 to implement these features becauseeach requires incompatible changes to the database file format.  Otherincompatible changes, such as a cleanup of the API, were introduced at thesame time under the theory that it is best to get your incompatible changesout of the way all at once.  </p><p>The API for version 3.0 is similar to the version 2.X API,but with some important changes.  Most noticeably, the "<tt>sqlite_</tt>"prefix that occurs on the beginning of all API functions and datastructures are changed to "<tt>sqlite3_</tt>".  This avoids confusion between the two APIs and allows linking against bothSQLite 2.X and SQLite 3.0 at the same time.</p><p>There is no agreement on what the C datatype for a UTF-16string should be.  Therefore, SQLite uses a generic type of void*to refer to UTF-16 strings.  Client software can cast the void* to whatever datatype is appropriate for their system.</p><h3>2.0 C/C++ Interface</h3><p>The API for SQLite 3.0 includes 83 separate functions in additionto several data structures and #defines.  (A complete<a href="c3ref/intro.html">API reference</a> is provided as a separate document.)Fortunately, the interface is not nearly as complex as its size implies.Simple programs can still make do with only 3 functions:<a href="c3ref/open.html">sqlite3_open()</a>, <a href="c3ref/exec.html">sqlite3_exec()</a>, and <a href="c3ref/close.html">sqlite3_close()</a>.More control over the execution of the database engine is providedusing <a href="c3ref/prepare.html">sqlite3_prepare_v2()</a>to compile an SQLite statement into byte code and<a href="c3ref/step.html">sqlite3_step()</a> to execute that bytecode.A family of routines with names beginning with <a href="c3ref/column_blob.html">sqlite3_column_</a>is used to extract information about the result set of a query.Many interface functions come in pairs, with both a UTF-8 andUTF-16 version.  And there is a collection of routinesused to implement user-defined SQL functions and user-definedtext collating sequences.</p><h4>2.1 Opening and closing a database</h4><blockquote><pre>   typedef struct sqlite3 sqlite3;   int sqlite3_open(const char*, sqlite3**);   int sqlite3_open16(const void*, sqlite3**);   int sqlite3_close(sqlite3*);   const char *sqlite3_errmsg(sqlite3*);   const void *sqlite3_errmsg16(sqlite3*);   int sqlite3_errcode(sqlite3*);</pre></blockquote><p>The sqlite3_open() routine returns an integer error code rather thana pointer to the sqlite3 structure as the version 2 interface did.The difference between sqlite3_open()and sqlite3_open16() is that sqlite3_open16() takes UTF-16 (in host nativebyte order) for the name of the database file.  If a new database fileneeds to be created, then sqlite3_open16() sets the internal textrepresentation to UTF-16 whereas sqlite3_open() sets the textrepresentation to UTF-8.</p><p>The opening and/or creating of the database file is deferred until thefile is actually needed.  This allows options and parameters, suchas the native text representation and default page size, to beset using PRAGMA statements.</p><p>The sqlite3_errcode() routine returns a result code for the mostrecent major API call.  sqlite3_errmsg() returns an English-languagetext error message for the most recent error.  The error message isrepresented in UTF-8 and will be ephemeral - it could disappear onthe next call to any SQLite API function.  sqlite3_errmsg16() works likesqlite3_errmsg() except that it returns the error message representedas UTF-16 in host native byte order.</p><p>The error codes for SQLite version 3 are unchanged from version 2.They are as follows:</p><blockquote><pre>#define SQLITE_OK           0   /* Successful result */#define SQLITE_ERROR        1   /* SQL error or missing database */#define SQLITE_INTERNAL     2   /* An 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 sqlite_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   /* (Internal Only) Table or record not found */#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   /* (Internal Only) Database table is empty */#define SQLITE_SCHEMA      17   /* The database schema changed */#define SQLITE_TOOBIG      18   /* Too much data for one row of a table */#define SQLITE_CONSTRAINT  19   /* Abort due to contraint 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_ROW         100  /* sqlite_step() has another row ready */#define SQLITE_DONE        101  /* sqlite_step() has finished executing */</pre></blockquote><h4>2.2 Executing SQL statements</h4><blockquote><pre>   typedef int (*sqlite_callback)(void*,int,char**, char**);   int sqlite3_exec(sqlite3*, const char *sql, sqlite_callback, void*, char**);</pre></blockquote><p>The <a href="c3ref/exec.html">sqlite3_exec()</a> function works much as it did in SQLite version 2.Zero or more SQL statements specified in the second parameter are compiledand executed.  Query results are returned to a callback routine.</p><p>In SQLite version 3, the sqlite3_exec routine is just a wrapper aroundcalls to the prepared statement interface.</p><blockquote><pre>   typedef struct sqlite3_stmt sqlite3_stmt;   int sqlite3_prepare(sqlite3*, const char*, int, sqlite3_stmt**, const char**);   int sqlite3_prepare16(sqlite3*, const void*, int, sqlite3_stmt**, const void**);   int sqlite3_finalize(sqlite3_stmt*);   int sqlite3_reset(sqlite3_stmt*);</pre></blockquote><p>The sqlite3_prepare interface compiles a single SQL statement into byte codefor later execution.  This interface is now the preferred way of accessingthe database.</p><p>The SQL statement is a UTF-8 string for sqlite3_prepare().The sqlite3_prepare16() works the same way exceptthat it expects a UTF-16 string as SQL input.Only the first SQL statement in the input string is compiled.The fourth parameter is filled in with a pointer to the next (uncompiled)SQLite statement in the input string, if any.The sqlite3_finalize() routine deallocates a prepared SQL statement.All prepared statements must be finalized before the database can beclosed.The sqlite3_reset() routine resets a prepared SQL statement so that itcan be executed again.</p><p>The SQL statement may contain tokens of the form "?" or "?nnn" or ":aaa"where "nnn" is an integer and "aaa" is an identifier.Such tokens represent unspecified literal values (or "wildcards")to be filled in later by the <a href="c3ref/bind_blob.html">sqlite3_bind</a> interface.Each wildcard has an associated number which is its sequence in thestatement or the "nnn" in the case of a "?nnn" form. It is allowed for the same wildcardto occur more than once in the same SQL statement, in which caseall instance of that wildcard will be filled in with the same value.Unbound wildcards have a value of NULL.</p><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, long long int);   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 n, void(*)(void*));   int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);</pre></blockquote><p>There is an assortment of sqlite3_bind routines used to assign valuesto wildcards in a prepared SQL statement.  Unbound wildcardsare interpreted as NULLs.  Bindings are not reset by sqlite3_reset().But wildcards can be rebound to new values after an sqlite3_reset().

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -