C 扩展库 - sqlite3 API
sqlite3 API
Summary
sqlite3
- The database connection object. Created by sqlite3_open() and destroyed by sqlite3_close().
- Each open SQLite database is represented by a pointer to an instance of the opaque structure named "sqlite3". It is useful to think of an sqlite3 pointer as an object.
typedef struct sqlite3 sqlite3;
sqlite3_stmt
- The prepared statement object. Created by sqlite3_prepare() and destroyed by sqlite3_finalize().
- An instance of this object represents a single SQL statement that has been compiled into binary form and is ready to be evaluated.
typedef struct sqlite3_stmt sqlite3_stmt;
The life-cycle of a prepared statement object usually goes like this:
- Create the prepared statement object using sqlite3_prepare_v2().
- Bind values to parameters using the sqlite3_bind_*() interfaces.
- Run the SQL by calling sqlite3_step() one or more times.
- Reset the prepared statement using sqlite3_reset() then go back to step 2. Do this zero or more times.
- Destroy the object using sqlite3_finalize().
sqlite3_open()
- Open a connection to a new or existing SQLite database. The constructor for sqlite3.
- These routines open an SQLite database file as specified by the filename argument.
- A database connection handle is usually returned in *ppDb, even if an error occurs. The only exception is that if SQLite is unable to allocate memory to hold the sqlite3 object, a NULL will be written into *ppDb instead of a pointer to the sqlite3 object. If the database is opened (and/or created) successfully, then SQLITE_OK is returned. Otherwise an error code is returned.
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 */
);
int sqlite3_open_v2(
const char *filename, /* Database filename (UTF-8) */
sqlite3 **ppDb, /* OUT: SQLite db handle */
int flags, /* Flags */
const char *zVfs /* Name of VFS module to use */
);
sqlite3_prepare()
- Compile SQL text into byte-code that will do the work of querying or updating the database. The constructor for sqlite3_stmt.
- To execute an SQL statement, it must first be compiled into a byte-code program using one of these routines. Or, in other words, these routines are constructors for the prepared statement object.
int sqlite3_prepare(
sqlite3 *db, /* Database handle */
const char *zSql, /* SQL statement, UTF-8 encoded */
int nByte, /* Maximum length of zSql in bytes. */
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
const char **pzTail /* OUT: Pointer to unused portion of zSql */
);
int sqlite3_prepare_v2(
sqlite3 *db, /* Database handle */
const char *zSql, /* SQL statement, UTF-8 encoded */
int nByte, /* Maximum length of zSql in bytes. */
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
const char **pzTail /* OUT: Pointer to unused portion of zSql */
);
int sqlite3_prepare_v3(
sqlite3 *db, /* Database handle */
const char *zSql, /* SQL statement, UTF-8 encoded */
int nByte, /* Maximum length of zSql in bytes. */
unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
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 nByte, /* Maximum length of zSql in bytes. */
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
const void **pzTail /* OUT: Pointer to unused portion of zSql */
);
int sqlite3_prepare16_v2(
sqlite3 *db, /* Database handle */
const void *zSql, /* SQL statement, UTF-16 encoded */
int nByte, /* Maximum length of zSql in bytes. */
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
const void **pzTail /* OUT: Pointer to unused portion of zSql */
);
int sqlite3_prepare16_v3(
sqlite3 *db, /* Database handle */
const void *zSql, /* SQL statement, UTF-16 encoded */
int nByte, /* Maximum length of zSql in bytes. */
unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
const void **pzTail /* OUT: Pointer to unused portion of zSql */
);
sqlite3_bind()
- Store application data into parameters of the original SQL.
int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,void(*)(void*));
int sqlite3_bind_double(sqlite3_stmt*, int, double);
int sqlite3_bind_int(sqlite3_stmt*, int, int);
int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
int sqlite3_bind_null(sqlite3_stmt*, int);
int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,void(*)(void*), unsigned char encoding);
int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*));
int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
sqlite3_step()
- Advance an sqlite3_stmt to the next result row or to completion.
int sqlite3_step(sqlite3_stmt*);
sqlite3_column()
- Column values in the current result row for an sqlite3_stmt.
const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
double sqlite3_column_double(sqlite3_stmt*, int iCol);
int sqlite3_column_int(sqlite3_stmt*, int iCol);
sqlite3_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);
sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
int sqlite3_column_type(sqlite3_stmt*, int iCol);
- sqlite3_column_blob → BLOB result
- sqlite3_column_double → REAL result
- sqlite3_column_int → 32-bit INTEGER result
- sqlite3_column_int64 → 64-bit INTEGER result
- sqlite3_column_text → UTF-8 TEXT result
- sqlite3_column_text16 → UTF-16 TEXT result
- sqlite3_column_value → The result as an unprotected sqlite3_value object.
- sqlite3_column_bytes → Size of a BLOB or a UTF-8 TEXT result in bytes
- sqlite3_column_bytes16 → Size of UTF-16 TEXT in bytes
- sqlite3_column_type → Default datatype of the result
sqlite3_finalize()
- Destructor for sqlite3_stmt.
int sqlite3_finalize(sqlite3_stmt *pStmt);
The sqlite3_finalize() function is called to delete a prepared statement. If the most recent evaluation of the statement encountered no errors or if the statement is never been evaluated, then sqlite3_finalize() returns SQLITE_OK.
sqlite3_close()
- Destructor for sqlite3.
int sqlite3_close(sqlite3*);
int sqlite3_close_v2(sqlite3*);
The sqlite3_close() and sqlite3_close_v2() routines are destructors for the sqlite3 object. Calls to sqlite3_close() and sqlite3_close_v2() return SQLITE_OK if the sqlite3 object is successfully destroyed and all associated resources are deallocated.
sqlite3_exec()
- A wrapper function that does sqlite3_prepare(), sqlite3_step(), sqlite3_column(), and sqlite3_finalize() for a string of one or more SQL statements.
int sqlite3_exec(
sqlite3*, /* An open database */
const char *sql, /* SQL to be evaluated */
int (*callback)(void*,int,char**,char**), /* Callback function */
void *, /* 1st argument to callback */
char **errmsg /* Error msg written here */
);
sqlite3_get_table()
- Convenience Routines For Running Queries
int sqlite3_get_table(
sqlite3 *db, /* An open database */
const char *zSql, /* SQL to be evaluated */
char ***pazResult, /* Results of the query */
int *pnRow, /* Number of result rows written here */
int *pnColumn, /* Number of result columns written here */
char **pzErrmsg /* Error msg written here */
);
void sqlite3_free_table(char **result);
A result table is memory data structure created by the sqlite3_get_table() interface. A result table records the complete query results from one or more queries.
See
All rights reserved
C 扩展库 - sqlite3 API的更多相关文章
- C 扩展库 - sqlite3 API CRUD
CRUD struct student typedef struct STUDENT { unsigned int id; unsigned char name[16]; unsigned int a ...
- C 扩展库 - mysql API
MySQL API C API Data Structures MYSQL This structure represents handler for one database connection. ...
- C 扩展库 - mysql API general outline
Application programs should use this general outline for interacting with MySQL Initialize the MySQL ...
- C 扩展库 - mysql API CRUD
CRUD table create table if not exists `student` ( `id` int auto_increment, `name` varchar(16) not nu ...
- 安装php扩展库
无法加载'pdo_mysql' ,因为需要pdo这个module.PHP Warning: Cannot load module 'pdo_mysql' because required module ...
- 『Python CoolBook』C扩展库_其一_用法讲解
不依靠其他工具,直接使用Python的扩展API来编写一些简单的C扩展模块. 本篇参考PythonCookbook第15节和Python核心编程完成,值得注意的是,Python2.X和Python3. ...
- GLEW扩展库【转】
http://blog.sina.com.cn/s/blog_4aff14d50100ydsy.html 一.关于GLEW扩展库: GLEW是一个跨平台的C++扩展库,基于OpenGL图形接口.使用O ...
- 【OpenGL开发】关于GLEW扩展库
GLEW是一个跨平台的C++扩展库,基于OpenGL图形接口.使用OpenGL的朋友都知道,window目前只支持OpenGL1.1的涵数,但 OpenGL现在都发展到2.0以上了,要使用这些Open ...
- Layman 使用ffmpeg-php扩展库实现视频截图(默认图)
这几天做项目,其中一个需求是用户上传视频文件到服务器,然后服务器自动截取该视频的一帧作为该视频对应的缩略图,服务器端语言采用php编写,找了半天资料,发现ffmpeg-php可以满足该需求,所以下面简 ...
随机推荐
- AndroidStudio-永远无法进入
由于出现了莫名其妙的,AndroidStudio已过时错误信息 就去删除了: C:\Users\Administrator\.android C:\Users\Administrator\.Andro ...
- Javascript设计模式理论与实战:工厂方法模式
本文从简单工厂模式的缺点说起,引入工厂方法模式,介绍的工厂方法模式的基本知识,实现要点和应用场景,最后举例进行说明工厂方法模式的应用.在之前的<Javascript设计模式理论与实战:简单工厂模 ...
- TSQL--SQL SERVER 常用系统变量
----------全局变量select @@version as '版本';---------------------------返回当前数据库的版本信息 select APP_NAME ( ) a ...
- solrconfig.xml配置详解
solrconfig.xml配置文件主要定义了SOLR的一些处理规则,包括索引数据的存放位置,更新,删除,查询的一些规则配置. 可以在tomcat的安装路径下找到这个文件C:\Program File ...
- 更改kvm虚拟机磁盘大小
kvm 虚拟机的磁盘大小可通过命令:qemu-img resize filename size 来改,要注意的是resize只支持raw格式的磁盘文件,如果想更改qcow2等格式的磁盘大小,需先用qe ...
- java基础--配置环境变量的意义
0.jre和jdk jre(java runtime environment) 运行java程序要用的Java运行环境 jdk:java开发人员要用的java开发环境,包括jre 1.JAVA_HOM ...
- Rx.net 例子——(1)基础
1.订阅序列 using System; using System.Collections.Generic; using System.Linq; using System.Text; using S ...
- 【OCP-12c】CUUG 071题库考试原题及答案解析(23)
23.choose the best answer View the Exhibits and examine PRODUCTS and SALES tables. You issue the fol ...
- jQuery表单2
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- java从txt文档读写数据
package com.abin.facade.ws.mail.function; import java.io.BufferedReader; import java.io.File; import ...