int main(int argc, char* argv[]) { sqlite3 * db; int i; COLUMN column[10]; pTable_name = table_name; strcpy(pTable_name, "test_table"); ret = sqlite3_open("student.db", &db); if(ret != SQLITE_OK) { perror("slqite3_open"); exit(1); } while(choice != 0) { printf("please input your choise:\n"); printf("-------------------------------------\n"); printf("|0.exit|1.create|2.show|3.insert|4.update|5.delete|6.empty|7.drop|\n"); printf("-------------------------------------\n"); scanf("%d", &choice); switch(choice) { case 0: printf("you choise leave, y or n?\n"); setbuf(stdin, NULL); scanf("%c", &c); setbuf(stdin, NULL); if(c == 'y') { if(test_flag == 0) { db_drop(db, "test_table", &test_flag, &create_flag); } printf("goodbye!\n"); sqlite3_close(db); return 0; } else { choice = -1; } break; case 1: printf("we will create a table for you, please input the name of your table:\n"); scanf("%s",pTable_name); printf("please input the number of column:\n"); scanf("%d", &column_num); printf("please input column_name column_type:\n"); for(i = 0; i < column_num; i++) scanf("%s %s", column[i].column_name, column[i].column_type); db_create(db, table_name, column_num, column, &create_flag); break; case 2: db_flag(db, &create_flag, &test_flag, table_name); db_show(db, table_name); break; case 3: db_flag(db, &create_flag, &test_flag, table_name); db_insert(db, table_name, column_num, column, &test_flag, &create_flag); break; case 4: db_flag(db, &create_flag, &test_flag, table_name); db_update(db, table_name, column_num, column, &test_flag, &create_flag); break; case 5: db_flag(db, &create_flag, &test_flag, table_name); db_delete(db, table_name); break; case 6: db_flag(db, &create_flag, &test_flag, table_name); db_empty(db, table_name); break; case 7: db_flag(db, &create_flag, &test_flag, table_name); db_drop(db, table_name, &test_flag, &create_flag); break; default: printf("your choice is not exist!\n"); break; } } sqlite3_close(db); return 0; }
int main(int argc, char** argv) { char* args; /* no option, print usage */ if (argc < 2) { usage(); return 0; } config_load(); /* connect to the db or error */ if (db_connect()) { fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); return 0; } /* compile the arguments */ args = get_args(argc,argv); /* if listing notes */ if (strcmp(argv[1],"list") == 0) { db_list(args); }else{ /* if null argument print usage */ if (args == NULL || argc <3) { usage(); /* if creating a new note */ }else if (strcmp(argv[1],"new") == 0 || strcmp(argv[1],"create") == 0) { db_new(args); /* if opening/editing an existing note */ }else if (strcmp(argv[1],"open") == 0 || strcmp(argv[1],"edit") == 0) { db_edit(args); /* append to a note if data is on stdin */ }else if (strcmp(argv[1],"append") == 0) { if (isatty(STDIN_FILENO)) { db_edit(args); }else{ db_append(args); } /* encrypt a new or existing note */ }else if (strcmp(argv[1],"encrypt") == 0) { db_encrypt(args); /* decrypt an existing note */ }else if (strcmp(argv[1],"decrypt") == 0) { db_decrypt(args); /* display an existing note */ }else if (strcmp(argv[1],"show") == 0) { db_show(args); /* if deleting note/s */ }else if (strcmp(argv[1],"del") == 0) { db_del(args); /* unknown option, print usage */ }else{ usage(); } } /* free args if we can */ if (args != NULL) free(args); /* close the database */ sqlite3_close(db); /* save config */ config_save(); return 0; }