First 5 minutes of SQLite

Source: Internet
Author: User
Tags sql error

What is SQLite?


SQLite is Light-weight RDBMS, it's use the file system rather than the C/S client, it's written by C and was widely used In the embedded system, for instance, the IOS system.

How do I use the database?

Since the database was written in C, it had some useful interface for C + +, the user interface is. Basically we need to understand-useful objects, database_connection and prepared_statement they are just the pointer o f the C struct. The Database_connection object is Sqlite3, and the Prepared_statement object sqlite3_stmt.
You can control the 2 basic objects by varies routines provided by SQLite below:
Sqlite3_open ()
Sqlite3_prepare ()
Sqlite3_step ()
Sqlite3_column ()
Sqlite3_finalize ()
sqlite3_close ()


How to run the SQL statement?
Create APrepared statementUsingSqlite3_prepare ().
Evaluate thePrepared statementby callingSqlite3_step ()One or more times.
For queries, extract results by callingSqlite3_column ()In between-calls toSqlite3_step ().
Destroy thePrepared statementUsingSqlite3_finalize ().
Or you can use one wrapper routine instead, sqlite_exec, here's the detail of this routine:

int Sqlite3_exec (
sqlite3*,/* An open database */
const char *SQL,/* SQL to be evaluated */
int (*callback) (void*,int,char**,char**), /* callback function */ 
Span style= "font:13px Osaka;" >void *,                                    /* 1st argument to callback */ 
char **errmsg                               /* Error msg written here */);
for instance, you can run statement like this:

 char  *ERRMSG;  const  char  *createsql =  " create TABLE IF not EXISTS people   "    " ;  int  result = sqlite3_exec (database, createsql, NULL, NULL, &ERRMSG); 




 

    #defineSQLITE_OK 0/* Successful result *//*Beginning-of-error-codes*/    #defineSqlite_error 1/* SQL ERROR or missing database */#defineSqlite_internal 2/* INTERNAL logic Error in SQLite */#defineSqlite_perm 3/* Access Permission denied */#defineSqlite_abort 4/* Callback routine requested an ABORT */#defineSqlite_busy 5/* The database file is locked */#defineSqlite_locked 6/* A table in the database is LOCKED */#defineSqlite_nomem 7/* A malloc () failed */#defineSqlite_readonly 8/* Attempt to write a READONLY database */#defineSqlite_interrupt 9/* Operation terminated by Sqlite3_interrupt () */#defineSqlite_ioerr/* Some kind of disk I/O error occurred */#defineSqlite_corrupt/* The database disk image is malformed */#defineSqlite_notfound/* Unknown opcode in Sqlite3_file_control () */#defineSqlite_full/* Insertion failed because database is full */#defineSqlite_cantopen/* Unable to open the database file */#defineSqlite_protocol/* Database lock PROTOCOL Error */#defineSqlite_empty/* Database is EMPTY */#defineSqlite_schema/* The database SCHEMA changed */#defineSqlite_toobig/* String or BLOB exceeds size limit */#defineSqlite_constraint/* Abort due to CONSTRAINT violation */#defineSqlite_mismatch/* Data Type Mismatch */#defineSqlite_misuse/* Library used incorrectly */#defineSqlite_nolfs/* Uses OS features not supported on Host */#defineSqlite_auth/* Authorization denied */#defineSqlite_format/* Auxiliary Database FORMAT Error */#defineSqlite_range/* 2nd parameter to sqlite3_bind out of RANGE */#defineSQLITE_NOTADB-*/File opened-a database file */#defineSqlite_notice/* Notifications from Sqlite3_log () */#definesqlite_warning/* Warnings from Sqlite3_log () */#defineSqlite_row/* Sqlite3_step () has another ROW ready */#defineSqlite_done 101/* SQLITE3_STEP () has finished executing *//*End-of-error-codes*/



if your statement is run successfully, you'll get the SQLITE_OK return code, otherwise, you'll get more information o f the error in the errmsg.  

First 5 minutes of SQLite

Related Article

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.