-
Notifications
You must be signed in to change notification settings - Fork 153
/
Actions.h
176 lines (123 loc) · 4.9 KB
/
Actions.h
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
/************************************************************************
* Copyright(c) 2010, One Unified. All rights reserved. *
* email: info@oneunified.net *
* *
* This file is provided as is WITHOUT ANY WARRANTY *
* without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
* This software may not be used nor distributed without proper license *
* agreement. *
* *
* See the file LICENSE.txt for redistribution information. *
************************************************************************/
// LibSql/Actions.h
#pragma once
#include <string>
#include <vector>
#include "Functions.h"
namespace ou {
namespace db {
// Action_Compose
class Action_Compose {
private:
// definition of fields for table creation
struct structField {
std::string sFieldName;
structField( const std::string& sFieldName_ ): sFieldName( sFieldName_ ) {};
};
typedef std::vector<structField> vField_t;
public:
Action_Compose( void );
virtual ~Action_Compose( void );
template<typename T>
void Field( const std::string& sFieldName, const T& var ) {
addField( sFieldName );
}
template<typename T>
void Field( const std::string& sFieldName, const T& var, const std::string& sFieldType ) {
addField( sFieldName );
}
// inheritor will likely need something like:
// void ComposeStatement( const std::string& sTableName, std::string& sStatement );
// void ComposeStatement( std::string& sStatement );
vField_t::size_type FieldCount( void ) { return m_vField.size(); };
protected:
typedef vField_t::iterator vField_iter_t;
vField_t m_vField;
void addField( const std::string& sFieldName );
private:
};
// Action_Compose_CreateTable
class Action_Assemble_TableDef: public Action_Compose {
public:
Action_Assemble_TableDef( const std::string& sTableName );
~Action_Assemble_TableDef( void );
// template<typename T> // located in inheritor
// void Field( const std::string& sFieldName, T& var ) { };
// template<typename T> // located in inheritor
// void Field( const std::string& sFieldName, T& var, const std::string& sFieldType ) { };
void Key( const std::string& sLocalField );
void Constraint( const std::string& sLocalField, const std::string& sRemoteTable, const std::string& sRemoteField );
void ComposeCreateStatement( std::string& sStatement );
protected:
// called by inheritor
void addField( const std::string& sField, const char* szDbFieldType );
// definition of fields for table creation
struct structFieldDef {
std::string sFieldName;
std::string sFieldType;
bool bIsKeyPart;
structFieldDef( void ): bIsKeyPart( false ) {};
structFieldDef(const std::string& sFieldName_, const std::string& sFieldType_ )
: sFieldName( sFieldName_ ), sFieldType( sFieldType_ ), bIsKeyPart( false ) {};
};
typedef std::vector<structFieldDef> vFieldDef_t;
typedef vFieldDef_t::iterator vFieldDef_iter_t;
vFieldDef_t m_vFieldDef;
unsigned int m_cntKeys;
struct structConstraint {
std::string sLocalField;
std::string sRemoteTable;
std::string sRemoteField;
structConstraint( const std::string& sLocalField_, const std::string& sRemoteTable_, const std::string& sRemoteField_ ):
sLocalField( sLocalField_ ), sRemoteTable( sRemoteTable_ ), sRemoteField( sRemoteField_ ) {};
};
typedef std::vector<structConstraint> vConstraints_t;
typedef vConstraints_t::iterator vConstraints_iter_t;
vConstraints_t m_vConstraints;
std::string m_sTableName;
private:
};
// Action_Compose_Insert
class Action_Compose_Insert: public Action_Compose {
public:
Action_Compose_Insert( const std::string& sTableName );
~Action_Compose_Insert( void );
void ComposeStatement( std::string& sStatement );
protected:
private:
std::string m_sTableName;
};
// Action_Compose_Update
class Action_Compose_Update: public Action_Compose {
public:
Action_Compose_Update( const std::string& sTableName );
~Action_Compose_Update( void );
void ComposeStatement( std::string& sStatement );
protected:
private:
std::string m_sTableName;
};
// Action_Compose_Delete
class Action_Compose_Delete: public Action_Compose {
public:
Action_Compose_Delete( const std::string& sTableName );
~Action_Compose_Delete( void );
void ComposeStatement( std::string& sStatement );
protected:
private:
std::string m_sTableName;
};
} // db
} // ou