Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
375 additions
and
0 deletions.
There are no files selected for viewing
19
.codio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
// This file is used to configure the three buttons along Codio's top menu. | ||
|
||
// Run button configuration | ||
"commands": { | ||
"Compile & Run": "g++ -o {{filename_no_ext}} {{filename}} && ./{{filename_no_ext}}", | ||
"Compile": "g++ -o {{filename_no_ext}} {{filename}}", | ||
"Run": "./{{filename_no_ext}}" | ||
}, | ||
// Preview button configuration | ||
"preview": { | ||
"Project Index (static)": "https://{{domain}}/{{index}}", | ||
"Current File (static)": "https://{{domain}}/{{filepath}}", | ||
"Box URL": "http://{{domain3000}}/", | ||
"Box URL SSL": "https://{{domain3000}}/" | ||
}, | ||
// Debugger target button configuration | ||
"debugger": [{"type":"GDB","command":"/tmp/program83b0717fa37e2e0346bafc8c1429cb87 ","before":"g++ -g {{filepath}} -o /tmp/program83b0717fa37e2e0346bafc8c1429cb87","single":true,"lang":"cpp","additionalCompilerFlags":"","sourcePath":"{{filepath}}","args":"","uuid":"63f293ba-8385-602d-bcbe-7b86f94c9c58","name":"Debug Current File"}] | ||
} |
21
README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Creating C++ programs in Codio | ||
|
||
### Make a new file | ||
Use **File > New File...** or right-click in the file tree to create a new file. You can right-click in the file tree to rename or delete files. | ||
|
||
As Codio detects which file is in focus, simply put your cursor into whichever code editor you want to compile and run. | ||
|
||
### Compile, Run or Both | ||
Use the Run button (that looks like a Rocketship) to Compile and Run the file your cursor is in. | ||
|
||
![](https://global.codio.com/platform/readme.resources/RunMenuJava.png) | ||
|
||
Use the drop-down arrow to the right of the "Compile & Run" option to change the button to just Compile or just Run. | ||
|
||
### Debug your Code | ||
Use the "Debug Current File" on the far right of the top menu bar to launch the debugger targeting the file your cursor is in. | ||
|
||
### Reconfigure your Panels for easier development | ||
Use the **View > Panels** menu on the top tool bar to segment your screen. | ||
|
||
Simply drag the tab of the file or terminal (the part with the name) you want to move into the new panel. |
0
database
Empty file.
44
functions.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <iostream> | ||
#include <array> | ||
#include <string> | ||
#include "libsqlite.hpp" | ||
|
||
using namespace std; | ||
|
||
int showLecturers(){ | ||
sqlite::sqlite db("4007database.db"); | ||
|
||
auto cur = db.get_statement(); | ||
cur->set_sql("SELECT * FROM LecturerTable;"); | ||
cur->prepare(); | ||
|
||
while( cur->step()){ | ||
cout <<" "<< cur->get_int(0) << " " << cur->get_text(1) <<endl; | ||
|
||
} | ||
} | ||
|
||
int showStudents(){ | ||
sqlite::sqlite db("4007database.db"); | ||
|
||
auto cur = db get_statement(); | ||
cur->set_sql( "SELECT * FROM StudentTable" ); | ||
cur->prepare(); | ||
|
||
while( cur->step()){ | ||
cout <<" "<< cur->get_int(0) << " " << cur->get_text(1) << " " << cur->get_int(2)<<endl; | ||
} | ||
} | ||
|
||
int showModules(){ | ||
sqlite::sqlite db("4007database.db"); | ||
|
||
auto cur = db.get_statement(); | ||
cur->set_sql( "SELECT * FROM ModuleTable" ); | ||
cur->prepare(); | ||
|
||
while( cur->step()){ | ||
cout <<" "<< cur->get_int(0) << " " << cur->get_text(1) <<endl; | ||
} | ||
} | ||
|
256
libsqlite.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,256 @@ | ||
/** | ||
* Copyrights: | ||
* Netlogic Belgium: | ||
* Ruben De Smet | ||
* | ||
* this file is licensed under the terms stated in the LICENCE file | ||
* | ||
*/ | ||
#include <iostream> | ||
#include <sqlite3.h> | ||
#include <string> | ||
#include <vector> | ||
#include <exception> | ||
#include <memory> | ||
|
||
#ifndef SQLITEPP | ||
#define SQLITEPP | ||
|
||
namespace sqlite | ||
{ | ||
class sqlite; | ||
class statement; | ||
typedef std::shared_ptr<statement> statement_ptr; | ||
typedef std::shared_ptr<sqlite> sqlite_ptr; | ||
|
||
class exception : public std::exception | ||
{ | ||
friend statement; | ||
friend sqlite; | ||
public: | ||
exception(std::string msg) | ||
{ | ||
this->_msg = msg; | ||
} | ||
std::string what() | ||
{ | ||
return "Sqlite error: " + this->_msg; | ||
} | ||
private: | ||
void _set_errorno(int err) | ||
{ | ||
} | ||
std::string _msg; | ||
}; | ||
|
||
class statement | ||
{ | ||
friend sqlite; | ||
friend exception; | ||
public: | ||
void set_sql(std::string sql) | ||
{ | ||
if(this->_prepared) | ||
{ | ||
exception e("Can not set sql on prepared query."); | ||
throw e; | ||
} | ||
else | ||
{ | ||
this->_sql = sql; | ||
} | ||
} | ||
void prepare() | ||
{ | ||
this->_prepared = true; | ||
const char* tail; | ||
int rc = sqlite3_prepare_v2(this->_db, | ||
this->_sql.c_str(), | ||
this->_sql.length(), | ||
&this->_s, | ||
&tail); | ||
if(rc != SQLITE_OK) | ||
{ | ||
exception e("Could not prepare sql."); | ||
e._set_errorno(rc); | ||
throw e; | ||
} | ||
this->_tail = std::string(tail); | ||
} | ||
|
||
bool step() | ||
{ | ||
if(!this->_valid) | ||
{ | ||
exception e("Trying to step an invalid statement."); | ||
} | ||
|
||
int rc = sqlite3_step(this->_s); | ||
if(rc == SQLITE_DONE) | ||
{ | ||
this->_valid = false; | ||
return false; | ||
} | ||
if(rc == SQLITE_ROW) | ||
{ | ||
this->_has_row = true; | ||
return true; | ||
} | ||
// Ok, this means error if we get here | ||
exception e("Sqlite had an error: " + std::string(sqlite3_errmsg(this->_db))); | ||
return false; | ||
} | ||
void reset() | ||
{ | ||
int rc = sqlite3_reset(this->_s); | ||
if(rc != SQLITE_OK) | ||
{ | ||
exception e("Could not reset the virtual machine."); | ||
throw e; | ||
} | ||
this->_valid = true; | ||
this->_has_row = false; | ||
this->_prepared = false; | ||
} | ||
|
||
void exec() | ||
{ | ||
this->prepare(); | ||
this->step(); | ||
} | ||
|
||
double get_double(int fieldnumber) | ||
{ | ||
return sqlite3_column_double(this->_s, fieldnumber); | ||
} | ||
|
||
int get_int(int fieldnumber) | ||
{ | ||
return sqlite3_column_int(this->_s, fieldnumber); | ||
} | ||
|
||
std::string get_text(int fieldnumber) | ||
{ | ||
return std::string((const char*)sqlite3_column_text(this->_s, fieldnumber)); | ||
} | ||
std::string get_blob(int fieldnumber) | ||
{ | ||
return std::string((const char*)sqlite3_column_blob(this->_s, fieldnumber), | ||
sqlite3_column_bytes(this->_s, fieldnumber)); | ||
} | ||
|
||
void bind(int where, const std::string& text) | ||
{ | ||
int rc = sqlite3_bind_text(this->_s, where, text.c_str(), text.length(), SQLITE_STATIC); | ||
if(rc != SQLITE_OK) | ||
{ | ||
exception e("Could not bind text."); | ||
throw e; | ||
} | ||
} | ||
|
||
void bind(int where, const std::string&& text) | ||
{ | ||
int rc = sqlite3_bind_text(this->_s, where, text.c_str(), text.length(), SQLITE_TRANSIENT); | ||
if(rc != SQLITE_OK) | ||
{ | ||
exception e("Could not bind text."); | ||
throw e; | ||
} | ||
} | ||
|
||
void bind(int where, double d) | ||
{ | ||
int rc = sqlite3_bind_double(this->_s, where, d); | ||
if(rc != SQLITE_OK) | ||
{ | ||
exception e("Could not bind double."); | ||
throw e; | ||
} | ||
} | ||
void bind(int where, int i) | ||
{ | ||
int rc = sqlite3_bind_int(this->_s, where, i); | ||
if(rc != SQLITE_OK) | ||
{ | ||
exception e("Could not bind int."); | ||
throw e; | ||
} | ||
} | ||
void bind_null(int where) | ||
{ | ||
int rc = sqlite3_bind_null(this->_s, where); | ||
if(rc != SQLITE_OK) | ||
{ | ||
exception e("Could not bind to NULL."); | ||
throw e; | ||
} | ||
} | ||
|
||
virtual ~statement() | ||
{ | ||
sqlite3_finalize(this->_s); | ||
} | ||
private: | ||
statement(sqlite3* db) | ||
{ | ||
this->_db = db; | ||
this->_prepared = false; | ||
this->_valid = true; | ||
this->_has_row = false; | ||
} | ||
statement(sqlite3* db, std::string sql) | ||
{ | ||
this->_db = db; | ||
this->_prepared = false; | ||
this->_valid = true; | ||
this->_has_row = false; | ||
this->set_sql(sql); | ||
} | ||
sqlite3* _db; | ||
bool _prepared, _valid, _has_row; | ||
std::string _sql; | ||
std::string _tail; | ||
sqlite3_stmt* _s; | ||
}; | ||
|
||
class sqlite | ||
{ | ||
friend statement; | ||
public: | ||
sqlite(std::string filename) throw (exception) | ||
{ | ||
this->_filename = filename; | ||
int rc = sqlite3_open(filename.c_str(), &this->_db); | ||
if(rc != SQLITE_OK) | ||
{ | ||
exception e("Could not open '" + filename + "'"); | ||
throw e; | ||
} | ||
} | ||
std::shared_ptr<statement> get_statement() | ||
{ | ||
statement_ptr st(new statement(this->_db)); | ||
return st; | ||
} | ||
statement_ptr get_statement(std::string sql) | ||
{ | ||
statement_ptr st(new statement(this->_db, sql)); | ||
return st; | ||
} | ||
int64_t last_insert_id() | ||
{ | ||
return sqlite3_last_insert_rowid(this->_db); | ||
} | ||
virtual ~sqlite() | ||
{ | ||
sqlite3_close(this->_db); | ||
} | ||
private: | ||
std::string _filename; | ||
|
||
sqlite3* _db; | ||
}; | ||
} | ||
|
||
#endif |
35
menu.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <iostream> | ||
#include "functions.h" | ||
using namespace std; | ||
|
||
int main(){ | ||
|
||
cout << "Computer Science SECOND YEAR timetable database system." << endl; | ||
|
||
|
||
int menuChoice=0; | ||
while(true){ | ||
cout<< " Choose the number for option of choice---1.Modules 2. Students 3.Lecturers 4.Rooms and Modules 5.Class : "<<endl; | ||
cin >> menuChoice; | ||
if (menuChoice==1){ | ||
showModules(); | ||
|
||
} | ||
else if (menuChoice=2){ | ||
showStudents(); | ||
} | ||
else if (menuChoice=3){ | ||
showLecturers(); | ||
} | ||
|
||
|
||
|
||
else if (menuChoice==4){ | ||
|
||
} | ||
else if (menuChoice==5){ | ||
|
||
} | ||
} | ||
|
||
} |