sqlite3查询例子

 
#include <stdio.h>

#include <stdlib.h>

#include <sqlite3.h>



#define P3SCAN_DB "/usr/local/conf/as.db"

sqlite3 *p3scan_db = NULL;



int main()

{

        int ret, i, n;

        char *errmsg = NULL, **result = NULL;

        int nrow = 0,ncol = 0;



        if(sqlite3_open(P3SCAN_DB, &p3scan_db))

        {

                sqlite3_free(p3scan_db);

                return -1;

        }



        ret = sqlite3_get_table(p3scan_db,"select blackserverip from blackServer;",&result,&nrow,&ncol,&errmsg);

        sqlite3_free(errmsg);

        if(ret == SQLITE_OK)

        {

                printf("nrow: %d, ncol: %d\n", nrow, ncol);

                if(nrow && result)

                {

                        for(i=1; i<=nrow; i++)

                        {

                                printf("%s\n", result[i*ncol]);

                        }

                }

                sqlite3_free_table(result);

        }

}
编译:
[root@localhost ~]# gcc -o select_blackserverip select_blackserverip.c -lsqlite3
 


你可能感兴趣的:(sqlite3)