SHOW:
|
|
- or go back to the newest paste.
| 1 | #include "sqlite3.h" | |
| 2 | #include "sqliteInt.h" | |
| 3 | #include "vdbe.h" | |
| 4 | #include "vdbeInt.h" | |
| 5 | #include "opcodes.h" | |
| 6 | ||
| 7 | ||
| 8 | static int callback(void *NotUsed, int argc, char **argv, char **azColName){
| |
| 9 | int i; | |
| 10 | for(i=0; i<argc; i++){
| |
| 11 | printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
| |
| 12 | } | |
| 13 | printf("\n");
| |
| 14 | return 0; | |
| 15 | } | |
| 16 | ||
| 17 | ||
| 18 | int main(int argc,char* argv[]) | |
| 19 | {
| |
| 20 | sqlite3 *db; | |
| 21 | sqlite3_stmt *pStmt=NULL; | |
| 22 | char *sql,*zerrmsg=0; | |
| 23 | int rc,i; | |
| 24 | Vdbe *pVdbe; | |
| 25 | const unsigned char *zAns; | |
| 26 | ||
| 27 | //open database | |
| 28 | rc=sqlite3_open("d.db",&db);
| |
| 29 | if(rc) {
| |
| 30 | fprintf(stderr,"cant open database: %s \n",sqlite3_errmsg(db)); | |
| 31 | exit(0); | |
| 32 | } | |
| 33 | ||
| 34 | sql="drop table student;"; | |
| 35 | rc=sqlite3_exec(db,sql,callback,0,&zerrmsg); | |
| 36 | sql="drop table location;"; | |
| 37 | rc=sqlite3_exec(db,sql,callback,0,&zerrmsg); | |
| 38 | ||
| 39 | //create table | |
| 40 | sql="create table student(id int primary key,name text,age int);"\ | |
| 41 | "create table location(city text,country text,id int primary key);"; | |
| 42 | ||
| 43 | rc=sqlite3_exec(db,sql,callback,0,&zerrmsg); | |
| 44 | ||
| 45 | //insert values | |
| 46 | sql="insert into student values(1,'sai',20);"\ | |
| 47 | "insert into student values(2,'ram',25);"\ | |
| 48 | ||
| 49 | "insert into location values('new york','usa',1);"\
| |
| 50 | "insert into location values('london','uk',2);";
| |
| 51 | ||
| 52 | ||
| 53 | rc=sqlite3_exec(db,sql,callback,0,&zerrmsg); | |
| 54 | ||
| 55 | if( rc != SQLITE_OK ) {
| |
| 56 | fprintf(stderr, "SQL error: %s\n", zerrmsg); | |
| 57 | sqlite3_free(zerrmsg); | |
| 58 | } | |
| 59 | else {
| |
| 60 | fprintf(stdout, "Records created successfully\n"); | |
| 61 | } | |
| 62 | ||
| 63 | sql="select * from student,location;"; | |
| 64 | rc=sqlite3_exec(db,sql,callback,0,&zerrmsg); | |
| 65 | ||
| 66 | ||
| 67 | if(rc != SQLITE_OK){
| |
| 68 | fprintf(stderr, "SQL error: %s\n", zerrmsg); | |
| 69 | sqlite3_free(zerrmsg); } | |
| 70 | ||
| 71 | ||
| 72 | rc = sqlite3_prepare(db,sql,strlen(sql)+1,&pStmt,NULL); | |
| 73 | ||
| 74 | if(rc != SQLITE_OK) {
| |
| 75 | fprintf(stderr, "SQL error: Prepare Err"); | |
| 76 | } | |
| 77 | ||
| 78 | pVdbe = (Vdbe*)pStmt; | |
| 79 | ||
| 80 | for(i=0;i<pVdbe->nOp;i++) {
| |
| 81 | - | printf("addr opcode p1 p2 p3 p4 p5 comment\n");
|
| 81 | + | |
| 82 | - | printf("---- ------------- -- -- -- ----------- -- -------------\n");
|
| 82 | + | |
| 83 | ||
| 84 | sqlite3_close(db); | |
| 85 | } |