Skip to content
This repository has been archived by the owner. It is now read-only.
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 <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);
}