Permalink
Cannot retrieve contributors at this time
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?
4007CEM/Database.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
67 lines (54 sloc)
1.53 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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; | |
} | |