Skip to content
Permalink
Browse files
Finished resit
  • Loading branch information
anumoluu committed Aug 13, 2019
1 parent dff563b commit 098f9b9332ea68196c55a1f46a6fa46e8dec7724
Show file tree
Hide file tree
Showing 8 changed files with 935 additions and 207 deletions.
@@ -0,0 +1,216 @@
#include <iostream> #took some help from https://github.coventry.ac.uk/milesd7/122COM-Project/blob/master/DataBase.h

#include <array>

#include <string>

#include "libsqlite.hpp"

using namespace std;

int UploadLecturer(int id, string Name){

try

{

sqlite::sqlite db( "uni_info.db" ); //open database



auto q1 = db.get_statement();//create cursor

auto q2 = db.get_statement();//create cursor



q1->set_sql( "INSERT INTO Lecturers ( Lect_ID, Lect_name) "

"VALUES (?, ?);" );// insert into DB

q1->prepare();



q1->bind( 1, id );

q1->bind( 2, Name );



q1->step();


}



catch( sqlite::exception e )

{

cerr << e.what() << endl;

return 1;

}

}
int UploadStudent(int id, string Name, string class1){

try

{

sqlite::sqlite db( "uni_info.db" ); //open database



auto q1 = db.get_statement();//create cursor

auto q2 = db.get_statement();//create cursor



q1->set_sql( "INSERT INTO Student ( Stu_ID, Student_Name, Class) "

"VALUES (?, ?, ?);" );// insert into DB

q1->prepare();



q1->bind( 1, id );

q1->bind( 2, Name );

q1->bind( 3, class1 );

q1->step();


}



catch( sqlite::exception e )

{

cerr << e.what() << endl;

return 1;

}

}






int printLecturers(){

try

{

sqlite::sqlite db( "uni_info.db" ); // open database



auto us = db.get_statement();

auto bo = db.get_statement();



us->set_sql( "SELECT * FROM Lecturers" );// set query

us->prepare();




while( us->step()){

if (us->get_int(0) < 10){// if datas from DB is less than 10 , spaces between id and name is 5

cout <<" "<< us->get_int(0) << " " << us->get_text(1) <<endl;

}

else{ //// if datas from DB is more than 10 , spaces between id and name is 4..

cout<<" "<<us-> get_int(0) << " " << us->get_text(1)<<endl;



}

}

}

catch( sqlite::exception e ){

cerr << e.what() << endl;

return 1;

}

}
int printStudents(){

try

{

sqlite::sqlite db( "uni_info.db" ); // open database



auto us = db.get_statement();

auto bo = db.get_statement();



us->set_sql( "SELECT * FROM Student" );// set query

us->prepare();




while( us->step()){

if (us->get_int(0) < 10){// if datas from DB is less than 10 , spaces between id and name is 5

cout <<" "<< us->get_int(0) << " " << us->get_text(1) << " " << us->get_text(2)<<endl;

}

else{ //// if datas from DB is more than 10 , spaces between id and name is 4..

cout<<" "<<us-> get_int(0) << " " << us->get_text(1) <<" " << us->get_text(2)<<endl;



}

}

}

catch( sqlite::exception e ){

cerr << e.what() << endl;

return 1;

}

}

0 comments on commit 098f9b9

Please sign in to comment.