sqlite环境下的数据库

sqlite环境下的数据库,第1张

概述sqlite3数据库之处女作 By—it_zujun #include <stdio.h>#include <stdlib.h>#include <sqlite3.h>#include <string.h>#define LEN 20#define TAB_NAME "room"#define SIZE 1024sqlite3 *db = NUL sqlite3数据库之处女作
By—it_zujun

#include <stdio.h>#include <stdlib.h>#include <sqlite3.h>#include <string.h>#define     LEN     20#define     TAB_name "room"#define     SIZE    1024sqlite3 *db = NulL;char** result;char buffer[1024];          //send buffer to AndroIDint nx,ny;char* errmsg;int ret;char tab[20];               //sql command sqacechar a[7] = {'"','"','(',')',',';','*'};char* create_tab_name(char tab[20]);     //build  tab command tab[20]voID create_tab(sqlite3* db);            //do create_tab commandchar* cmd_insert(char tab[20],char* device,char* status);char* sql_insert(char* device,char* status);char* cmd_delete(char tab[20],char* device);voID sql_delete(char* device);char*  sql_to_androID(char tab[20]);char*  sql_to_androID(char tab[20]){    int i,j;    memset(tab,LEN);    strcat(tab,"select * from room");    ret = sqlite3_get_table(db,tab,&result,&ny,&nx,&errmsg);    if (ret != sqlITE_OK)        printf("serch the room data Failed\n");    else        printf("serch thr room data succeed\n");    printf("nx = %d\n",nx);    printf("ny = %d\n",ny);    memset(buffer,SIZE);    strcat(buffer,"R");        for(i = 1; i< ny+1; i++)    {        strcat(buffer,":");        for (j=0; j< nx; j++)        {            strcat(buffer,result[i*nx+j]);        }    }/*    for (i= nx; i<(ny+1)*nx; i++)    {        strcat(buffer,":");        strcat(buffer,result[i]);        printf("string: %s\n",result[i]);    } */    printf("send_to_androID: %s\n",buffer);    }char* cmd_update(char* device,char* sta){    memset(tab,"update room set sta = ");    strncat(tab,&a[0],1);    strcat(tab,sta);    strncat(tab," where device = ");    strncat(tab,device);    strncat(tab,1);    strncat(tab,&a[5],1);    printf("string = %s\n",tab);    return tab;}voID sql_update(char* device,char* sta){    cmd_update(device,sta);    ret = sqlite3_exec(db,NulL,&errmsg);    if (ret != sqlITE_OK)        printf("sql update Failed\n");    else         printf("sql update succeed\n");    return;}char* cmd_search(char tab[20],char* device){    /*     select * from room where device = %s     */    memset(tab,"select * from room where device = ");    strcat(tab,device);    printf("string: %s\n",tab);    return tab;}voID sql_search(char* device){    ret = sqlite3_exec(db,&errmsg);    if (ret != sqlITE_OK)        printf("sql search Failed\n");    else           printf("sql search succeed\n");    return;}char* cmd_delete(char tab[20],char* device){    memset(tab,"delete from room where device = ");    strcat(tab,tab);    return tab;}voID sql_delete(char* device){    cmd_delete(tab,device);    ret = sqlite3_exec(db,&errmsg);    if (ret != sqlITE_OK)        printf("sql delete Failed\n");    else        printf("sql delete succeed\n");    return;}char* cmd_insert(char tab[20],char* status){    memset(tab,"insert into room values");    strncat(tab,&a[2],1); // (    strncat(tab,1); // "    strcat(tab,device);    // device    strncat(tab,&a[1],1); // "    strncat(tab,&a[4],1); //,strncat(tab,status);    // status    strncat(tab,&a[3],1); // )    strncat(tab,1); // ;    return tab;}char* sql_insert(char* device,char* status){  cmd_insert(tab,device,status);  ret = sqlite3_exec(db,&errmsg);  if (ret != sqlITE_OK)      printf("sql insert Failed\n");  else       printf("sql insert successe\n");  return;}voID tab_insert(sqlite3* db,char* status){    ret = sqlite3_exec(db,&errmsg);    if (ret != sqlITE_OK)        printf("create room tab Failed\nyou have created tab !!!!!!\n");    else         printf("crate root tab succeed\n");}char* create_tab_name(char tab[20]){    memset(tab,"create table ");    strcat(tab,TAB_name);    strcat(tab,"(device varchar(2),sta varchar(1));");    return tab;}voID create_tab(sqlite3* db){    create_tab_name(tab);    ret = sqlite3_exec(db,&errmsg);    if (ret != sqlITE_OK)    {        printf("create room tab Failed\nyou have created tab !!!!!!\n");    } else {        printf("crate root tab succeed\n");    }    return;}int main(int argc,char *argv[]){    ret = sqlite3_open("uwan.db",&db);    if (sqlITE_OK != ret)    {        printf("open uwan.db Failed\n");        exit(0);    } else {        printf("open uwan.db succeed\n");    }    create_tab(db);    sql_insert("11","N");    sql_insert("12","N");    sql_insert("13","N");    sql_insert("14","F");    sql_insert("15","F");  //  sql_delete("14");    cmd_search(tab,"11");    sql_to_androID(tab);    sql_update("13","F");    sql_search("12");    sqlite3_close(db);    printf("close uwan.db succed\n");        return 0;}
总结

以上是内存溢出为你收集整理的sqlite环境下的数据库全部内容,希望文章能够帮你解决sqlite环境下的数据库所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1170895.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存