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 00000000..2d8f08a1 Binary files /dev/null and b/windows/templates/sqlite.ico differ diff --git a/windows/templates/sqlite.template b/windows/templates/sqlite.template new file mode 100644 index 00000000..5b9f4bee --- /dev/null +++ b/windows/templates/sqlite.template @@ -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 diff --git a/windows/templates/sqlite_c.txt b/windows/templates/sqlite_c.txt new file mode 100644 index 00000000..9e16ea19 --- /dev/null +++ b/windows/templates/sqlite_c.txt @@ -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 +#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