#include <stdio.h>
#include <stdlib.h>
#include "sqlora.h"
/*
*
*/
int main(int argc, char** argv) {
sqlo_db_handle_t dbh;
const char *cstr = "xia/pass123@TestDB";
if (SQLO_SUCCESS != sqlo_init(SQLO_OFF,1,100)) {
printf ("sql_init failed. Exiting\n");
exit(1);
}
if (SQLO_SUCCESS != sqlo_connect(&dbh, cstr)){
printf ("connect failed. Exiting\n");
exit(1);
}
int stat;
const char * arg[2];
arg[0] = "1.0";
arg[1] = "2.0";
//VERSION 为 VARCHAR类型,如果是数字类型,也需要加双引号
//arg[0]="33"
stat=sqlo_run(dbh,"UPDATE STATUS SET VERSION = :1 where VERSION = :2",2,arg);
if (0>stat){
printf("Error happened %s ",sqlo_geterror(dbh));
}
stat = sqlo_commit(dbh);
sqlo_finish(dbh);
return (EXIT_SUCCESS);
}
方式二
int stat;
stat=sqlo_exec(dbh,"UPDATE TEST SET Age = 39 where ID = 1 and Name='jack'");
if (0>stat){
printf("Error happened %s ",sqlo_geterror(dbh));
}
stat = sqlo_commit(dbh);
方式三
int stat;
char stmt[1024];
sprintf(stmt,"UPDATE TEST SET Age = 40 where ID = %d and Name = %s",1,"'mike'");
stat=sqlo_exec(dbh,stmt);
if (0>stat){
printf("Error happened %s ",sqlo_geterror(dbh));
}
编译
gcc -c -g -I/usr/local/lib/libsqlora8/include -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.c
gcc -o dist/Debug/GNU-Linux-x86/gcctest build/Debug/GNU-Linux-x86/main.o -L/usr/local/lib -lsqlora8
LD_LIBRARY_PATH=LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
生成a.out, 运行: ./a.out