forked from BuddhistBuck/GreenTeamPROJECT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmimirNBAcrappy.txt
641 lines (483 loc) · 15.2 KB
/
mimirNBAcrappy.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
//Program: menu for NBACONFERENCES.bitand
//author: Brian Chamberlain
//last update: 12.04.2021
//goal: main menu to search and insert into NBACONFERENCES.bd
// at least have options for viewing the teams in a division; (You can provide
//menu options that allow the user to choose the division). Adding a new team;
//Adding a player; Viewing the roster for a team; Viewing game information;
//Adding game information.
/*
void rollback(sqlite3* db)
{
std::string query = "rollback;";
sqlite3_exec(db, query.c_str(), NULL, NULL, NULL);
std::cout << "Transaction rolled back..." << std::endl;
}
void commit(sqlite3* db)
{
std::string query = "commit;";
char * err;
int rc = sqlite3_exec(db, query.c_str(), NULL, NULL, &err);
if(rc != SQLITE_OK)
{
std::cout << "Error committing transaction: " << err << std::endl;
sqlite3_free(err);
rollback(db);
return;
}
std::cout << "transaction committed..." << std::endl;
}*/
#include <iostream>
#include <string>
#include <iomanip>
#include "sqlite3.h"
#include <climits>
using namespace std;
int mainMenu();
void printMainMenu();
void viewConference(sqlite3 *);
void viewCustomer(sqlite3 *);
void displayRoster(sqlite3* db);
void AddaTeam(sqlite3 *db);
void AddaPlayer(sqlite3 *db);
void AddaGame(sqlite3 *db);
void ViewaGame(sqlite3 *db);
int main() {
int choice;
sqlite3 *mydb;
int rc;
rc = sqlite3_open_v2("NBDProjectDB.db", &mydb, SQLITE_OPEN_READWRITE, NULL);
if(rc != SQLITE_OK){
//if the database cannot be opened
cout << "Error in connection: " << sqlite3_errmsg(mydb);
return 1;
}
cout << "Welcome to NBA CONFERENCES Database by ME!" << endl;
choice = mainMenu();
while (true)
{
switch (choice)
{
case 1: viewConference(mydb); break;
case 2: AddaTeam(mydb); break;//not working
case 3: displayRoster(mydb); break;
case 4: AddaPlayer(mydb); break;
case 5: AddaGame(mydb); break;
case 6: ViewaGame(mydb); break;
case -1:
{
//don't forget to close.
sqlite3_close(mydb);
return 0;
}
default: cout << "That is not a valid choice." << endl;
}
cout << "\n\n";
choice = mainMenu();
}
}
void printMainMenu()
{
cout << "Please choose an option (enter -1 to quit): " << endl;
cout << "1. View a full Conference team list" << endl;
cout << "2. Add a Team" << endl;
cout << "3. View a teams Roster" << endl;
cout << "4. Add a Player" << endl;
cout << "5. Add a Game" <<endl;
cout << "6. View a Game" <<endl;
cout << "Enter Choice: ";
}
int mainMenu()
{
int choice = 0;
printMainMenu();
cin >> choice;
while ((!cin || choice < 1 || choice > 24) && choice != -1)
{
if (!cin)
{
cin.clear();
cin.ignore(INT_MAX,'\n');
}
cout << "That is not a valid choice." << endl << endl;
printMainMenu();
cin >> choice;
}
return choice;
}
/*
SELECT TEAMS.Name, TEAMS.citystate, DIVISION.Name as Division, DIVISION.Conference
FROM TEAMS JOIN DIVISION ON TEAMS.Name = DIVISION.TeamName;*/
void viewConference(sqlite3 *db)
{ //displays teams table
int columnCount;
int choice = 0;
string conference = "NONE";
cout << "Eastern = 1 or Western = 2" << endl;
cin >>choice;
if(choice == 1){conference = "\"Eastern\"";}
else if (choice == 2){conference = "\"Western\"";}
//else{cin.clear();cin.ignore(INT_MAX,'\n');
// cout << "That is not a valid choice." << endl << endl;
// viewInvoice(db);
// cin >> choice;
// }
string query = "SELECT TEAMS.Name as Team, TEAMS.citystate, DIVISION.Name as Division, DIVISION.Conference ";
query += "FROM TEAMS JOIN DIVISION ON TEAMS.Name = DIVISION.TeamName ";
query += "WHERE DIVISION.Conference = ";
query += conference + ";";
sqlite3_stmt *pRes, *pRes2;
string m_strLastError;
string query2;
string TeamName;//teamname
string citystate, playerNum, PlayerName, GameCount;//
string division;
if (sqlite3_prepare_v2(db, query.c_str(), -1, &pRes, NULL) != SQLITE_OK)
{
m_strLastError = sqlite3_errmsg(db);
sqlite3_finalize(pRes);
cout << "There was an error: viewinvoice " << m_strLastError << endl;
return;
}
else {
int i = 1;
cout << left;
while (sqlite3_step(pRes) == SQLITE_ROW)
{
cout << i << ". " << sqlite3_column_text(pRes, 0);
cout << endl;
i++;
}}
}
//end viewInvoicefunction
void displayRoster(sqlite3 *db){
// viewConference(db);
//displays teams table
int columnCount;
int choice = 0;
string conference = "NONE";
cout << "Eastern = 1 or Western = 2 : " ;
cin.clear();
cin.ignore(INT_MAX, '\n');
cin >>choice;
if(choice == 1){conference = "\"Eastern\"";}
else if (choice == 2){conference = "\"Western\"";}
//else{cin.clear();cin.ignore(INT_MAX,'\n');
// cout << "That is not a valid choice." << endl << endl;
// viewInvoice(db);
// cin >> choice;
// }
string query = "SELECT TEAMS.Name as Team, TEAMS.citystate, DIVISION.Name as Division, DIVISION.Conference ";
query += "FROM TEAMS JOIN DIVISION ON TEAMS.Name = DIVISION.TeamName ";
query += "WHERE DIVISION.Conference = ";
query += conference + ";";
sqlite3_stmt *pRes, *pRes2, *pRes3;
string m_strLastError;
string query2;
string TeamName;//teamname
string citystate, playerNum, PlayerName, GameCount;//
string division;
int i = 1;
if (sqlite3_prepare_v2(db, query.c_str(), -1, &pRes, NULL) != SQLITE_OK)
{
m_strLastError = sqlite3_errmsg(db);
sqlite3_finalize(pRes);
cout << "There was an error: viewrostinvoice " << m_strLastError << endl;
return;
}
else {
cout << left;
while (sqlite3_step(pRes) == SQLITE_ROW)
{
cout << i << ". " << sqlite3_column_text(pRes, 0);
cout << endl;
i++;
// cout << TeamName;
}
}
columnCount = sqlite3_column_count(pRes);
cout << "Please choose the Team you want to see: ";
//cin.clear();cin.ignore(INT_MAX, '\n');
// cin >> choice;
cout << left;
while(!(cin>>choice) || choice < 1 || choice > (i - 1)){
if(!cin){
cin.clear();
cin.ignore(INT_MAX, '\n');
}
cout << "That is not a valid choice! Try again6!" << endl;
}
sqlite3_reset(pRes);
for (int i = 0; i < choice; i++)
sqlite3_step(pRes);
TeamName = reinterpret_cast<const char*>(sqlite3_column_text(pRes,0));
query = "SELECT * FROM PLAYER JOIN TEAMS ON TEAMS.Name";
query+= " = ";
query+= "PLAYER.Team ";
query += "WHERE TEAMS.Name = \'";
query += TeamName;
query += "\' ;";
cout << query<<endl;
sqlite3_reset(pRes);
if (sqlite3_prepare_v2(db, query.c_str(), -1, &pRes, NULL) != SQLITE_OK)
{
m_strLastError = sqlite3_errmsg(db);
sqlite3_finalize(pRes);
cout << "There was an error: viewiteam " << m_strLastError << endl;
return;
}
else {
int i = 1;
cout << left;
cout << TeamName<<endl;
while (sqlite3_step(pRes) == SQLITE_ROW )
// for(int i =0; i<3; i++)
{ cout << i <<". ";
cout << "#"<< sqlite3_column_text(pRes, 1);
cout << " " << sqlite3_column_text(pRes, 0);
cout << endl;
i++;
}
}
}
void AddaTeam(sqlite3 *db){
int CoachID, GameCount;
sqlite3_stmt *pRes, *pRes2, *pRes3;
string m_strLastError;
string query2;
string TeamName;//teamname
string city, state, citystate, arena, mascot;//
string division;
string conference = "NONE";
cout << "Eastern = 1 or Western = 2 : " ;
cin.clear();
cin.ignore(INT_MAX, '\n');
int choice = 0;
cin >>choice;
if(choice == 1){conference = "\"Eastern\"";}
else if (choice == 2){conference = "\"Western\"";}
cout << "Insert Division:";
cin >> division;
cout<< "Insert team name: ";
cin>>TeamName;
//query2 = "Insert into TEAMS values (";
// query2 += TeamName.c_str();
// query2= ", ";
cout << "\nInsert CoachID (must exist(1-7), is an INTEGER): ";
cin>>CoachID;
while(!cin){cout<<"Please enter and integer: "<<endl; cin.clear();cin.ignore(INT_MAX,'\n'); cin>>CoachID;}
// query2 += to_string( CoachID);
// query2= ", ";
cout << "\nInsert City: ";
cin >> city;
cout << "and State: ";\
cin >> state;
//build citystate
citystate = city;
citystate+= " ";
citystate+= state;
cout << "\nInsert arena name: ";
cin >> arena;
cout << "\nInsert Mascot name: ";
cin >> mascot;
cout << "\nInsert Game Count(must be INTEGER): ";
cin>> GameCount;
while(!cin){cout<<"Please enter and integer: "<<endl; cin.clear();cin.ignore(INT_MAX,'\n'); cin>>GameCount;}
// cout <<query2<<endl;
//Insert into TEAMS values("TeamName",'CoachID',"citystate","arena",'gamecount')
query2 = "Insert into TEAMS values(\"";
query2+= TeamName;
query2 += "\"";
query2 += ",\'";
query2 += to_string(CoachID);
query2+= "\',\"";
query2+= citystate;
query2+= "\",\"";
query2+= arena;
query2+="\",\"";
query2+= mascot;
query2+="\",\'";
query2+= to_string(GameCount);
query2+= "\');";
query2 = "Insert into DIVISION values(";
query2+= conference;
// query2 += "\"";
query2 += ",\"";
query2 += division;
query2+= "\",\"";
query2+= TeamName;
query2+= "\");";
//cout<<"'TEMCOACH:"<<query2<<endl;
if (sqlite3_prepare_v2(db, query2.c_str(), -1, &pRes2, NULL) != SQLITE_OK)
{
m_strLastError = sqlite3_errmsg(db);
sqlite3_finalize(pRes2);
cout << "There was an error: insertteam" << m_strLastError << endl;
return;
}
else
{
cout << "Inserted: "<< TeamName << " Team" <<endl;
}
}
void AddaPlayer(sqlite3 *db){
int CoachID, GameCount;
sqlite3_stmt *pRes, *pRes2, *pRes3;
string m_strLastError;
string query2;
string TeamName;//teamname
string city, state, citystate, arena, mascot;//
string division;
cout<< "Insert team name: ";
cin>>TeamName;
//query2 = "Insert into TEAMS values (";
// query2 += TeamName.c_str();
// query2= ", ";
cout << "\nInsert Player #: (is an INTEGER): ";
cin>> CoachID;
while(!cin){cout<<"Please enter and integer: "<<endl; cin.clear();cin.ignore(INT_MAX,'\n'); cin>>CoachID;}
// query2 += to_string( CoachID);
// query2= ", ";
cout << "\nInsert First Name";
cin >> city;
cout << "and Last Name: ";\
cin >> state;
//build citystate
citystate = city;
citystate+= " ";
citystate+= state;
//Insert into TEAMS values("TeamName",'CoachID',"citystate","arena",'gamecount')
query2 = "Insert into PLAYER values(\"";
query2+= citystate;
query2 += "\"";
query2 += ",\'";
query2 += to_string(CoachID);
query2+= "\',\"";
query2+= TeamName;
query2+= "\"";
query2+= ");";
//cout<<"'TEMCOACH:"<<query2<<endl;
if (sqlite3_prepare_v2(db, query2.c_str(), -1, &pRes2, NULL) != SQLITE_OK)
{
m_strLastError = sqlite3_errmsg(db);
sqlite3_finalize(pRes2);
cout << "There was an error: " << m_strLastError << endl;
return;
}
else
{
cout << "Inserted: "<< TeamName << citystate<< to_string(CoachID)<<endl;
}
}
void AddaGame(sqlite3 *db){
int CoachID, GameCount;
sqlite3_stmt *pRes, *pRes2, *pRes3;
string m_strLastError;
string query2;
string TeamName;//teamname
string city, state, citystate, arena, mascot;//
string division;
cout<< "Insert Home team name: ";
cin>>TeamName;//acts as home team name temp
cout<< "Insert Away team name: ";
cin>>mascot;//acts as away team name temp
//query2 = "Insert into TEAMS values (";
// query2 += TeamName.c_str();
// query2= ", ";
cout << "\nInsert Date (in form mm-dd-yyy): ";
cin>> arena;//acts as date temp
cout << "\nInsert Final Score: ";
cin>> citystate;//acts as score temp
cout << " insert Arena Played: ";
cin >> state;//acts as arena temp
//use more direct insert(below) so primary key autoincrements, remove or apply teamsTEAMS alias
//insert into TEAMS(soulumn_name,col_nam,col_int) values ("Brian", "Chamber", '3')
//Insert into TEAMS values("TeamName",'CoachID',"citystate","arena",'gamecount')
query2 = "Insert into GAME values(\'";
query2 += "999\',\"";//hard coded cus i dunno how to check last row #
query2+= arena;
query2+= "\",\"";
query2+= citystate;
query2 += "\"";
query2 += ",\"";
query2 += TeamName;
query2+= "\",\"";
query2+= mascot;
query2+= "\",\"";
query2+= state;
query2+=" \"";
query2+= ");";
cout<<"'TEMCOACH:"<<query2<<endl;
if (sqlite3_prepare_v2(db, query2.c_str(), -1, &pRes2, NULL) != SQLITE_OK)
{
m_strLastError = sqlite3_errmsg(db);
sqlite3_finalize(pRes2);
cout << "There was an error: " << m_strLastError << endl;
return;
}
else
{
cout << "Inserted: "<< TeamName << citystate<< to_string(CoachID)<<endl;
}
}
void ViewaGame(sqlite3 *db){
sqlite3_stmt *pRes, *pRes2, *pRes3;
string m_strLastError;
string query2;
string TeamName;//teamname
string city, state, citystate, arena, mascot;//
string division;
int choice;
string query = "SELECT * FROM GAME; ";
//cout << query<<endl;
if (sqlite3_prepare_v2(db, query.c_str(), -1, &pRes, NULL) != SQLITE_OK)
{
m_strLastError = sqlite3_errmsg(db);
sqlite3_finalize(pRes);
cout << "There was an error: viewgame " << m_strLastError << endl;
return;
}
else {
int i = 1;
cout << left;
while (sqlite3_step(pRes) == SQLITE_ROW)
{ cout << "ID: " << (sqlite3_column_text(pRes,0));
cout << " Date: " << (sqlite3_column_text(pRes,1));
cout << " Finale Score: " << (sqlite3_column_text(pRes,2));
cout << "\n Home Team: " << (sqlite3_column_text(pRes,3));
cout << " Away Team:" << (sqlite3_column_text(pRes,4));
cout << " Arena: " << (sqlite3_column_text(pRes,5));
cout << endl;
i++;
}}
//end display games
cout << "\nSelect a game"<<endl;
cin >> query2;
query = "SELECT * FROM GAME ";
query += "WHERE GameID = \'";
query += query2;
query += "\' ;";
// cout << query<<endl;
// cout << "Select a game"<<endl;
// cin >> query2;
if (sqlite3_prepare_v2(db, query.c_str(), -1, &pRes, NULL) != SQLITE_OK)
{
m_strLastError = sqlite3_errmsg(db);
sqlite3_finalize(pRes);
cout << "There was an error: viewgame " << m_strLastError << endl;
return;
}
else {
int i = 1;
cout << left;
while (sqlite3_step(pRes) == SQLITE_ROW)
{ cout << "ID: " << (sqlite3_column_text(pRes,0));
cout << " Date: " << (sqlite3_column_text(pRes,1));
cout << " Finale Score: " << (sqlite3_column_text(pRes,2));
cout << "\n Home Team: " << (sqlite3_column_text(pRes,3));
cout << " Away Team:" << (sqlite3_column_text(pRes,4));
cout << " Arena: " << (sqlite3_column_text(pRes,5));
cout << endl;
i++;
}}
}//end display games