Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#ifndef CREATE_DB_H
#define CREATE_DB_H
#include <iostream>
#include <string>
#include <sqlite3.h>
using namespace std;
int callback(void *NotUsed, int len, char **value, char **column){
for(int i = 0; i < len; i++) {
cout << column[i] << ": " << value[i] << endl;
}
return 0;
}
int create_db() {/*creating a database for the timetable*/
sqlite3 *db;
char *column = 0;
int load;
string sql;
load = sqlite3_open("School.db", &db);
if(load){
cout << "DB Error: " << sqlite3_errmsg(db) << endl;
sqlite3_close(db);
return(1);
}
sql = "DROP TABLE STUDENTDETAILS;";
load = sqlite3_exec(db, sql.c_str(), callback, 0, &column);
sql = "CREATE TABLE STUDENTDETAILS ("\
"studentID INT NOT NULL," \
"name STR NOT NULL,"\
"surname STR NOT NULL,"\
"username STR NOT NULL,"\
"email STR NOT NULL,"\
"password STR NOT NULL);";
load = sqlite3_exec(db, sql.c_str(), callback, 0, &column);
sqlite3_close(db);
return 0;
}
#endif