1 #ifndef BZS_DB_PROTOCOL_TDAP_CLIENT_SERIALIZEER_H
2 #define BZS_DB_PROTOCOL_TDAP_CLIENT_SERIALIZEER_H
21 #include <bzs/db/protocol/tdap/client/activeTable.h>
25 #define DLLLIBSTMT AGRPACK
28 #define DLLLIBSTMT AGRPACK
30 #define DLLLIBSTMT // PACKAGE_IMPORT
32 #endif // LIB_TDCLSTMT
34 #if (defined(TRDCL_AUTOLINK) && !defined(LIB_TDCLSTMT))
35 #include "trdclcppautolink.h"
36 #define TD_STMT_LIB_NAME \
37 LIB_PREFIX "tdclstmt" CPP_INTERFACE_VERSTR SHARED_LIB_EXTENTION
38 #pragma comment(lib, TD_STMT_LIB_NAME)
39 #endif // TRDCL_AUTOLINK
52 #define ID_READ_STMT 0
53 #define ID_READHASMANY_STMT 1
54 #define ID_GROUPBY_STMT 2
55 #define ID_ORDERBY_STMT 3
56 #define ID_REVORDER_STMT 4
57 #define ID_MATCHBY_STMT 5
60 class DLLLIBSTMT executable
62 friend struct queryStatementsImple;
65 executable() : m_enabled(true){}
66 virtual ~executable(){};
67 virtual void execute(recordset& rs) = 0;
69 void setEnabled(
bool v) { m_enabled = v; }
70 bool isEnabled()
const {
return m_enabled; }
71 virtual const int typeID()
const = 0;
74 class DLLLIBSTMT groupByStatement :
public fieldNames,
public executable
76 struct queryStatementsImple* m_parent;
77 friend class queryStatements;
78 friend struct queryStatementsImple;
79 std::vector<groupFuncBase*>* m_statements;
81 template <
class Archive>
82 friend void serialize(Archive& ar, groupByStatement& q,
83 const unsigned int version);
84 groupByStatement(
const groupByStatement& r);
85 groupByStatement& operator=(
const groupByStatement& r);
101 groupFuncBase& addFunction(eFunc v,
const fieldNames& targetNames,
102 const _TCHAR* resultName = NULL);
103 groupFuncBase&
function(
int index);
104 groupByStatement& reset();
106 void execute(recordset& rs);
107 const int typeID()
const {
return ID_GROUPBY_STMT; };
108 static groupByStatement* create();
111 #define MAX_FUNCTION_SIZE (int) groupByStatement::flast + 1
113 class DLLLIBSTMT matchByStatement :
public recordsetQuery,
public executable
115 struct queryStatementsImple* m_parent;
116 friend class queryStatements;
117 friend struct queryStatementsImple;
120 void execute(recordset& rs);
121 static matchByStatement* create();
122 const int typeID()
const {
return ID_MATCHBY_STMT; };
125 class DLLLIBSTMT orderByStatement :
public executable
127 sortFields* m_sortFields;
128 template <
class Archive>
129 friend void serialize(Archive& ar, orderByStatement& q,
130 const unsigned int version);
131 orderByStatement(
const orderByStatement& r);
132 orderByStatement& operator=(
const orderByStatement& r);
136 void execute(recordset& rs);
137 void add(
const _TCHAR* name,
bool asc =
true);
138 orderByStatement& reset();
140 const sortField&
get(
int index)
const;
141 const int typeID()
const {
return ID_ORDERBY_STMT; };
142 static orderByStatement* create();
145 class DLLLIBSTMT reverseOrderStatement :
public executable
151 void execute(recordset& rs);
152 const int typeID()
const {
return ID_REVORDER_STMT; };
153 static reverseOrderStatement* create();
156 class DLLLIBSTMT readStatement :
public fieldValues,
160 friend struct queryStatementsImple;
161 friend class queryStatements;
163 struct queryStatementImple* m_impl;
164 queryStatementImple* internalPtr()
const;
165 template <
class Archive>
166 friend void serialize(Archive& ar, readStatement& q,
167 const unsigned int version);
168 readStatement(
const readStatement& r);
169 readStatement& operator=(
const readStatement& r);
180 int getIndex()
const;
181 readStatement& index(
int v);
182 int getOption()
const;
183 readStatement& option(
int v);
184 const _TCHAR* getDatabaseUri()
const;
185 readStatement& databaseUri(
const _TCHAR* v);
186 const _TCHAR* getTableName()
const;
187 readStatement& tableName(
const _TCHAR* v);
188 eReadType getReadType()
const;
189 readStatement& readType(eReadType v);
190 readStatement& alias(
const _TCHAR* src,
const _TCHAR* dst);
191 readStatement& reset();
192 int aliasCount()
const;
193 const _TCHAR* getAliasFirst(
int index)
const;
194 const _TCHAR* getAliasSecond(
int index)
const;
196 void execute(recordset& rs);
197 const int typeID()
const {
return ID_READ_STMT; };
198 static readStatement* create();
201 typedef std::vector<boost::shared_ptr<recordset> > recordsets;
203 class DLLLIBSTMT readHasMany :
public readStatement
205 struct readHasManyImple* m_readHasManyImpl;
206 readHasManyImple* internalPtr()
const;
207 template <
class Archive>
208 friend void serialize(Archive& ar, readHasMany& q,
209 const unsigned int version);
210 readHasMany(
const readHasMany& r);
211 readHasMany& operator=(
const readHasMany& r);
215 client::recordsets& recordsets();
216 void addkeyValueColumn(
const _TCHAR* name);
217 const _TCHAR* getkeyValueColumn(
int index)
const;
218 int keyValueColumns()
const;
219 readHasMany& reset();
220 void execute(recordset& rs);
221 const int typeID()
const {
return ID_READHASMANY_STMT; };
222 static readHasMany* create();
228 virtual void onExecuted(
const executable* e,
const recordset& rs) = 0;
231 class DLLLIBSTMT queryStatements
233 struct queryStatementsImple* m_impl;
234 queryStatementsImple* internalPtr()
const;
235 template <
class Archive>
236 friend void serialize(Archive& ar, queryStatements& q,
237 const unsigned int version);
238 queryStatements(
const queryStatements& r);
239 queryStatements& operator=(
const queryStatements& r);
240 void* getPtr(
const executable* e)
const;
243 queryStatements(idatabaseManager& dbm);
244 queryStatements(database* db);
247 queryStatements& id(
int v);
248 const _TCHAR* getTitle()
const;
249 queryStatements& title(
const _TCHAR* v);
250 const _TCHAR* getDescription()
const;
251 queryStatements& description(
const _TCHAR* v);
252 executable*
get(
int index);
255 readStatement* addRead(readStatement::eReadType type);
256 readHasMany* addHasManyRead();
257 groupByStatement* addGroupBy();
258 orderByStatement* addOrderBy();
259 matchByStatement* addMatchBy();
260 reverseOrderStatement* addReverseOrder();
261 int statementType(
int index);
263 readStatement* getReadStatement(executable* e);
264 readHasMany* getReadHasMany(executable* e);
265 groupByStatement* getGroupByStatement(executable* e);
266 orderByStatement* getOrderByStatement(executable* e);
267 matchByStatement* getMatchByStatement(executable* e);
268 reverseOrderStatement* getReverseOrderStatement(executable* e);
270 const readStatement* getReadStatement(
const executable* e)
const;
271 const readHasMany* getReadHasMany(
const executable* e)
const;
272 const groupByStatement* getGroupByStatement(
const executable* e)
const;
273 const orderByStatement* getOrderByStatement(
const executable* e)
const;
274 const matchByStatement* getMatchByStatement(
const executable* e)
const;
275 const reverseOrderStatement*
276 getReverseOrderStatement(
const executable* e)
const;
280 void move(
int from,
int to);
281 void save(
const _TCHAR* filename);
282 void load(
const _TCHAR* filename);
283 void save(std::stringstream& sf);
284 void load(std::stringstream& sf);
285 void execute(recordset& rs,
const std::vector<std::_tstring>* values = NULL,
286 executeListner* listner = NULL);
287 static queryStatements* create(idatabaseManager& dbm);
288 static queryStatements* create(database* db);
301 #endif // BZS_DB_PROTOCOL_TDAP_CLIENT_SERIALIZEER_H