- enhancement: add autolink and project template for sqlite3

This commit is contained in:
Roy Qu 2022-04-18 20:19:11 +08:00
parent 15ec17f16b
commit 434d46ef80
5 changed files with 135 additions and 3 deletions

View File

@ -1,3 +1,6 @@
Red Panda C++ Version 1.0.5
- enhancement: add autolink and project template for sqlite3
Red Panda C++ Version 1.0.4 Red Panda C++ Version 1.0.4
- fix: hide function tips, when move or resize the main window - fix: hide function tips, when move or resize the main window
- enhancement: add help link for regular expression in search dialog - enhancement: add help link for regular expression in search dialog

View File

@ -25,18 +25,22 @@
}, },
{ {
"header": "ege.h", "header": "ege.h",
"links": "-lgraphics -luuid -lmsimg32 -lgdi32 -limm32 -lole32 -loleaut32 -lwinmm -lgdiplus" "links": "-lgraphics -luuid -lmsimg32 -lgdi32 -limm32 -lole32 -loleaut32 -lwinmm -lgdiplus -mwindows"
}, },
{ {
"header": "raylib.h", "header": "raylib.h",
"links": "-lraylib -lopengl32 -lgdi32 -lwinmm" "links": "-lraylib -lopengl32 -lgdi32 -lwinmm"
}, },
{ {
"header": "winsock2.h", "header": "sqlite3.h",
"links": "-lws2_32" "links": "-lsqlite3"
}, },
{ {
"header": "turtle.h", "header": "turtle.h",
"links": "-lturtle" "links": "-lturtle"
},
{
"header": "winsock2.h",
"links": "-lws2_32"
} }
] ]

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

View File

@ -0,0 +1,19 @@
[Template]
ver=2
Name=Sqlite3
Icon=sqlite.ico
Description=A Sqlite3 API Example
Description[zh_CN]=Sqlite3 示例程序
Category=Utilities
Category[zh_CN]=工具
[Unit0]
CName=main.c
C=sqlite_c.txt
[Project]
UnitCount=1
Type=1
Compiler=
CppCompiler=-std=gnu++11
Linker=-lsqlite3

View File

@ -0,0 +1,106 @@
/*
An API demo of sqlite3
author: Ady Liu
email: imxylz@gmail.com
web: http://www.blogjava.net/xylz/archive/2012/09/25/388519.html
*/
#include <stdio.h>
#include <string.h>
#include <sqlite3.h>
int print_record(void *,int,char **,char **);
int main(void){
const char *sql_drop_table="drop table if exists t";
const char *sql_create_table="create table t(id int primary key,msg varchar(128))";
char *errmsg = 0;
int ret = 0;
int i = 0;
sqlite3_stmt *stmt;
char ca[255];
char **dbresult;
int j,nrow,ncolumn,index;
sqlite3 *db = 0;
ret = sqlite3_open("./sqlite3-demo.db",&db);
if(ret != SQLITE_OK){
fprintf(stderr,"Cannot open db: %s\n",sqlite3_errmsg(db));
return 1;
}
printf("Open database\n");
ret = sqlite3_exec(db,sql_drop_table,NULL,NULL,&errmsg);
if(ret != SQLITE_OK){
fprintf(stderr,"drop table fail: %s\n",errmsg);
}
ret &= sqlite3_exec(db,sql_create_table,NULL,NULL,&errmsg);
if(ret != SQLITE_OK){
fprintf(stderr,"create table fail: %s\n",errmsg);
}
ret = sqlite3_exec(db,"insert into t(id,msg) values(1,'Ady Liu')",NULL,NULL,&errmsg);
printf("Insert a record %s\n",ret == SQLITE_OK ? "OK":"FAIL");
ret = sqlite3_exec(db,"insert into t(id,msg) values(2,'IMXYLZ')",NULL,NULL,&errmsg);
printf("Insert a record %s\n",ret == SQLITE_OK ? "OK":"FAIL");
ret = sqlite3_exec(db,"delete from t where id < 3",NULL,NULL,&errmsg);
printf("Delete records: %s\n",ret == SQLITE_OK ? "OK":"FAIL");
//prepare statement
sqlite3_prepare_v2(db,"insert into t(id,msg) values(?,?)",-1,&stmt,0);
for(i=10;i<20;i++){
sprintf(ca,"HELLO#%i",i);
sqlite3_bind_int(stmt,1,i);
sqlite3_bind_text(stmt,2,ca,strlen(ca),SQLITE_STATIC);
sqlite3_step(stmt);
sqlite3_reset(stmt);
}
sqlite3_finalize(stmt);
//select data
ret = sqlite3_exec(db,"select * from t",print_record,NULL,&errmsg);
if(ret != SQLITE_OK){
fprintf(stderr,"query SQL error: %s\n",errmsg);
}
sqlite3_exec(db,"update t set msg='MESSAGE#10' where id=10",NULL,NULL,&errmsg);
//select table
ret = sqlite3_get_table(db,"select * from t",&dbresult,&nrow,&ncolumn,&errmsg);
if(ret == SQLITE_OK){
printf("query %i records.\n",nrow);
index=ncolumn;
for(i=0;i<nrow;i++){
printf("[%2i]",i);
for(j=0;j<ncolumn;j++){
printf(" %s",dbresult[index]);
index++;
}
printf("\n");
}
}else{
fprintf(stderr,"query with get_table error: %s\n",errmsg);
}
sqlite3_free_table(dbresult);
ret = sqlite3_exec(db,"delete from t",NULL,NULL,&errmsg);
if(ret == SQLITE_OK){
printf("delete records: %i\n",sqlite3_changes(db));
}
sqlite3_free(errmsg);
sqlite3_close(db);
printf("Close database\n");
return 0;
}
int print_record(void * params,int n_column,char **column_value,char **column_name){
int i;
for(i=0;i<n_column;i++){
printf("\t%s",column_value[i]);
}
printf("\n");
return 0;
}