From 434d46ef80d17e588ed4f605ade33fdee351cec7 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 18 Apr 2022 20:19:11 +0800 Subject: [PATCH] - enhancement: add autolink and project template for sqlite3 --- NEWS.md | 3 + RedPandaIDE/resources/autolink.json | 10 ++- windows/templates/sqlite.ico | Bin 0 -> 766 bytes windows/templates/sqlite.template | 19 +++++ windows/templates/sqlite_c.txt | 106 ++++++++++++++++++++++++++++ 5 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 windows/templates/sqlite.ico create mode 100644 windows/templates/sqlite.template create mode 100644 windows/templates/sqlite_c.txt diff --git a/NEWS.md b/NEWS.md index 31a26276..a5d01c95 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 - fix: hide function tips, when move or resize the main window - enhancement: add help link for regular expression in search dialog diff --git a/RedPandaIDE/resources/autolink.json b/RedPandaIDE/resources/autolink.json index a0d8d792..59e03fdc 100644 --- a/RedPandaIDE/resources/autolink.json +++ b/RedPandaIDE/resources/autolink.json @@ -25,18 +25,22 @@ }, { "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", "links": "-lraylib -lopengl32 -lgdi32 -lwinmm" }, { - "header": "winsock2.h", - "links": "-lws2_32" + "header": "sqlite3.h", + "links": "-lsqlite3" }, { "header": "turtle.h", "links": "-lturtle" + }, + { + "header": "winsock2.h", + "links": "-lws2_32" } ] diff --git a/windows/templates/sqlite.ico b/windows/templates/sqlite.ico new file mode 100644 index 0000000000000000000000000000000000000000..2d8f08a1d2255afe33751a1d1c65c96278e1ca8d GIT binary patch literal 766 zcmah{v2KGf6g-NhjM=)v*uTI-q;$ytuvEfhhJKU>h75c|#n>?;1LE}_#<4>y^_lbY z`R>^kHc+tDwSmU>3-HSPM%08Q3Iq+*{tgH5gL5IV=Mdg|W))=pAfh9JO{cUAVNNF- z$C@wi*FNLs*0&!vP3-yQb2zuDz}$u*FQ7bR29 +#include +#include + +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