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
#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;
}