-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.hpp
More file actions
91 lines (67 loc) · 2 KB
/
utils.hpp
File metadata and controls
91 lines (67 loc) · 2 KB
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
#ifndef __UTILS_HPP__
#define __UTILS_HPP__
#include <cstdlib>
#include <vector>
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <pqxx/pqxx>
using std::vector;
using std::string;
#define PLAYER "\"PLAYER\""
#define TEAM "\"TEAM\""
#define STATE "\"STATE\""
#define COLOR "\"COLOR\""
using namespace std;
using namespace pqxx;
int last_playerID;
int last_teamID;
int last_stateID;
int last_colorID;
/**
* Initializes table attributes
*/
vector<pair<string, string> > getPlayerAttributes();
vector<pair<string, string> > getTeamAttributes();
vector<pair<string, string> > getStateAttributes();
vector<pair<string, string> > getColorAttributes();
/**
*
* Helper Functions
*
*/
void tokenize(string & input, string & delim, vector<string> & tokens, int start_indx);
vector<string> parse(string data, string delim);
string addSingleQuotes(string input);
/*
* Parse text files into list of comma-separated value strings;
*/
vector<string> parseTexts(string filename, int & last_id);
/*
* Query Handlers
*/
//Create string of attributes from attribute vector
string getAttributeString(vector<pair<string, string> > & attr);
//Generates a query string to create a table based on the vector of attributes
//t_name: name of the table
//attributes: vector of attibute:domain pairs (first mapping must be the primary key)
string createTableQuery(string & t_name, vector<pair<string, string> > attributes);
//Generates a query string to insert a row into a table
//params:
//t_name: name of table to insert into
//attributes: vector of attibute:domain pairs
//values: string of value items to insert into table
string insertRowQuery(string & t_name,
vector<pair<string, string> > & attributes, string & values);
/*
* Create DB tables
*/
void createDBTables(connection & db_conn);
void initDBTable(connection & db_conn, string file_name, string t_name);
void initAllTables(connection & db_conn);
/*
* Drop all database tables
*/
void cleanupDB(connection & db_conn);
#endif