Common sqlite3 Interfaces

Source: Internet
Author: User
Tags sqlite db time in milliseconds

 

Int sqlite3_open (
Const char * filename,/* database filename (UTF-8 )*/
Sqlite3 ** ppdb/* Out: SQLite dB handle */
);
Function: Open the database. If the database does not exist, it is automatically created.
Param1 (in): database file name, UTF-8 format
Param2 (out): The Returned Database handle.
Return Value: sqlite_ OK is returned. Otherwise, it fails (the database handle ppdb is empty). For the failure value, see the specific SQLite _ * definition.
========================================================== ========================================================== =====

Int sqlite3_close (sqlite3 *);
Function: Disable the database.
Param1 (in): opened database handle
Return Value: sqlite_ OK is returned. Otherwise, it fails.
========================================================== ========================================================== =====

Int sqlite3_exec (
Sqlite3 *,/* an open database */
Const char * SQL,/* SQL to be executed */
Sqlite3_callback,/* callback function */
Void *,/* 1st argument to callback function */
Char ** errmsg/* error MSG written here */
);
Function: run SQL
Param1 (in): Database handle
Param2 (in): SQL statement ending with \ 0.
Param3 (in): callback function
Param4 (in): callback Parameter
Param5 (out): output error message
Return Value: sqlite_ OK; otherwise, it fails. For the error message after failure, see param5;
Note: Multiple SQL statements are separated by semicolons (;). Callback functions and callback parameters are usually used in query statements,
The callback function is called once for each query result.
Callback Function Format:
Typedef int (* sqlite3_callback) (void *, Int, char **, char **);
Parameter 1: parameters passed in sqlite3_exec
Parameter 2: Total number of columns.
Parameter 3: column data (char *)
Parameter 4: column name (char *)

========================================================== ========================================================== =====
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 */
Int * nrow,/* Number of result rows written here */
Int * ncolumn,/* Number of result columns written here */
Char ** errmsg/* error MSG written here */
);
Function: query a table.
Param1 (in): Database handle
Param2 (in): SQL statement ending with \ 0.
Param3 (out): Query Result
Param4 (out): number of returned rows (How many rows of data)
Param5 (out): number of returned columns (number of fields)
Param6 (out): error message returned
Returned value: sqlite_ OK. If the House fails, see the error message.

========================================================== ========================================================== =====
Void sqlite3_free_table (char ** result );
Function: releases the result data saved through sqlite3_get_table query.
Param1 (in): Data Pointer to be released

========================================================== ========================================================== =====
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 */
);
Function: Construct a query.
Param1 (in): Database handle
Param2 (in): SQL statement
Param3 (in): SQL statement length. If it is set to-1, the length of the SQL statement is automatically calculated by string.
Param4 (out): saved query struct,
Param5 (out): NULL
Returned value: sqlite_ OK.

========================================================== ========================================================== =====
Int sqlite3_bind_blob (sqlite3_stmt *, Int, const void *, int N, void (*) (void *));
Function: bind data to the query struct.
Param1 (in): Query struct
Param2 (in): bind the nth data (question mark (?) in the SQL statement (?))
Param3 (in): binary data pointer
Param4 (in): binary data length
Param5 (in): destructor callback function. It is usually set to null and is released after completion.
Returned value: s_ OK.
Note: The binding function must be called before sqlite3_step and after sqlite3_prepare or sqlite3_reset.
Unbound parameters are null by default. Similar binding functions include the following:
Int sqlite3_bind_double (sqlite3_stmt *, Int, double );
Int sqlite3_bind_int (sqlite3_stmt *, Int, INT );
Int sqlite3_bind_int64 (sqlite3_stmt *, Int, sqlite_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_reset (sqlite3_stmt * pstmt );
Function: reset all bound values and return to the status after sqlite3_prepare is called.

========================================================== ========================================================== =====
Int sqlite3_step (sqlite3_stmt *);
Function: Query
Param1: Query struct
Return Value:
Sqlite_busy: the database is locked. You can call this function again after it is released.
Sqlite_done: Successful
Sqlite_row: If the query succeeds and data is returned, this value is returned for each query,
You can call the sqlite3_column _ * function to obtain data and then call it again to process the next data.
Sqlite_error: Failed
Sqlite_misuse: indicates an incorrect call. For example, if you have returned sqlite_done or sqlite_error, you can continue to call this function.

========================================================== ========================================================== =====
Int sqlite3_finalize (sqlite3_stmt * pstmt );
Function: Release the query struct.

========================================================== ========================================================== =====
Int sqlite3_key (
Sqlite3 * dB,/* database to be rekeyed */
Const void * pkey, int nkey/* The key */
);
Function: specify a password for the encrypted database. The function is called after sqlite3_open.

========================================================== ========================================================== =====
Int sqlite3_rekey (
Sqlite3 * dB,/* database to be rekeyed */
Const void * pkey, int nkey/* the new key */
);
Function: reset the database password. If pkey = 0 or nkey = 0, the database is not encrypted.

========================================================== ========================================================== =====

 

Const char * sqlite3_libversion (void );
Int sqlite3_libversion_number (void );
Function: gets the version number.

Sqlite_int64 sqlite3_last_insert_rowid (sqlite3 *);
Function: gets the last inserted row ID.

Int sqlite3_changes (sqlite3 *);
Function: gets the number of rows affected by the latest execution of sqlite3_exec.

Int sqlite3_total_changes (sqlite3 *);
Function: gets the function that has been changed since the database is opened.

Void sqlite3_interrupt (sqlite3 *);
Function: interrupts or stops the current database operation.

Int sqlite3_complete (const char * SQL );
Function: determines whether a statement ends with a semicolon (;).

Int sqlite3_busy_handler (sqlite3 *, INT (*) (void *, INT), void *);
Function: sets the callback processing when the query is busy.
Note: The default callback function is empty. If the callback function is empty, sqlite3_exec () will be returned directly for execution after the table is locked.

Int sqlite3_busy_timeout (sqlite3 *, int MS );
Function: sets the query timeout time in milliseconds)

 

