Skip to content
Permalink
6fe9f288d6
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
67 lines (54 sloc) 1.53 KB
//
// Database.cpp
// BasketBallGame
//
// Created by Suraj Mann on 05/03/2020.
// Copyright © 2020 Suraj Mann. All rights reserved.
//
#include "Database.h"
#include <iostream>
#include "libsqlite.hpp"
using namespace std;
// Calling database class
Database::Database()
{
}
// function for displaying user information - Suraj
void Database::database_queries()
{
//open database
sqlite::sqlite db("BasketBallGame");
auto cur = db.get_statement();
cur->set_sql("SELECT * FROM USERS;");
cur->prepare();
while( cur->step() ) // loop over results
cout << cur->get_int(0) << " " << cur->get_text(1) << endl;
}
// function for writing player information to database - Suraj
void Database::add_players_db()
{
try
{
//open database
sqlite::sqlite db("basketDatabase");
int shooting, dribbling, guarding, stamina, acceleration, height;
auto cur = db.get_statement();
cur->set_sql( "INSERT INTO USERPLAYERS (name, shooting, dribbling, guarding, stamina, acceleration, height) "
"VALUES (?, ?, ?, ?, ?, ?, ?);" );
cur->prepare();
cur->bind( 1, name );
cur->bind( 2, shooting );
cur->bind( 3, dribbling );
cur->bind( 4, guarding );
cur->bind( 5, stamina );
cur->bind( 6, acceleration );
cur->bind( 7, height );
cur->step();
}
catch( sqlite::exception e )
{
cerr << e.what() << endl;
return 1;
}
return 0;
}