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/Computer Teams.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
69 lines (54 sloc)
2.12 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
#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; | |
} |