#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sqlite3.h>
#define BUFFSIZE 256
#define OPTIONSIZE 20
char *zErrMsg = 0;
char strDB[BUFFSIZE];
static void
tableCreat(sqlite3 *db)
{
int
ret;
//create the
table
sprintf(strDB,"CREATE TABLE STUSCORE(\
ID INTEGER PRIMARY KEY ,\
STUID INTEGER,\
NAME VARCHAR(12),\
SCORE INTEGER\
);");
ret =
sqlite3_exec(db, strDB ,0 , 0, &zErrMsg);
if(ret!=
0)
{
printf("create the table failed!\n");
exit(-1);
}
printf("create the table success!\n");
}
static void
showTable(sqlite3 *db)
{
int nrow=1, ncolumn=1 ;
char **azResult ;
int i,j=0;
strcpy(strDB, "SELECT * FROM STUSCORE") ;
sqlite3_get_table(db, strDB, &azResult,
&nrow, &ncolumn,
&zErrMsg) ;
printf("nrow : %d ncolumn :%d \n", nrow, ncolumn) ;
for (i = 0; i < (nrow + 1) * ncolumn; i++)
{
j++;
printf("%7s ", azResult[i])
;
if (j == ncolumn)
{
printf("\n");
j = 0;
}
}
sqlite3_free_table(azResult);
}
static void
search(sqlite3 *db)
{
char *stuidc
= "STUID";
char *namec
= "NAME";
char *scorec
= "SCORE";
char
**azResult;
int nrow =
0, ncolumn = 0;
char
optionAttrib[OPTIONSIZE];
char
optionValue[OPTIONSIZE];
int i = 0
;
int j =
0;
printf("Welcome to search!\n");
while(1)
{
printf("Option(STUID,NAME,SCORE):");
scanf("%s",optionAttrib);
if(!strncasecmp(stuidc,optionAttrib,sizeof(optionAttrib)))
{
printf("Option(num):");
scanf("%s",optionValue);
break;
}
else
if(!strncasecmp(namec,optionAttrib,sizeof(optionAttrib)))
{
printf("Option(name):");
scanf("%s",optionValue);