资源简介
SQLite3参考手册,CHM格式,包含C/C++、Java、PHP等函数接口
代码片段和文件信息
#include
#include
#include
static int callback(void *data int argc char **argv char **azColName)
{
int i;
for(i=0; i<argc; i++)
{
printf(“%s = %s\n“ azColName[i] argv[i] ? argv[i] : “NULL“);
}
printf(“\n“);
return 0;
}
static int callback(void *data int argc char **argv char **azColName)
{
int i;
fprintf(stderr “%s: “ (const char*)data);
for(i=0; i {
printf(“%s = %s\n“ azColName[i] argv[i] ? argv[i] : “NULL“);
}
printf(“\n“);
return 0;
}
/*连接数据库*/
int main(int argc char* argv[])
{
sqlite3 *db;
char *zErrMsg = 0;
int rc;
rc = sqlite3_open(“test.db“ &db);
if( rc ){
fprintf(stderr “Can‘t open database: %s\n“ sqlite3_errmsg(db));
exit(0);
}else{
fprintf(stderr “Opened database successfully\n“);
}
sqlite3_close(db);
}
/*创建表*/
int main(int argc char* argv[])
{
sqlite3 *db;
char *zErrMsg = 0;
int rc;
char *sql;
/* Open database */
rc = sqlite3_open(“test.db“ &db);
if( rc ){
fprintf(stderr “Can‘t open database: %s\n“ sqlite3_errmsg(db));
exit(0);
}else{
fprintf(stdout “Opened database successfully\n“);
}
/* Create SQL statement */
sql = “CREATE TABLE COMPANY(“ \
“ID INT PRIMARY KEY NOT NULL“ \
“NAME TEXT NOT NULL“ \
“AGE INT NOT NULL“ \
“ADDRESS CHAR(50)“ \
“SALARY REAL );“;
/* Execute SQL statement */
rc = sqlite3_exec(db sql callback 0 &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr “SQL error: %s\n“ zErrMsg);
sqlite3_free(zErrMsg);
}else{
fprintf(stdout “Table created successfully\n“);
}
sqlite3_close(db);
return 0;
}
/*INSERT操作*/
int main(int argc char* argv[])
{
sqlite3 *db;
char *zErrMsg = 0;
int rc;
char *sql;
/* Open database */
rc = sqlite3_open(“test.db“ &db);
if( rc ){
fprintf(stderr “Can‘t open database: %s\n“ sqlite3_errmsg(db));
exit(0);
}else{
fprintf(stderr “Opened database successfully\n“);
}
/* Create SQL statement */
sql = “INSERT INTO COMPANY (IDNAMEAGEADDRESSSALARY) “ \
“VALUES (1 ‘Paul‘ 32 ‘California‘ 20000.00 ); “ \
“INSERT INTO COMPANY (IDNAMEAGEADDRESSSALARY) “ \
“VALUES (2 ‘Allen‘ 25 ‘Texas‘ 15000.00 ); “ \
“INSERT INTO COMPANY (IDNAMEAGEADDRESSSALARY)“ \
“VALUES (3 ‘Teddy‘ 23 ‘Norway‘ 20000.00 );“ \
“INSERT INTO COMPANY (IDNAMEAGEADDRESSSALARY)“ \
“VALUES (4 ‘Mark‘ 25 ‘Rich-Mond ‘ 65000.00 );“;
/* Execute SQL statement */
rc = sqlite3_exec(db sql callback 0 &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr “SQL error: %s\n“ zErrMsg);
sqlite3_free(zErrMsg);
}else{
fprintf(stdout “Records created successfully\n“);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5653 2017-11-02 09:05 DEMO.c
文件 142474 2017-05-12 16:39 SQLite参考手册.CHM
评论
共有 条评论