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
#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>
#include <iostream>
#include <string>
using namespace std;
class Insert{
int excuteSql(string);
public:
int insertStudent(string, string);
int insertClass(string,int,int,string,int);
int insertLecturer(string, string);
int insertModule(string, string);
int insertRoom(string);
int enrolStudent(int, int);
};
int Insert::insertStudent(string firstname, string lastname)
{
string insertCommand=" insert into student(first_name, last_name ) values('";
insertCommand.append(firstname).append("', '").append(lastname).append("')");
excuteSql(insertCommand);
}
int Insert::insertClass(string name,int module_id,int room_number,string class_time, int lecturer_id)
{
string insertCommand=" insert into class(name,module_id,room_number,class_time,lecturer_id ) values('";
insertCommand.append(name).append("',").append(to_string(module_id)).append(",")
.append(to_string(room_number)).append(", '").append(class_time).append("',").append(to_string(lecturer_id)).append(");");
excuteSql(insertCommand);
}
int Insert::insertLecturer(string firstname,string lastname)
{
string insertCommand=" insert into lecturer(first_name, last_name ) values('";
insertCommand.append(firstname).append("', '").append(lastname).append("')");
excuteSql(insertCommand);
}
int Insert::insertModule(string title, string code)
{
string insertCommand="insert into module(title, code) values('";
insertCommand.append(title).append("', '").append(code).append("');");
excuteSql(insertCommand);
}
int Insert::insertRoom(string bname)
{
string insertCommand="insert into room(buiding_name) values('";
insertCommand.append(bname).append("')");
excuteSql(insertCommand);
}
int Insert::enrolStudent(int studentID, int classID)
{
//e.g. insert into enrolment(class_id,student_id,date) values(3,3,date('now'));
string insertCommand="insert into enrolment(class_id,student_id,date) values(";
insertCommand.append(to_string(classID)).append(" ,").append(to_string(studentID)).append(", date('now'));");
excuteSql(insertCommand);
}
int Insert::excuteSql(string sql)
{
sqlite3* DB;
char * SQL;
int EJRF;
char *errMsg = 0;
// opening the database
EJRF = sqlite3_open("TimeTable.db",&DB);
if(EJRF)
{
cout<<stderr, "unsuccessful opening database: %s\n";
return(0);
}
else
{
cout<< "opened database: \n";
}
// //create database a
// //Execute SQL statement
EJRF = sqlite3_exec(DB, sql.c_str(), NULL, 0, &errMsg);
cout<< EJRF <<errMsg ;
sqlite3_close(DB);
return 0;
}
/////insert into class vaules('GF',1,1,'2019-11-06',1);