This repository has been archived by the owner. It is now read-only.
Permalink
Cannot retrieve contributors at this time
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?
university-timetable/drop_all_tables.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
43 lines (38 sloc)
1.5 KB
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
#include <iostream> | |
#include <sqlite3.h> //using sqlite3 library for database integration | |
int main() | |
{ | |
sqlite3* db; | |
std::string sql = "DROP TABLE Rooms;" | |
"DROP TABLE Lecturers;" | |
"DROP TABLE Students;" | |
"DROP TABLE Modules;" | |
"DROP TABLE Classes;" | |
"DROP TABLE Class_students;"; | |
int exit = 0; | |
char* sqlErrorMessage; | |
//open connection to database | |
exit = sqlite3_open("data.db", &db); //will return 0 if succeeded | |
//check connection was successful before continuing | |
//example code taken from https://www.geeksforgeeks.org/sql-using-c-c-and-sqlite/ | |
if (exit) { | |
std::cerr << "Error opening database: " << sqlite3_errmsg(db) << std::endl; | |
return (-1); | |
} | |
else | |
std::cout << "Opened Database Successfully!" << std::endl; | |
//end of example code | |
//execute sql commands | |
//sqlite3_exec(sqlite3*, const char *sql, sqlite_callback, void *data, char **errmsg) | |
//arguments taken from https://www.geeksforgeeks.org/sql-using-c-c-and-sqlite/ | |
exit = sqlite3_exec(db, sql.c_str(), NULL, 0, &sqlErrorMessage ); | |
//report back to user if execution was successful, and if not why | |
if (exit != SQLITE_OK) { | |
std::cerr << "Some errors occured when dropping tables:" << std::endl; | |
std::cerr << sqlErrorMessage << std::endl; | |
} | |
else | |
std::cout << "Tables dropped successfully." << std::endl; | |
sqlite3_close(db); //close connection to the database once finished | |
return (0); | |
} |