From f7573989892f59fb74a906f14a819ebb1fc2608f Mon Sep 17 00:00:00 2001 From: "Jatin Dhangar (dhangarj)" Date: Fri, 20 Mar 2020 18:08:44 +0000 Subject: [PATCH] Add files via upload --- Computer Teams.cpp | 69 +++++++++++++++++++++++++ Login and Register.cpp | 112 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 Computer Teams.cpp create mode 100644 Login and Register.cpp diff --git a/Computer Teams.cpp b/Computer Teams.cpp new file mode 100644 index 0000000..2e792e4 --- /dev/null +++ b/Computer Teams.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +#include + +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; +} \ No newline at end of file diff --git a/Login and Register.cpp b/Login and Register.cpp new file mode 100644 index 0000000..dbc1dba --- /dev/null +++ b/Login and Register.cpp @@ -0,0 +1,112 @@ +#include +#include +#include +#include + +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; +} \ No newline at end of file