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

📄 capi3ref.tcl

📁 嵌入式数据库,在嵌入式平台上实现数据库功能,没有数据引擎,符合sql92标准
💻 TCL
📖 第 1 页 / 共 5 页
字号:
api {} {void *sqlite3_malloc(int);void *sqlite3_realloc(void*, int);void sqlite3_free(void*);} { These routines provide access to the memory allocator used by SQLite. Depending on how SQLite has been compiled and the OS-layer backend, the memory allocator used by SQLite might be the standard system malloc()/realloc()/free(), or it might be something different.  With certain compile-time flags, SQLite will add wrapper logic around the memory allocator to add memory leak and buffer overrun detection.  The OS layer might substitute a completely different memory allocator. Use these APIs to be sure you are always using the correct memory allocator.  The sqlite3_free() API, not the standard free() from the system library, should always be used to free the memory buffer returned by sqlite3_mprintf() or sqlite3_vmprintf() and to free the error message string returned by sqlite3_exec().  Using free() instead of sqlite3_free() might accidentally work on some systems and build configurations but  will fail on others. Compatibility Note:  Prior to version 3.4.0, the sqlite3_free API was prototyped to take a <tt>char*</tt> parameter rather than  <tt>void*</tt>.  Like this:<blockquote><pre>void sqlite3_free(char*);</pre></blockquote> The change to using <tt>void*</tt> might cause warnings when  compiling older code against newer libraries, but everything should still work correctly.}api {} {int sqlite3_get_table(  sqlite3*,              /* An open database */  const char *sql,       /* SQL to be executed */  char ***resultp,       /* Result written to a char *[]  that this points to */  int *nrow,             /* Number of result rows written here */  int *ncolumn,          /* Number of result columns written here */  char **errmsg          /* Error msg written here */);void sqlite3_free_table(char **result);} { This next routine is really just a wrapper around sqlite3_exec(). Instead of invoking a user-supplied callback for each row of the result, this routine remembers each row of the result in memory obtained from malloc(), then returns all of the result after the query has finished.  As an example, suppose the query result where this table: <pre>        Name        | Age        -----------------------        Alice       | 43        Bob         | 28        Cindy       | 21 </pre> If the 3rd argument were &azResult then after the function returns azResult will contain the following data: <pre>        azResult[0] = "Name";        azResult[1] = "Age";        azResult[2] = "Alice";        azResult[3] = "43";        azResult[4] = "Bob";        azResult[5] = "28";        azResult[6] = "Cindy";        azResult[7] = "21"; </pre> Notice that there is an extra row of data containing the column headers.  But the *nrow return value is still 3.  *ncolumn is set to 2.  In general, the number of values inserted into azResult will be ((*nrow) + 1)*(*ncolumn). After the calling function has finished using the result, it should  pass the result data pointer to sqlite3_free_table() in order to  release the memory that was malloc-ed.  Because of the way the  malloc() happens, the calling function must not try to call  malloc() directly.  Only sqlite3_free_table() is able to release  the memory properly and safely. The return value of this routine is the same as from sqlite3_exec().}api {sqlite3_interrupt} { void sqlite3_interrupt(sqlite3*);} { This function causes any pending database operation to abort and return at its earliest opportunity.  This routine is typically called in response to a user action such as pressing "Cancel" or Ctrl-C where the user wants a long query operation to halt immediately.} {}api {} {long long int sqlite3_last_insert_rowid(sqlite3*);} { Each entry in an SQLite table has a unique integer key called the "rowid". The rowid is always available as an undeclared column named ROWID, OID, or _ROWID_. If the table has a column of type INTEGER PRIMARY KEY then that column is another an alias for the rowid. This routine returns the rowid of the most recent INSERT into the database from the database connection given in the first argument.  If no inserts have ever occurred on this database connection, zero is returned. If an INSERT occurs within a trigger, then the rowid of the inserted row is returned by this routine as long as the trigger is running.  But once the trigger terminates, the value returned by this routine reverts to the last value inserted before the trigger fired.} {}api {} {char *sqlite3_mprintf(const char*,...);char *sqlite3_vmprintf(const char*, va_list);} { These routines are variants of the "sprintf()" from the standard C library.  The resulting string is written into memory obtained from malloc() so that there is never a possibility of buffer overflow.  These routines also implement some additional formatting options that are useful for constructing SQL statements. The strings returned by these routines should be freed by calling sqlite3_free(). All of the usual printf formatting options apply.  In addition, there is a "%q" option.  %q works like %s in that it substitutes a null-terminated string from the argument list.  But %q also doubles every '\\'' character. %q is designed for use inside a string literal.  By doubling each '\\'' character it escapes that character and allows it to be inserted into the string. For example, so some string variable contains text as follows: <blockquote><pre>  char *zText = "It's a happy day!"; </pre></blockquote> One can use this text in an SQL statement as follows: <blockquote><pre>  sqlite3_exec_printf(db, "INSERT INTO table VALUES('%q')",       callback1, 0, 0, zText);  </pre></blockquote> Because the %q format string is used, the '\\'' character in zText is escaped and the SQL generated is as follows: <blockquote><pre>  INSERT INTO table1 VALUES('It''s a happy day!') </pre></blockquote> This is correct.  Had we used %s instead of %q, the generated SQL would have looked like this:  <blockquote><pre>  INSERT INTO table1 VALUES('It's a happy day!');  </pre></blockquote> This second example is an SQL syntax error.  As a general rule you should always use %q instead of %s when inserting text into a string  literal.} {}api {} {int sqlite3_open(  const char *filename,   /* Database filename (UTF-8) */  sqlite3 **ppDb          /* OUT: SQLite db handle */);int sqlite3_open16(  const void *filename,   /* Database filename (UTF-16) */  sqlite3 **ppDb          /* OUT: SQLite db handle */);} { Open the sqlite database file "filename".  The "filename" is UTF-8 encoded for sqlite3_open() and UTF-16 encoded in the native byte order for sqlite3_open16().  An sqlite3* handle is returned in *ppDb, even if an error occurs. If the database is opened (or created) successfully, then SQLITE_OK is returned. Otherwise an error code is returned. The sqlite3_errmsg() or sqlite3_errmsg16()  routines can be used to obtain an English language description of the error. If the database file does not exist, then a new database will be created as needed. The encoding for the database will be UTF-8 if sqlite3_open() is called and UTF-16 if sqlite3_open16 is used. Whether or not an error occurs when it is opened, resources associated with the sqlite3* handle should be released by passing it to sqlite3_close() when it is no longer required. The returned sqlite3* can only be used in the same thread in which it was created.  It is an error to call sqlite3_open() in one thread then pass the resulting database handle off to another thread to use.  This restriction is due to goofy design decisions (bugs?) in the way some threading implementations interact with file locks. Note to windows users:  The encoding used for the filename argument of sqlite3_open() must be UTF-8, not whatever codepage is currently defined.  Filenames containing international characters must be converted to UTF-8 prior to passing them into sqlite3_open().}api {} {int sqlite3_prepare(  sqlite3 *db,            /* Database handle */  const char *zSql,       /* SQL statement, UTF-8 encoded */  int nBytes,             /* Length of zSql in bytes. */  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */  const char **pzTail     /* OUT: Pointer to unused portion of zSql */);int sqlite3_prepare16(  sqlite3 *db,            /* Database handle */  const void *zSql,       /* SQL statement, UTF-16 encoded */  int nBytes,             /* Length of zSql in bytes. */  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */  const void **pzTail     /* OUT: Pointer to unused portion of zSql */);} { To execute an SQL query, it must first be compiled into a byte-code program using one of the following routines. The only difference between them is that the second argument, specifying the SQL statement to compile, is assumed to be encoded in UTF-8 for the sqlite3_prepare() function and UTF-16 for sqlite3_prepare16(). The first argument "db" is an SQLite database handle. The second argument "zSql" is the statement to be compiled, encoded as either UTF-8 or UTF-16 (see above). If the next argument, "nBytes", is less than zero, then zSql is read up to the first nul terminator.  If "nBytes" is not less than zero, then it is the length of the string zSql in bytes (not characters). *pzTail is made to point to the first byte past the end of the first SQL statement in zSql.  This routine only compiles the first statement in zSql, so *pzTail is left pointing to what remains uncompiled. *ppStmt is left pointing to a compiled SQL statement that can be executed using sqlite3_step().  Or if there is an error, *ppStmt may be set to NULL.  If the input text contained no SQL (if the input is and empty string or a comment) then *ppStmt is set to NULL.  The calling procedure is responsible for deleting this compiled SQL statement using sqlite3_finalize() after it has finished with it. On success, SQLITE_OK is returned.  Otherwise an error code is returned.}api {} {void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);} { <i>Experimental</i> This routine configures a callback function - the progress callback - that is invoked periodically during long running calls to sqlite3_exec(), sqlite3_step() and sqlite3_get_table(). An example use for this API is to keep a GUI updated during a large query. The progress callback is invoked once for every N virtual machine opcodes, where N is the second argument to this function. The progress callback itself is identified by the third argument to this function. The fourth argument to this function is a void pointer passed to the progress callback function each time it is invoked. If a call to sqlite3_exec(), sqlite3_step() or sqlite3_get_table() results  in less than N opcodes being executed, then the progress callback is not invoked.  To remove the progress callback altogether, pass NULL as the third argument to this function. If the progress callback returns a result other than 0, then the current  query is immediately terminated and any database changes rolled back. If the query was part of a larger transaction, then the transaction is not rolled back and remains active. The sqlite3_exec() call returns SQLITE_ABORT. }api {} {int sqlite3_reset(sqlite3_stmt *pStmt);} { The sqlite3_reset() function is called to reset a prepared SQL statement obtained by a previous call to sqlite3_prepare() or sqlite3_prepare16() back to it's initial state, ready to be re-executed. Any SQL statement variables that had values bound to them using the sqlite3_bind_*() API retain their values.}api {} {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*);

⌨️ 快捷键说明

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