@@ -1,97 +0,0 @@
5−sqlite3* db; // pointer to the database
9−int select_callback(void *p_data, int num_fields, char **p_fields, char **p_col_names) {
12− int *p_rn =(int*)p_data; // pointer counter
16− // Go through the columns
17− for(int i=0; i<num_fields; i++){
18− printf("%20s", p_col_names[i]);
21− for(i=0; i<num_fields; i++){
26− (*p_rn)++; // increment the pointer counter for column
29− for(i=0; i< num_fields; i++){
30− printf("%20s", p_fields[i]);
35−void select_stmt(const char* stmt){
36− char *errmsg; // erro
37− int ret; // return code
38− int nrecs =0; // return code 0 for successful
42− // open database, SQL to be evaluated, call back function, 1st argument to call back ,err
43− ret = sqlite3_exec(db, stmt, select_callback, &nrecs, &errmsg);
45− printf("Error in select statement %s [%s].\n", stmt, errmsg);
48− printf("\n %d records returned.\n", nrecs);
52−void sql_stmt(const char* stmt){
56− ret = sqlite3_exec(db, stmt, 0, 0, &errmsg);
59− printf("Error in select statement %s [%s].\n", stmt, errmsg);
66− sql_stmt("insert into Student values ('Alice','Peterson',1234551,'Medicine',12)");
67− //sql_stmt("insert into mytable values ('mytable2' , 251826, 22660136)");
68− //sql_stmt("insert into mytable values ('mytable3' , 271826, 22684136)");
73− sqlite3_open("./students.db", &db);
76− printf("Could not open the database");
80− //sql_stmt("Create table Student (Name, Surname, Passport ,School, School Student)");
82−// select_stmt("Select *from Student;");
83−// select_stmt("Select *from Module;");
84−// select_stmt("Select *from Enrollment;");
85− select_stmt("SELECT student.name FROM student, module, enrollment WHERE module.credits = 30 AND student.school_student = enrollment.school_student AND student.school = enrollment.school AND enrollment.code = module.code");