简单Sqlite 查询

前端之家收集整理的这篇文章主要介绍了简单Sqlite 查询前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#include <stdio.h>
#include <sqlite3.h>

#define  AV_DB "/usr/local/conf/av.db"
int main()
{
        sqlite3 *av_db = NULL;
        char *errmsg = NULL;
        char **result=NULL;
        int nrow,ncol,ret,i;
        int smtp_num[6];
        int pop_num[6];


        if(sqlite3_open(AV_DB,&av_db))
        {
                sqlite3_close(av_db);
                fprintf(stderr,"open error.\n");
                return -1;
        }
//smtp
        ret = sqlite3_get_table(av_db,"select port from service where name = \'smtp\'",&result,&nrow,&ncol,&errmsg);
        if(ret != 0)
        {
                sqlite3_free(errmsg);
                fprintf(stderr,"get error.\n");
                return -1;
        }
        for(i=1; i<=nrow; i++){
                smtp_num[i] = atoi(result[i*ncol]);
        }
        for(i=1;i<=6;i++)
                printf("smtp port: %d\n",smtp_num[i]);

//pop
        ret = sqlite3_get_table(av_db,"select port from service where name = \'pop\'",&errmsg);
        if(ret != 0)
        {
              sqlite3_free(errmsg);
                fprintf(stderr,"get error.\n");
                return -1;
        }
        for(i=1; i<=nrow; i++){
                pop_num[i] = atoi(result[i*ncol]);
        }
        for(i=1;i<=6;i++)
                printf("pop port: %d\n",pop_num[i]);
        return 0;
}

猜你在找的Sqlite相关文章