sqlite__初识

前端之家收集整理的这篇文章主要介绍了sqlite__初识前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

sqlite ----命令行管理

----C/C++接口


命令行管理:

create table mytb1(列名1 列内容类型;列名2 列内容类型);

root@vm-ubuntu:~# sqlite3 test.db 
sqlite version 3.8.2 2013-12-06 14:53:30
Enter ".help" for instructions
Enter sql statements terminated with a ";"
sqlite> create table tbl1(one varchar(10),two smallint);
sqlite> insert into tbl1 values('hello',10);
sqlite> insert into tbl1 values('goodbye',20);
sqlite> select * from tbl1;
hello|10
goodbye|10
goodbye|20

C/C++接口

sqlite3_open()

This routine opens a connection to an sqlite database file and returns a database connection object. This is often the first sqlite API call that an application makes and is a prerequisite for most other sqlite APIs. Many sqlite interfaces require a pointer to the database connection object as their first parameter and can be thought of as methods on the database connection object. This routine is the constructor for the database connection object.

sqlite3_prepare( )

This routine converts sql text into a prepared statement object and returns a pointer to that object. This interface requires a database connection pointer created by a prior call to sqlite3_open() and a text string containing the sql statement to be prepared. This API does not actually evaluate the sql statement. It merely prepares the sql statement for evaluation.

Think of each sql statement as a small computer program. The purpose of sqlite3_prepare() is to compile that program into object code. The prepared statement is the object code. The sqlite3_step() interface then runs the object code to get a result
Note that the use of sqlite3_prepare() is not recommended for new applications. A newer alternative routine sqlite3_prepare_v2() should be used instead.

sqlite3_step()

This routine is used to evaluate a prepared statement that has been prevIoUsly created by the sqlite3_prepare() interface. The statement is evaluated up to the point where the first row of results are available. To advance to the second row of results,invoke sqlite3_step() again. Continue invoking sqlite3_step() until the statement is complete. Statements that do not return results (ex: INSERT,UPDATE,or DELETE statements) run to completion on a single call to sqlite3_step().

sqlite3_column()

This routine returns a single column from the current row of a result set for a prepared statement that is being evaluated by sqlite3_step(). Each time sqlite3_step() stops with a new result set row,this routine can be called multiple times to find the values of all columns in that row. As noted above,there really is no such thing as a "sqlite3_column()" function in the sqlite API. Instead,what we here call "sqlite3_column()" is a place-holder for an entire family of functions that return a value from the result set in varIoUs data types. There are also routines in this family that return the size of the result (if it is a string or BLOB) and the number of columns in the result set.

sqlite3_column_blob()
sqlite3_column_bytes()
sqlite3_column_bytes16()
sqlite3_column_count()
sqlite3_column_double()
sqlite3_column_int()
sqlite3_column_int64()
sqlite3_column_text()
sqlite3_column_text16()
sqlite3_column_type()
sqlite3_column_value()

sqlite3_finalize()

This routine destroys a prepared statement created by a prior call to sqlite3_prepare(). Every prepared statement must be destroyed using a call to this routine in order to avoid memory leaks.

sqlite3_close()

This routine closes a database connection prevIoUsly opened by a call to sqlite3_open(). All prepared statements associated with the connection should be finalized prior to closing the connection.

原文链接:https://www.f2er.com/sqlite/200025.html

猜你在找的Sqlite相关文章