GlistEngine
Loading...
Searching...
No Matches
gDatabase.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 Nitra Games Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef UTILS_GDATABASE_H_
18#define UTILS_GDATABASE_H_
19
20#include <queue>
21#include "sqlite3.h"
22#include "gObject.h"
23
24
25class gDatabase: public gObject {
26public:
28 virtual ~gDatabase();
29
30 bool load(std::string fullPath);
31 bool loadDatabase(std::string databasePath);
32 void close();
33
34 std::string getPath();
35
36 void execute(std::string statement, std::string id = "0");
37 static int callback(void *statementId, int argc, char **argv, char **azColName);
38
39 std::string getSelectData();
42
43 /*
44 * Recieves all table infos from a database
45 *
46 * By sending variable pointers this method will give you all table infos from a database.
47 *
48 * @return since you sending pointer as input, it will modify and alter variables with results so you can directly use same variable.
49 */
50 void getTableInfo(char*** sqlResult, int* rowNum, int* colNum);
51
52 void setDelimiter(std::string delimiter);
53 std::string getDelimiter();
54
55 /*
56 * Receives table names from database
57 *
58 * This metod give you table lists in a database.
59 *
60 * Using sql query for execute() metod and getting table list as result
61 *
62 * @param data which table to get info so metod will get full column list
63 * @param datastorage selecting column to recieve which type of this column name
64 * @param temporarystring storing table names which metod finds
65 * @param data returning tablenames info as vector
66 *
67 * @return resultstring return back column type of columnName
68 */
69 std::vector<std::string> getTableNames();
70
71 /* Gives all column names from table info
72 *
73 * Receives column names from @tableName after database loaded.
74 *
75 * After load database and give table name as input metod store all column names of that table
76 *
77 * @return sending back colunm name list as string vector
78 */
79 std::vector<std::string> getColumnNames(std::string tableName);
80
81 /*
82 * Receives columnType from given colunmName and tableName
83 *
84 * This metod give you column type from senden table name and column name.
85 *
86 * @param tableName which table to get info so metod will get full column list
87 * @param columnName selecting column to recieve which type of this column name
88 *
89 * @return resultstring return back column type of columnName
90 */
91 std::string getColumnType(std::string tableName, std::string columnName);
92private:
93 sqlite3* db;
94 std::string fullpath;
95 static int num;
96 static std::queue<std::string> selectdata;
97 static std::string delimiter;
98 //parameters of
99 std::string zsql;
100 int rows;
101 int cols;
102 char **result;
103 int kt;
104 int pipecounter = 0;
105 std::string** resultstring;
106 std::vector<std::string> columnList;
107};
108
109#endif /* UTILS_GDATABASE_H_ */
Definition gDatabase.h:25
bool load(std::string fullPath)
std::vector< std::string > getTableNames()
std::string getColumnType(std::string tableName, std::string columnName)
std::vector< std::string > getColumnNames(std::string tableName)
bool loadDatabase(std::string databasePath)
void getTableInfo(char ***sqlResult, int *rowNum, int *colNum)
static int callback(void *statementId, int argc, char **argv, char **azColName)
std::string getDelimiter()
std::string getSelectData()
void execute(std::string statement, std::string id="0")
int getSelectDataNum()
bool hasSelectData()
std::string getPath()
virtual ~gDatabase()
void setDelimiter(std::string delimiter)
void close()
Definition gObject.h:33