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
/* Database using SQLite 3*/
#include <iostream>
#include <stdio.h>
#include <sqlite3.h>
using namespace std;
static int createDB (const char* directoryString);
static int createTable(const char* directoryString);
int main()
{ //"C:\gameDatabase"
const char* dirString = " c:\\gameDatabase\\PlayerDetails.db";
sqlite3* gameDB;
createDB(dirString);
createTable(dirString);
return 0;
}
static int createDB(const char* dString) //going to be using sqlite db
{
sqlite3* gameDB;
int exit = 0;
exit = sqlite3_open(dString, &gameDB); //going to use the exit as an int return
/*This is going to take the directory string("directoryString")
and
try to open the database called ("DB")
if the database doesn't exist, sqlite it will create it!
it will try to find playerDetails and doesnt see it and creates it. */
sqlite3_close(gameDB);
return 0;
}
static int createTable(const char* dString)
{
sqlite3* DB;
string sql = "CREATE TABLE PlayerDetails ("
"ID INTEGER PRIMARY KEY AUTOINCREMENT"
"NAME TEXT NOT NULL, "
"SURNAME TEXT NOT NULL, "
"POKEMON TEXT NOT NULL, "
"LEVEL INT NOT NULL);";
try
{
int exit = 0;
exit = sqlite3_open(dString, &gameDB);
char* messaggeError;
exit = sqlite3_exec(gameDB, sql.c_str(), NULL, 0, &messaggeError); //CALLBACK COMMAND
if (exit != SQLITE_OK) { // THIS CALL BACK COMMAND IS USED HERE, SO IF IT DOESN'T WORK THIS WILL PASS A ERROR. IF ELSE STATEMENT FOR ERROR HANDELLING
cerr << "Error Create Table" << endl;
sqlite3_free(messaggeError);
}
else
cout << "Table created Successfully" << endl;
sqlite3_close(gameDB);
}
catch (const exception & e)
{
cerr << e.what();
}
return 0;
}