Char * sqlite3_mprintf (const char *,...);
Char * sqlite3_vmprintf (const char *, va_list );
Char * sqlite3_snprintf (INT, char *, const char *,...);
Function: format characters. % Q must be used instead of % S. (The semicolon is not escaped)

Void * sqlite3_malloc (INT );
Void * sqlite3_realloc (void *, INT );
Void sqlite3_free (void *);
Function: Memory Function

Int sqlite3_set_authorizer (
Sqlite3 *,
INT (* XAUTH) (void *, Int, const char *, const char *),
Void * puserdata
);
Function: sets database authorization.

Void * sqlite3_trace (sqlite3 *, void (* xtrace) (void *, const char *), void *);
Void * sqlite3_profile (sqlite3 *,
Void (* xprofile) (void *, const char *, sqlite_uint64), void *);

Void sqlite3_progress_handler (sqlite3 *, Int, INT (*) (void *), void *);
Function: sets the callback function to be called when sqlite3_exec (), sqlite3_step (), and sqlite3_get_table () are executed.

Void * sqlite3_commit_hook (sqlite3 *, INT (*) (void *), void *);
Function: sets the transaction callback function.

Int sqlite3_errcode (sqlite3 * dB );
Const char * sqlite3_errmsg (sqlite3 *);
Function: Get error codes and error messages

Int sqlite3_bind_parameter_count (sqlite3_stmt *);
Function: return the number of parameters to be bound (question mark in SQL statements? Quantity)

Const char * sqlite3_bind_parameter_name (sqlite3_stmt *, INT );
Function: get the name of the binding parameter ,? The return value is null.

Int sqlite3_bind_parameter_index (sqlite3_stmt *, const char * zname );
Function: Obtain the bound parameter index.

Int sqlite3_clear_bindings (sqlite3_stmt *);
Function: clears bound parameters.

Int sqlite3_column_count (sqlite3_stmt * pstmt );
Function: gets the number of columns.
Const char * sqlite3_column_name (sqlite3_stmt *, INT );
Function: obtains the column name.

Const char * sqlite3_column_database_name (sqlite3_stmt *, INT );
Const void * sqlite3_column_database_name16 (sqlite3_stmt *, INT );
Const char * sqlite3_column_table_name (sqlite3_stmt *, INT );
Const void * sqlite3_column_table_name16 (sqlite3_stmt *, INT );
Const char * sqlite3_column_origin_name (sqlite3_stmt *, INT );
Const void * sqlite3_column_origin_name16 (sqlite3_stmt *, INT );
Function: returns the column information?

Const char * sqlite3_column_decltype (sqlite3_stmt *, int I );
Function: returns the column data type.

Int sqlite3_data_count (sqlite3_stmt * pstmt );
Function: number of returned data rows)

 

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 );
Double sqlite3_column_double (sqlite3_stmt *, int icol );
Int sqlite3_column_int (sqlite3_stmt *, int icol );
Sqlite_int64 sqlite3_column_int64 (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 );
Int sqlite3_column_numeric_type (sqlite3_stmt *, int icol );
Sqlite3_value * sqlite3_column_value (sqlite3_stmt *, int icol );
Function: obtains column data.

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 *)
);
Function:

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 *);
Sqlite_int64 sqlite3_value_int64 (sqlite3_value *);
Const unsigned char * sqlite3_value_text (sqlite3_value *);
Const void * sqlite3_value_text16 (sqlite3_value *);
Const void * sqlite3_value_text16le (sqlite3_value *);
Const void * sqlite3_value_text16be (sqlite3_value *);
Int sqlite3_value_type (sqlite3_value *);
Int sqlite3_value_numeric_type (sqlite3_value *);
Function: functions similar to sqlite3_column _ *

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.