A detailed introduction to the common syntax of SQLite

Source: Internet
Author: User
Tags sqlite stmt

1, the SQL statement precompilation: The statement to the data stream, the execution of the statement before the syntax of the check statement, but do not know whether the statement can detect the results. This method has a return value

Precompiled succeeds returns SQLITE_OK----0 otherwise sqlite_error----1
int Sqlite3_prepare_v2 (
Sqlite3 *db,//Pointer to database
const Char *zsql,//SQL statement
int Nbyte, the length of the//sql statement (typically-1, the system can automatically calculate the length of the string)
Sqlite3_stmt **ppstmt,//Pointer to statement
const char **pztail//sql is not used in the part that is generally empty
); 2. Value bindings for SQL statements
* All such methods have a return value precompiled successfully returns SQLITE_OK----0 otherwise returns SQLITE_ERROR----1
Binding to an integer value
int Sqlite3_bind_int (
sqlite3_stmt*,//Pointer to statement
ordinal of int,//placeholder (starting from 1 and so on)
int//Bound value
);
Binding to a String value
int Sqlite3_bind_text (
sqlite3_stmt*,//Pointer to statement
ordinal of int,//placeholder (starting from 1 and so on)
Const char*,//The value to bind (here to the C type of string (CString), generally we use OC string (nsstring*) to pass-(__strong const char *) utf8string to turn it can be In the)
int n,//length of the string (typically-1, the system can automatically calculate the length of the string)
void (*) (void*)//callback function (the blogger is useless here, so I don't know how to update slowly)
);
The binding of binary data values is generally used for image access
int Sqlite3_bind_blob (
sqlite3_stmt*,//Pointer to statement
ordinal of int,//placeholder (starting from 1 and so on)
Const void*,//The value to bind (here is the C type of bit (Byte), generally we are using OC NSData (nsdata*) to pass-(const void *) bytes to turn on it)
int n,//length of data (with-(nsuinteger) length Get here why not-1? Because 1 is the length of the string, the other is not necessarily accurate, so here we manually calculate the length of the data)
void (*) (void*)//callback function (the blogger is useless here, so I don't know how to update slowly)
); 3, the SQL statement value (from the database for each column value)
The value of an integer number field
int Sqlite3_column_int (
sqlite3_stmt*,//Pointer to statement
int Icol//number of columns in the table in the database (starting from 0 and so on)
);
Value of the String field
* Note here we get an unsigned C string we're going to first convert the signed C string to the OC string
Example sname to OC string
NSString *sname=[nsstring stringwithutf8string: (const char *) Sqlite3_column_text (stmt, 1)];

Const unsigned char *sqlite3_column_text (
sqlite3_stmt*,//Pointer to statement
int Icol//number of columns in the table in the database (starting from 0 and so on)
);
Values for binary fields
* Note Here we get is C binary we want to convert to OC binary (we want to convert byte (c) to NSData (OC) via + (ID) datawithbytes: (const void *) bytes length: (Nsuinteger) Length, because this requires data lengths so you need to call int sqlite3_column_bytes (sqlite3_stmt*, int icol); Get the length of the data)
Cases
int length=sqlite3_column_bytes (stmt,3);//Gets the length of the binary data
NSData *img=[nsdata Datawithbytes:sqlite3_column_blob (stmt, 3) length:length]; Converting binary data to bits NSData object

const void *sqlite3_column_blob (
sqlite3_stmt*,//Pointer to statement
int Icol//number of columns in the table in the database (starting from 0 and so on)
);

A detailed introduction to the common syntax 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.