Skip to content
Permalink
Browse files
Add files via upload
  • Loading branch information
dhangarj committed Mar 20, 2020
1 parent 6fe9f28 commit f7573989892f59fb74a906f14a819ebb1fc2608f
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 0 deletions.
@@ -0,0 +1,69 @@
#include <iostream>
#include <string>
#include <sqlite3.h>
#include <stdio.h>

using namespace std;

//create a callback function
int callback(void* NotUsed, int argc, char** argv, char** azColName) {
// holds the number of results
// holds each value
// holds each column returned

for (int i = 0; i < argc; i++) {

//show column name, value, and newline
cout << azColName[i] << ": " << argv[i] << endl;

}
return 0;
}

int main() {

//Pointer
sqlite3* db;

//Save any error messages
char* ErrMsg;

int works;
string qry;
run= sqlite3_open("Teams.db", &db);

if (works){
cout << "DB Error: " << sqlite3_errmsg(db) << endl;
sqlite3_close(db);
return(1);
}

qry = "CREATE TABLE IF NOT EXISTS Team1(" \
"ID INT PRIMARY KEY NOT NULL," \
"FirstName TEXT NOT NULL," \
"LastName TEXT NOT NULL," \
"Shooting INT NOT NULL," \
"Dribbling INT NOT NULL," \
"Defence INT NOT NULL);";

works= sqlite3_exec(db, qry.c_str(), NULL, 0, &ErrMsg);
qry = "INSERT INTO Team1 ('ID','FirstName','LastName','Shooting', 'Dribbling', 'Defence') VALUES (1,'John','Smith',57,72,34);";
works = sqlite3_exec(db, qry.c_str(), NULL, 0, &ErrMsg);
qry = "INSERT INTO Team1 ('ID','FirstName','LastName','Shooting', 'Dribbling', 'Defence') VALUES (2,'Jim','Brown',87,77,89);";
works = sqlite3_exec(db, qry.c_str(), NULL, 0, &ErrMsg);
qry = "INSERT INTO Team1 ('ID','FirstName','LastName','Shooting', 'Dribbling', 'Defence') VALUES (3,'Sam','Brown',57,49,61);";
works = sqlite3_exec(db, qry.c_str(), NULL, 0, &ErrMsg);
qry = "INSERT INTO Team1 ('ID','FirstName','LastName','Shooting', 'Dribbling', 'Defence') VALUES (4,'Antonio','Kane',78,33,84);";
works = sqlite3_exec(db, qry.c_str(), NULL, 0, &ErrMsg);
qry = "INSERT INTO Team1 ('ID','FirstName','LastName','Shooting', 'Dribbling', 'Defence') VALUES (5,'Jake','Mawn',86,46,85);";
works = sqlite3_exec(db, qry.c_str(), NULL, 0, &ErrMsg);

//Save SQL Insert Data
qry = "SELECT * FROM 'Team1';";
works = sqlite3_exec(db, qry.c_str(), callback, 0, &ErrMsg);

//Close the SQL Connection
sqlite3_close(db);

return 0;
}
@@ -0,0 +1,112 @@
#include <iostream>
#include <stdio.h>
#include <sqlite3.h>
#include <string>

using namespace std;

//create a callback function
int callback(void* NotUsed, int argc, char** argv, char** azColName) {
// holds the number of results
// holds each value
// holds each column returned

for (int i = 0; i < argc; i++) {

//show column name, value, and newline
cout << azColName[i] << ": " << argv[i] << endl;

}
return 0;
}

class Details {
public:
string username,password;

void DetailsIn() {
cout << "Enter Username: ";
cin >> username;
cout << "Input: " << username << endl;
cout << "Enter Password: ";
cin >> password;
cout << "Input: " << password << endl;
};

int MakeDb() {
//Pointer
sqlite3* db;
//Save any error messages
char* ErrMsg;
int run;
string sql;
run = sqlite3_open("Details.db", &db);
if (run) {
cout << "DB Error: " << sqlite3_errmsg(db) << endl;
sqlite3_close(db);
return 1;
}
sql = "CREATE TABLE IF NOT EXISTS Details(" \
"ID INT PRIMARY KEY NOT NULL," \
"Username TEXT NOT NULL," \
"Password TEXT NOT NULL);";
run = sqlite3_exec(db, sql.c_str(), callback, 0, &ErrMsg);
//Close the SQL Connection
sqlite3_close(db);
}
};

int registration() {
//Pointer
sqlite3* db;
//Save any error messages
char* ErrMsg;
int run;
string sql;
run = sqlite3_open("Details.db", &db);
if (run) {
cout << "DB Error: " << sqlite3_errmsg(db) << endl;
sqlite3_close(db);
return 1;
}
sql = "INSERT INTO Details('ID','Username','Password') VALUES (1,'?','?');";

run = sqlite3_exec(db, sql.c_str(), callback, 0, &ErrMsg);
//Close the SQL Connection
sqlite3_close(db);
}

int main() {

char choose;
Details d1;
d1.MakeDb();
do {

cout << "'R' to Register or 'L' to Login \n";
cin >> choose;

switch (choose)
{
case 'R':
d1.DetailsIn();
registration();
return 0;
case 'L':
cout << "Login";
}




}

while (choose != 0);






return 0;
}

0 comments on commit f757398

Please sign in to comment.