BmnRoot
Loading...
Searching...
No Matches
UniGenerateClasses.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- UniGenerateClasses cxx file -----
3// ----- Created 18/08/15 by K. Gertsenberger -----
4// -------------------------------------------------------------------------
6
7#include "TClass.h"
8#include "TList.h"
9#include "TMethodCall.h"
10#include "TSQLColumnInfo.h"
11#include "TSQLResult.h"
12#include "TSQLRow.h"
13#include "TSQLServer.h"
14#include "TSQLTableInfo.h"
15#include "TSystem.h"
16#include "function_set.h"
17#include "nlohmann/json.hpp"
18
19#include <fstream>
20#include <iostream>
21using namespace std;
23
24// ----- Constructor -------------------------------
26{
27 /*arrTableJoin = new TObjArray();
28
29 structTableJoin* stTableJoin = new structTableJoin();
30 stTableJoin->strSourceTableName = "detector_parameter";
31 stTableJoin->strJoinTableName = "parameter_";
32
33 stTableJoin->strJoinField.strColumnName = "parameter_id";
34 stTableJoin->strJoinField.strColumnPointer = "parameter_id";
35 stTableJoin->strJoinField.strColumnNameSpace = "parameter id";
36 stTableJoin->strJoinField.strVariableType = "int";
37 stTableJoin->strJoinField.strVariableTypePointer = "int";
38 stTableJoin->strJoinField.strStatementType = "Int";
39 stTableJoin->strJoinField.strPrintfType = "d";
40 stTableJoin->strJoinField.strVariableName = "i_parameter_id";
41 stTableJoin->strJoinField.strTempVariableName = "tmp__parameter_id";
42 stTableJoin->strJoinField.strShortVariableName = "ParameterId";
43 stTableJoin->strJoinField.isIdentity = false;
44 stTableJoin->strJoinField.isPrimary = false;
45 stTableJoin->strJoinField.isCompositeKey = false;
46 stTableJoin->strJoinField.isUnique = false;
47 stTableJoin->strJoinField.isNullable = false;
48 stTableJoin->strJoinField.isBinary = false;
49 stTableJoin->strJoinField.isDateTime = false;
50 stTableJoin->strJoinField.isTimeStamp = false;
51
52 structColumnInfo* pNameColumn = new structColumnInfo();
53 pNameColumn->strColumnName = "parameter_name";
54 pNameColumn->strColumnPointer = "parameter_name";
55 pNameColumn->strColumnNameSpace = "parameter name";
56 pNameColumn->strVariableType = "TString";
57 pNameColumn->strVariableTypePointer = "TString";
58 pNameColumn->strStatementType = "String";
59 pNameColumn->strPrintfType = "s";
60 pNameColumn->strVariableName = "str_parameter_name";
61 pNameColumn->strTempVariableName = "tmp__parameter_name";
62 pNameColumn->strShortVariableName = "ParameterName";
63 pNameColumn->isIdentity = false;
64 pNameColumn->isPrimary = false;
65 pNameColumn->isCompositeKey = false;
66 pNameColumn->isUnique = false;
67 pNameColumn->isNullable = false;
68 pNameColumn->isBinary = false;
69 pNameColumn->isDateTime = false;
70 pNameColumn->isTimeStamp = false;
71 stTableJoin->arrManualFieldNames->Add((TObject*)pNameColumn);
72
73 structColumnInfo* pTypeColumn = new structColumnInfo();
74 pTypeColumn->strColumnName = "parameter_type";
75 pTypeColumn->strColumnPointer = "parameter_type";
76 pTypeColumn->strColumnNameSpace = "parameter type";
77 pTypeColumn->strVariableType = "int";
78 pTypeColumn->strVariableTypePointer = "int";
79 pTypeColumn->strStatementType = "Int";
80 pTypeColumn->strPrintfType = "d";
81 pTypeColumn->strVariableName = "i_parameter_type";
82 pTypeColumn->strTempVariableName = "tmp__parameter_type";
83 pTypeColumn->strShortVariableName = "ParameterType";
84 pTypeColumn->isIdentity = false;
85 pTypeColumn->isPrimary = false;
86 pTypeColumn->isCompositeKey = false;
87 pTypeColumn->isUnique = false;
88 pTypeColumn->isNullable = false;
89 pTypeColumn->isBinary = false;
90 pTypeColumn->isDateTime = false;
91 pTypeColumn->isTimeStamp = false;
92 stTableJoin->arrManualFieldNames->Add((TObject*)pTypeColumn);
93
94 arrTableJoin->Add((TObject*)stTableJoin);
95
96 stTableJoin->arrManualFieldNames->SetOwner(kTRUE);
97 arrTableJoin->SetOwner(kTRUE);*/
98}
99
100// ----- Destructor -------------------------------
102
103// ----- Generate C++ classess - wrappers for database tables -------------------------------
104int UniGenerateClasses::GenerateClasses(TString json_configuration_file)
105{
106 TObjArray* arrTableJoin = nullptr;
107
108 bool isOnlyUpdate = true;
109 TString strConnectionName = "", strClassPrefix = "", strClassDirectory = "";
110
111 string file_path = gSystem->ExpandPathName(json_configuration_file.Data());
112 ifstream file(file_path);
113 if (file.is_open()) {
114 json data;
115 file >> data;
116
117 try {
118 strConnectionName = ((string)data["settings"]["connectionName"]).c_str();
119 strClassPrefix = ((string)data["settings"]["classPrefix"]).c_str();
120 } catch (const json::type_error& e) {
121 cout << "ERROR: Required settings were not found in the JSON file: settings->connectionName and "
122 "settings->classPrefix"
123 << endl;
124 file.close();
125 return -1;
126 }
127
128 try {
129 isOnlyUpdate = data["settings"]["onlyUpdateClasses"];
130 } catch (const json::type_error& e) {
131 isOnlyUpdate = true;
132 }
133
134 try {
135 strClassDirectory = ((string)data["settings"]["classDirectory"]).c_str();
136 if ((strClassDirectory != "") && (strClassDirectory[strClassDirectory.Length() - 1] != '/'))
137 strClassDirectory += '/';
138 strClassDirectory = gSystem->ExpandPathName(strClassDirectory.Data());
139 } catch (const json::type_error& e) {
140 strClassDirectory = "";
141 }
142 } else {
143 cout << "ERROR: JSON file with configuration was not found: " << file_path << endl;
144 return -2;
145 }
146 file.close();
147
148 TClass* connection_class = TClass::GetClass(strConnectionName.Data());
149 TMethodCall open_method(connection_class, "Open", "");
150 Long_t method_result = 0;
151 open_method.Execute(method_result);
152 TObject* pConnectionObject = (TObject*)method_result;
153 if (pConnectionObject == nullptr) {
154 cout << "ERROR: connection to the database was not established: " << strConnectionName << endl;
155 return -3;
156 }
157
158 TMethodCall server_method(connection_class, "GetSQLServer", "");
159 method_result = 0;
160 server_method.Execute(pConnectionObject, "", method_result);
161 TSQLServer* db_server = (TSQLServer*)method_result;
162 if (db_server == nullptr) {
163 cout << "ERROR: pointer to database server was not obtained" << endl;
164 return -4;
165 }
166
167 // define DBMS: MySQL (0) or Postgres (1)
168 int currentDBMS = -1;
169 if (strcmp(db_server->GetDBMS(), "MySQL") == 0)
170 currentDBMS = 0;
171 else if (strcmp(db_server->GetDBMS(), "PgSQL") == 0)
172 currentDBMS = 1;
173 else {
174 cout << "ERROR: this type of DBMS is not supported: " << db_server->GetDBMS() << endl;
175 return -5;
176 }
177
178 // int res_code = create_directory(strClassDir.Data());
179
180 // get list of all database tables
181 TList* lst = db_server->GetTablesList();
182 TIter next(lst);
183 TObject* obj;
184 // cycle for all database tables
185 TString sql;
186 while ((obj = next()) != nullptr) {
187 // define current table name
188 TString strTableName = obj->GetName();
189
190 // exclude system tables
191 if ((strTableName.BeginsWith("_"))
192 || ((currentDBMS == 1) && (strTableName.BeginsWith("pg_") || strTableName.BeginsWith("sql_"))))
193 continue;
194
195 cout << "Parsing table: " << strTableName << endl;
196 TSQLTableInfo* pTableInfo = db_server->GetTableInfo(strTableName.Data());
197
198 // GET LIST OF COLUMNS FOR THE CURRENT TABLE (pTableInfo->GetColumns() doesn't provide required info)
199 vector<structColumnInfo*> vecColumns;
200 if (currentDBMS == 0) {
201 sql = TString::Format(
202 "SELECT ordinal_position, column_name, data_type, (is_nullable = 'YES') AS is_nullable, "
203 "(extra = 'auto_increment') AS is_identity, (column_key = 'PRI') AS is_primary, (column_key = 'UNI') "
204 "AS is_unique "
205 "FROM INFORMATION_SCHEMA.COLUMNS "
206 "WHERE table_name = '%s' "
207 "ORDER BY ordinal_position",
208 strTableName.Data());
209 } else if (currentDBMS == 1) {
210 sql = TString::Format("SELECT DISTINCT a.attnum as ordinal_position, a.attname as column_name, "
211 "format_type(a.atttypid, a.atttypmod) as data_type, "
212 "a.attnotnull as is_nullable, pg_get_expr(def.adbin, def.adrelid) as is_default, "
213 "coalesce(i.indisprimary, false) as is_primary, coalesce(i.indisunique, false) as "
214 "is_unique, atttypmod as type_parameter "
215 "FROM pg_attribute a JOIN pg_class pgc ON pgc.oid = a.attrelid "
216 "LEFT JOIN pg_index i ON (pgc.oid = i.indrelid AND a.attnum = ANY(i.indkey)) "
217 "LEFT JOIN pg_description com on (pgc.oid = com.objoid AND a.attnum = com.objsubid) "
218 "LEFT JOIN pg_attrdef def ON (a.attrelid = def.adrelid AND a.attnum = def.adnum) "
219 "WHERE a.attnum > 0 AND pgc.oid = a.attrelid AND pg_table_is_visible(pgc.oid) "
220 "AND NOT a.attisdropped AND pgc.relname = '%s' "
221 "ORDER BY a.attnum;",
222 strTableName.Data());
223 }
224
225 TSQLResult* res = db_server->Query(sql);
226 int nrows = res->GetRowCount();
227 if (nrows == 0) {
228 cout << "CRITICAL ERROR: table with no attributes (columns) was found: " << strTableName << endl;
229 return -5;
230 }
231
232 // cycle all columns in the current table
233 TSQLRow* row;
234 while ((row = res->Next()) != nullptr) {
235 structColumnInfo* sColumnInfo = new structColumnInfo();
236 TString strColumnName = row->GetField(1);
237 sColumnInfo->strColumnName = strColumnName;
238 sColumnInfo->isBinary = false;
239 sColumnInfo->isDateTime = false;
240 sColumnInfo->isTimeStamp = false;
241
242 // remove last '_' in the column name in case of presence
243 TString strColumnNameWO = strColumnName;
244 if (strColumnNameWO[strColumnNameWO.Length() - 1] == '_')
245 strColumnNameWO = strColumnNameWO.Remove(strColumnNameWO.Length() - 1);
246
247 TString strColumnNameSpace = strColumnNameWO;
248 Ssiz_t char_under;
249 while ((char_under = strColumnNameSpace.First('_')) != kNPOS) {
250 strColumnNameSpace = strColumnNameSpace.Replace(char_under, 1, ' ');
251 }
252 sColumnInfo->strColumnNameSpace = strColumnNameSpace;
253
254 // define column properties depended on column type
255 TSQLColumnInfo* pColumnInfo = pTableInfo->FindColumn(strColumnName);
256 switch (pColumnInfo->GetSQLType()) {
257 case TSQLServer::kSQL_CHAR: {
258 sColumnInfo->strVariableType = "TString";
259 sColumnInfo->strStatementType = "String";
260 sColumnInfo->strPrintfType = "s";
261 sColumnInfo->strVariableName = "chr_" + strColumnNameWO;
262
263 break;
264 }
265 case TSQLServer::kSQL_VARCHAR: {
266 sColumnInfo->strVariableType = "TString";
267 sColumnInfo->strStatementType = "String";
268 sColumnInfo->strPrintfType = "s";
269 sColumnInfo->strVariableName = "str_" + strColumnNameWO;
270
271 break;
272 }
273 case TSQLServer::kSQL_INTEGER: {
274 TString strDataType = row->GetField(2);
275 if (strDataType == "uint") {
276 sColumnInfo->strVariableType = "unsigned int";
277 sColumnInfo->strStatementType = "UInt";
278 sColumnInfo->strPrintfType = "u";
279 sColumnInfo->strVariableName = "ui_" + strColumnNameWO;
280 } else {
281 if (strDataType.BeginsWith("bool")) {
282 sColumnInfo->strVariableType = "bool";
283 sColumnInfo->strStatementType = "Int";
284 sColumnInfo->strPrintfType = "d";
285 sColumnInfo->strVariableName = "b_" + strColumnNameWO;
286 } else {
287 if (strDataType.BeginsWith("bigint")) {
288 sColumnInfo->strVariableType = "int64_t";
289 sColumnInfo->strStatementType = "Long64";
290 sColumnInfo->strPrintfType = "ld";
291 sColumnInfo->strVariableName = "i64_" + strColumnNameWO;
292 } else {
293 sColumnInfo->strVariableType = "int";
294 sColumnInfo->strStatementType = "Int";
295 sColumnInfo->strPrintfType = "d";
296 sColumnInfo->strVariableName = "i_" + strColumnNameWO;
297 }
298 }
299 }
300
301 break;
302 }
303 case TSQLServer::kSQL_FLOAT: {
304 sColumnInfo->strVariableType = "float";
305 sColumnInfo->strStatementType = "Double";
306 sColumnInfo->strPrintfType = "f";
307 sColumnInfo->strVariableName = "f_" + strColumnNameWO;
308
309 break;
310 }
311 case TSQLServer::kSQL_DOUBLE: {
312 sColumnInfo->strVariableType = "double";
313 sColumnInfo->strStatementType = "Double";
314 sColumnInfo->strPrintfType = "f";
315 sColumnInfo->strVariableName = "d_" + strColumnNameWO;
316
317 break;
318 }
319 case TSQLServer::kSQL_BINARY: {
320 sColumnInfo->strVariableType = "unsigned char";
321 sColumnInfo->strStatementType = "Binary"; // LargeObject (old OID version)
322 sColumnInfo->strPrintfType = "p";
323 sColumnInfo->strVariableName = "blob_" + strColumnNameWO;
324 sColumnInfo->isBinary = true;
325
326 break;
327 }
328 case TSQLServer::kSQL_TIMESTAMP: {
329 // cout<<"TimeStamp. Size: "<<pColumnInfo->GetSize()<<". Length: "<<pColumnInfo->GetSize()<<".
330 // Scale: "<<pColumnInfo->GetScale()<<endl;
331 if ((row->GetField(7))[0] == '0') {
332 sColumnInfo->strVariableType = "TDatime";
333 sColumnInfo->strStatementType = "Datime";
334 sColumnInfo->strPrintfType = "s";
335 sColumnInfo->strVariableName = "dt_" + strColumnNameWO;
336 sColumnInfo->isDateTime = true;
337 } else {
338 // sColumnInfo->strVariableType = "TTimeStamp";
339 // sColumnInfo->strStatementType = "Timestamp";
340 sColumnInfo->strVariableType = "TDatime";
341 sColumnInfo->strStatementType = "Datime";
342 sColumnInfo->strPrintfType = "s";
343 sColumnInfo->strVariableName = "ts_" + strColumnNameWO;
344 // sColumnInfo->isTimeStamp = true;
345 sColumnInfo->isDateTime = true;
346 }
347
348 break;
349 }
350 default: {
351 TString strDataType = row->GetField(2);
352 if (strDataType == "bit") {
353 sColumnInfo->strVariableType = "bool";
354 sColumnInfo->strStatementType = "Int";
355 sColumnInfo->strPrintfType = "d";
356 sColumnInfo->strVariableName = "b_" + strColumnNameWO;
357 } else {
358 if (strDataType == "datetime") {
359 sColumnInfo->strVariableType = "TDatime";
360 sColumnInfo->strStatementType = "Datime";
361 sColumnInfo->strPrintfType = "s";
362 sColumnInfo->strVariableName = "dt_" + strColumnNameWO;
363 sColumnInfo->isDateTime = true;
364 } else {
365 if (strDataType.BeginsWith("character")) {
366 sColumnInfo->strVariableType = "TString";
367 sColumnInfo->strStatementType = "String";
368 sColumnInfo->strPrintfType = "s";
369 sColumnInfo->strVariableName = "chr_" + strColumnNameWO;
370 } else {
371 cout << "ERROR: no corresponding column type: " << row->GetField(2)
372 << ". SQLType: " << pColumnInfo->GetSQLType() << endl;
373 return -6;
374 }
375 }
376 }
377 }
378 } // switch (pColumnInfo->GetSQLType())
379
380 // form short variable name (e.g. ComponentName for 'component_name' column)
381 TString strShortVar = strColumnNameWO;
382 strShortVar = strShortVar.Replace(0, 1, toupper(strShortVar[0]));
383 while ((char_under = strShortVar.First('_')) != kNPOS) {
384 strShortVar = strShortVar.Remove(char_under, 1);
385 if (strShortVar.Length() > char_under)
386 strShortVar = strShortVar.Replace(char_under, 1, toupper(strShortVar[char_under]));
387 }
388 sColumnInfo->strShortVariableName = strShortVar;
389
390 if (currentDBMS == 0) {
391 sColumnInfo->isNullable = ((row->GetField(3))[0] == '1');
392 sColumnInfo->isIdentity = ((row->GetField(4))[0] == '1');
393 sColumnInfo->isPrimary = ((row->GetField(5))[0] == '1');
394 sColumnInfo->isUnique = ((row->GetField(6))[0] == '1');
395 } else if (currentDBMS == 1) {
396 string def_value = row->GetField(4);
397 sColumnInfo->isNullable = ((row->GetField(3))[0] == 'f');
398 sColumnInfo->isIdentity = (def_value.find("nextval") == 0);
399 sColumnInfo->isPrimary = ((row->GetField(5))[0] == 't');
400 if (sColumnInfo->isPrimary)
401 sColumnInfo->isUnique = false;
402 else
403 sColumnInfo->isUnique = ((row->GetField(6))[0] == 't');
404 }
405
406 sColumnInfo->strTempVariableName = "tmp_" + strColumnNameWO;
407 sColumnInfo->strVariableTypePointer = sColumnInfo->strVariableType;
408 if ((sColumnInfo->isNullable) || (sColumnInfo->isBinary)) {
409 sColumnInfo->strVariableType += "*";
410 sColumnInfo->strColumnPointer = "*" + strColumnNameWO;
411 } else
412 sColumnInfo->strColumnPointer = strColumnNameWO;
413
414 vecColumns.push_back(sColumnInfo);
415
416 if (sColumnInfo->isBinary) {
417 structColumnInfo* sColumnInfoBinary = new structColumnInfo();
418 sColumnInfoBinary->strVariableName = "sz_" + strColumnNameWO;
419 sColumnInfoBinary->strTempVariableName = "tmp_sz_" + strColumnNameWO;
420 sColumnInfoBinary->strVariableType = "Long_t";
421 sColumnInfoBinary->strColumnName = "size_" + strColumnNameWO;
422 sColumnInfoBinary->strColumnNameSpace = "size of " + strColumnNameSpace;
423 sColumnInfoBinary->strShortVariableName = sColumnInfo->strShortVariableName + "Size";
424 sColumnInfoBinary->strStatementType = "";
425
426 vecColumns.push_back(sColumnInfoBinary);
427 }
428 } // cycle for all columns of current table
429
430 delete row;
431 delete res;
432
433 // if join with another table is required - get structure with additional info
434 bool isJoin = false;
435 TIter nextJoin(arrTableJoin);
436 structTableJoin* curTableJoin;
437 while ((curTableJoin = (structTableJoin*)nextJoin()) != nullptr) {
438 if (curTableJoin->strSourceTableName == strTableName) {
439 isJoin = true;
440 break;
441 }
442 }
443
444 // generating class name corresponding current table name
445 TString strClassName = strTableName;
446 strClassName = strClassName.Replace(0, 1, toupper(strClassName[0]));
447 Ssiz_t char_under;
448 while ((char_under = strClassName.First('_')) != kNPOS) {
449 strClassName = strClassName.Remove(char_under, 1);
450 if (strClassName.Length() > char_under)
451 strClassName = strClassName.Replace(char_under, 1, toupper(strClassName[char_under]));
452 }
453 TString strShortTableName = strClassName;
454 strClassName = strClassPrefix + strClassName;
455
456 TString strTableNameSpace = strTableName;
457 if (strTableNameSpace[strTableNameSpace.Length() - 1] == '_')
458 strTableNameSpace = strTableNameSpace.Remove(strTableNameSpace.Length() - 1);
459 while ((char_under = strTableNameSpace.First('_')) != kNPOS)
460 strTableNameSpace = strTableNameSpace.Replace(char_under, 1, ' ');
461
462 // CREATING OR CHANGING HEADER FILE
463 TString strFileName = strClassDirectory + strClassName + ".h"; // set header file name
464 // open and write to file
465 ifstream oldFile;
466 TString strTempFileName;
467 ofstream hFile;
468 if (isOnlyUpdate) {
469 oldFile.open(strFileName, ios::in);
470 if (!oldFile.is_open()) {
471 cout << "ERROR: could not open existing header file: " << strFileName << endl;
472 return -7;
473 }
474
475 strTempFileName = strFileName + "_tmp";
476 hFile.open(strTempFileName, ios::out);
477 if (!hFile.is_open()) {
478 cout << "ERROR: could not create temporary header file: " << strTempFileName << endl;
479 return -8;
480 }
481
482 string cur_line;
483 while (getline(oldFile, cur_line)) {
484 string trim_line = trim(cur_line);
485 if (trim_line.substr(0, 20) == "/* GENERATED PRIVATE")
486 break;
487 else
488 hFile << cur_line << endl;
489 }
490 } else {
491 hFile.open(strFileName, ios::out);
492 if (!hFile.is_open()) {
493 cout << "ERROR: could not create header file: " << strFileName << endl;
494 return -9;
495 }
496
497 hFile << "// ----------------------------------------------------------------------\n";
498 hFile << (TString::Format("// %s header file\n", strClassName.Data())).Data();
499 hFile << (TString::Format("// Generated %s\n", get_current_date().c_str())).Data();
500 hFile << "// ----------------------------------------------------------------------\n\n";
501
502 hFile << TString::Format("/** %s\n", strFileName.Data());
503 hFile << (TString::Format(" ** Class for the table: %s\n", strTableName.Data())).Data();
504 hFile << " **/\n\n";
505
506 TString strClassNameUpper = strClassName;
507 strClassNameUpper.ToUpper();
508 hFile << (TString::Format("#ifndef %s_H\n", strClassNameUpper.Data())).Data();
509 hFile << (TString::Format("#define %s_H 1\n\n", strClassNameUpper.Data())).Data();
510
511 hFile << "#include \"TString.h\"\n";
512 hFile << "#include \"TDatime.h\"\n";
513 hFile << "#include \"TTimeStamp.h\"\n";
514 hFile << "\n#include \"" << strConnectionName.Data() << ".h\"\n\n";
515
516 hFile << (TString::Format("class %s\n", strClassName.Data())).Data();
517 hFile << "{\n";
518 hFile << " private:\n";
519 }
520
521 hFile << " /* GENERATED PRIVATE MEMBERS (SHOULD NOT BE CHANGED MANUALLY) */\n";
522
523 hFile << " /// connection to the database\n";
524 hFile << " " << strConnectionName.Data() << "* connectionDB;\n\n";
525
526 // adding member variables corresponding table columns
527 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
528 structColumnInfo* cur_col = *it;
529 hFile << (TString::Format(" /// %s\n", cur_col->strColumnNameSpace.Data())).Data();
530 hFile << (TString::Format(" %s %s;\n", cur_col->strVariableType.Data(), cur_col->strVariableName.Data()))
531 .Data();
532 }
533 // for join table
534 if (isJoin) {
535 TIter nextCol(curTableJoin->arrManualFieldNames);
536 structColumnInfo* cur_col;
537 while ((cur_col = (structColumnInfo*)nextCol()) != nullptr) {
538 hFile << (TString::Format(" /// Table: %s - column %s (read-only)\n",
539 curTableJoin->strJoinTableName.Data(), cur_col->strColumnNameSpace.Data()))
540 .Data();
541 hFile << (TString::Format(" %s %s;\n", cur_col->strVariableType.Data(),
542 cur_col->strVariableName.Data()))
543 .Data();
544 }
545 }
546
547 // CONSTRUCTOR - DECLARATION
548 hFile << "\n //Constructor\n";
549 hFile << (TString::Format(" %s(%s* db_connect", strClassName.Data(), strConnectionName.Data())).Data();
550 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
551 structColumnInfo* cur_col = *it;
552 hFile
553 << (TString::Format(", %s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data())).Data();
554 }
555 // for join table
556 if (isJoin) {
557 TIter nextCol(curTableJoin->arrManualFieldNames);
558 structColumnInfo* cur_col;
559 while ((cur_col = (structColumnInfo*)nextCol()) != nullptr)
560 hFile << (TString::Format(", %s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
561 .Data();
562 } // for join table
563 hFile << ");\n";
564 hFile << " /* END OF PRIVATE GENERATED PART (SHOULD NOT BE CHANGED MANUALLY) */\n";
565
566 if (isOnlyUpdate) {
567 string cur_line;
568 while (getline(oldFile, cur_line)) {
569 string trim_line = trim(cur_line);
570 if (trim_line.substr(0, 27) == "/* END OF PRIVATE GENERATED")
571 break;
572 }
573
574 while (getline(oldFile, cur_line)) {
575 string trim_line = trim(cur_line);
576 if (trim_line.substr(0, 19) == "/* GENERATED PUBLIC")
577 break;
578 else
579 hFile << cur_line << endl;
580 }
581 } else
582 hFile << "\n public:\n";
583
584 hFile << " /* GENERATED PUBLIC MEMBERS (SHOULD NOT BE CHANGED MANUALLY) */\n";
585 hFile << (TString::Format(" virtual ~%s(); // Destructor\n\n", strClassName.Data())).Data();
586
587 hFile << " // static class functions\n";
588 // CREATE NEW RECORD - DECLARATION
589 hFile << (TString::Format(" /// add new %s to the database\n", strTableNameSpace.Data())).Data();
590 hFile << (TString::Format(" static %s* Create%s(", strClassName.Data(), strShortTableName.Data())).Data();
591 int count = 0;
592 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
593 structColumnInfo* cur_col = *it;
594 if (cur_col->isIdentity)
595 continue;
596
597 if (count == 0)
598 hFile << (TString::Format("%s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
599 .Data();
600 else
601 hFile << (TString::Format(", %s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
602 .Data();
603
604 count++;
605 }
606 hFile << ");\n";
607
608 // GET RECORD - DECLARATION
609 hFile << (TString::Format(" /// get %s from the database\n", strTableNameSpace.Data())).Data();
610 hFile << (TString::Format(" static %s* Get%s(", strClassName.Data(), strShortTableName.Data())).Data();
611 count = 0;
612 bool is_flag = false;
613 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
614 structColumnInfo* cur_col = *it;
615 if (cur_col->isUnique)
616 is_flag = true;
617 if (!cur_col->isPrimary)
618 continue;
619
620 if (count == 0)
621 hFile << (TString::Format("%s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
622 .Data();
623 else
624 hFile << (TString::Format(", %s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
625 .Data();
626
627 count++;
628 }
629 hFile << ");\n";
630
631 if (is_flag) {
632 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
633 structColumnInfo* cur_col = *it;
634 if (!cur_col->isUnique)
635 continue;
636
637 hFile << (TString::Format(" /// get %s from the database\n", strTableNameSpace.Data())).Data();
638 hFile << (TString::Format(" static %s* Get%s(%s %s);\n", strClassName.Data(),
639 strShortTableName.Data(), cur_col->strVariableType.Data(),
640 cur_col->strColumnName.Data()))
641 .Data();
642 }
643 }
644
645 // CHECK RECORD EXISTS - DECLARATION
646 hFile << (TString::Format(
647 " /// check %s exists in the database: 1 - true, 0 - false, <0 - database operation error\n",
648 strTableNameSpace.Data()))
649 .Data();
650 hFile << (TString::Format(" static int Check%sExists(", strShortTableName.Data())).Data();
651 count = 0;
652 is_flag = false;
653 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
654 structColumnInfo* cur_col = *it;
655 if (cur_col->isUnique)
656 is_flag = true;
657 if (!cur_col->isPrimary)
658 continue;
659
660 if (count == 0)
661 hFile << (TString::Format("%s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
662 .Data();
663 else
664 hFile << (TString::Format(", %s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
665 .Data();
666
667 count++;
668 }
669 hFile << ");\n";
670
671 if (is_flag) {
672 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
673 structColumnInfo* cur_col = *it;
674 if (!cur_col->isUnique)
675 continue;
676
677 hFile << (TString::Format(" /// check %s exists in the database: 1 - true, 0 - false, <0 - database "
678 "operation error\n",
679 strTableNameSpace.Data()))
680 .Data();
681 hFile << (TString::Format(" static int Check%sExists(%s %s);\n", strShortTableName.Data(),
682 cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
683 .Data();
684 }
685 }
686
687 // DELETE RECORD - DECLARATION
688 hFile << (TString::Format(" /// delete %s from the database\n", strTableNameSpace.Data())).Data();
689 hFile << (TString::Format(" static int Delete%s(", strShortTableName.Data())).Data();
690 count = 0;
691 is_flag = false;
692 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
693 structColumnInfo* cur_col = *it;
694 if (cur_col->isUnique)
695 is_flag = true;
696 if (!cur_col->isPrimary)
697 continue;
698
699 if (count == 0)
700 hFile << (TString::Format("%s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
701 .Data();
702 else
703 hFile << (TString::Format(", %s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
704 .Data();
705
706 count++;
707 }
708 hFile << ");\n";
709
710 if (is_flag) {
711 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
712 structColumnInfo* cur_col = *it;
713 if (!cur_col->isUnique)
714 continue;
715
716 hFile << (TString::Format(" /// delete %s from the database\n", strTableNameSpace.Data())).Data();
717 hFile << (TString::Format(" static int Delete%s(%s %s);\n", strShortTableName.Data(),
718 cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
719 .Data();
720 }
721 }
722
723 // PRINT ALL ROWS -DECLARATION
724 hFile << (TString::Format(" /// print all %ss\n", strTableNameSpace.Data())).Data();
725 hFile << " static int PrintAll();\n";
726
727 // GETTERS FUNCTIONS - IMPLEMENTATIONS
728 hFile << "\n // Getters\n";
729 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
730 structColumnInfo* cur_col = *it;
731 hFile << (TString::Format(" /// get %s of the current %s\n", cur_col->strColumnNameSpace.Data(),
732 strTableNameSpace.Data()))
733 .Data();
734 hFile << (TString::Format(" %s Get%s() {", cur_col->strVariableType.Data(),
735 cur_col->strShortVariableName.Data()))
736 .Data();
737
738 if (cur_col->isNullable) {
739 hFile << (TString::Format("if (%s == nullptr) return nullptr; else ", cur_col->strVariableName.Data()))
740 .Data();
741 if (cur_col->isBinary) {
742 structColumnInfo* next_col = *(it + 1);
743 hFile << (TString::Format("{%s %s = new %s[%s]; ", cur_col->strVariableType.Data(),
744 cur_col->strTempVariableName.Data(),
745 cur_col->strVariableTypePointer.Data(), next_col->strVariableName.Data()))
746 .Data();
747 hFile << (TString::Format("memcpy(%s, %s, %s); ", cur_col->strTempVariableName.Data(),
748 cur_col->strVariableName.Data(), next_col->strVariableName.Data()))
749 .Data();
750 hFile << (TString::Format("return %s;}", cur_col->strTempVariableName.Data())).Data();
751 } else
752 hFile << (TString::Format("return new %s(*%s);", cur_col->strVariableTypePointer.Data(),
753 cur_col->strVariableName.Data()))
754 .Data();
755 } else {
756 if (cur_col->isBinary) {
757 structColumnInfo* next_col = *(it + 1);
758 hFile << (TString::Format("%s %s = new %s[%s]; ", cur_col->strVariableType.Data(),
759 cur_col->strTempVariableName.Data(),
760 cur_col->strVariableTypePointer.Data(), next_col->strVariableName.Data()))
761 .Data();
762 hFile << (TString::Format("memcpy(%s, %s, %s); ", cur_col->strTempVariableName.Data(),
763 cur_col->strVariableName.Data(), next_col->strVariableName.Data()))
764 .Data();
765 hFile << (TString::Format("return %s;", cur_col->strTempVariableName.Data())).Data();
766 } else
767 hFile << (TString::Format("return %s;", cur_col->strVariableName.Data())).Data();
768 }
769
770 hFile << "}\n";
771 }
772 // for join table
773 if (isJoin) {
774 structColumnInfo* cur_col;
775 for (int i = 0; i < curTableJoin->arrManualFieldNames->GetEntriesFast(); i++) {
776 cur_col = (structColumnInfo*)curTableJoin->arrManualFieldNames->At(i);
777
778 hFile << (TString::Format(" /// get %s of %s\n", cur_col->strColumnNameSpace.Data(),
779 curTableJoin->strJoinTableName.Data()))
780 .Data();
781 hFile << (TString::Format(" %s Get%s() {", cur_col->strVariableType.Data(),
782 cur_col->strShortVariableName.Data()))
783 .Data();
784
785 if (cur_col->isNullable) {
786 hFile << (TString::Format("if (%s == nullptr) return nullptr; else ",
787 cur_col->strVariableName.Data()))
788 .Data();
789 if (cur_col->isBinary) {
790 structColumnInfo* next_col = (structColumnInfo*)curTableJoin->arrManualFieldNames->At(i + 1);
791 hFile << (TString::Format("{%s %s = new %s[%s]; ", cur_col->strVariableType.Data(),
792 cur_col->strTempVariableName.Data(),
793 cur_col->strVariableTypePointer.Data(),
794 next_col->strVariableName.Data()))
795 .Data();
796 hFile << (TString::Format("memcpy(%s, %s, %s); ", cur_col->strTempVariableName.Data(),
797 cur_col->strVariableName.Data(), next_col->strVariableName.Data()))
798 .Data();
799 hFile << (TString::Format("return %s;}", cur_col->strTempVariableName.Data())).Data();
800 } else
801 hFile << (TString::Format("return new %s(*%s);", cur_col->strVariableTypePointer.Data(),
802 cur_col->strVariableName.Data()))
803 .Data();
804 } else {
805 if (cur_col->isBinary) {
806 structColumnInfo* next_col = (structColumnInfo*)curTableJoin->arrManualFieldNames->At(i + 1);
807 hFile << (TString::Format("%s %s = new %s[%s]; ", cur_col->strVariableType.Data(),
808 cur_col->strTempVariableName.Data(),
809 cur_col->strVariableTypePointer.Data(),
810 next_col->strVariableName.Data()))
811 .Data();
812 hFile << (TString::Format("memcpy(%s, %s, %s); ", cur_col->strTempVariableName.Data(),
813 cur_col->strVariableName.Data(), next_col->strVariableName.Data()))
814 .Data();
815 hFile << (TString::Format("return %s;", cur_col->strTempVariableName.Data())).Data();
816 } else
817 hFile << (TString::Format("return %s;", cur_col->strVariableName.Data())).Data();
818 }
819
820 hFile << "}\n";
821 }
822 } // for join table
823
824 // SETTERS FUNCTIONS - DECLARATIONS
825 hFile << "\n // Setters\n";
826 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
827 structColumnInfo* cur_col = *it;
828 if (cur_col->isIdentity)
829 continue;
830
831 if (!cur_col->isBinary) {
832 hFile << (TString::Format(" /// set %s of the current %s\n", cur_col->strColumnNameSpace.Data(),
833 strTableNameSpace.Data()))
834 .Data();
835 hFile << (TString::Format(" int Set%s(%s %s);\n", cur_col->strShortVariableName.Data(),
836 cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
837 .Data();
838 } else {
839 hFile << (TString::Format(" /// set %s of the current %s\n", cur_col->strColumnNameSpace.Data(),
840 strTableNameSpace.Data()))
841 .Data();
842 hFile << (TString::Format(" int Set%s(%s %s, ", cur_col->strShortVariableName.Data(),
843 cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
844 .Data();
845 ++it;
846 cur_col = *it;
847 hFile << (TString::Format("%s %s);\n", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
848 .Data();
849 }
850 }
851
852 // PRINT VALUES -DECLARATION
853 hFile << (TString::Format("\n /// print information about current %s\n", strTableNameSpace.Data())).Data();
854 hFile << " void Print();\n";
855 hFile << " /* END OF PUBLIC GENERATED PART (SHOULD NOT BE CHANGED MANUALLY) */\n";
856
857 if (isOnlyUpdate) {
858 string cur_line;
859 while (getline(oldFile, cur_line)) {
860 string trim_line = trim(cur_line);
861 if (trim_line.substr(0, 26) == "/* END OF PUBLIC GENERATED")
862 break;
863 }
864
865 while (getline(oldFile, cur_line))
866 hFile << cur_line << endl;
867 } else {
868 hFile << (TString::Format("\n ClassDef(%s,1);\n", strClassName.Data())).Data();
869 hFile << "};\n";
870 hFile << "\n#endif\n";
871 }
872
873 hFile.close();
874
875 if (isOnlyUpdate) {
876 oldFile.close();
877 // delete the original file
878 remove(strFileName);
879 // rename temporary file to original
880 rename(strTempFileName, strFileName);
881 }
882
883 // CREATING OR CHANGING CXX FILE
884 strFileName = strClassDirectory + strClassName + ".cxx";
885 // open and write to file
886 ofstream cxxFile;
887 if (isOnlyUpdate) {
888 oldFile.open(strFileName, ios::in);
889 if (!oldFile.is_open()) {
890 cout << "ERROR: could not open existing cxx file: " << strFileName << endl;
891 return -10;
892 }
893
894 strTempFileName = strFileName + "_tmp";
895 cxxFile.open(strTempFileName, ios::out);
896 if (!cxxFile.is_open()) {
897 cout << "ERROR: could not create temporary cxx file: " << strTempFileName << endl;
898 return -11;
899 }
900
901 string cur_line;
902 while (getline(oldFile, cur_line)) {
903 string trim_line = trim(cur_line);
904 if (trim_line.substr(0, 18) == "/* GENERATED CLASS")
905 break;
906 else
907 cxxFile << cur_line << endl;
908 }
909 } else {
910 cxxFile.open(strFileName, ios::out);
911 if (!cxxFile.is_open()) {
912 cout << "ERROR: could not create cxx file: " << strFileName << endl;
913 return -12;
914 }
915
916 cxxFile << "// ----------------------------------------------------------------------\n";
917 cxxFile << (TString::Format("// %s cxx file\n", strClassName.Data())).Data();
918 cxxFile << (TString::Format("// Generated %s\n", get_current_date().c_str())).Data();
919 cxxFile << "// ----------------------------------------------------------------------\n\n";
920
921 cxxFile << "#include \"TSQLServer.h\"\n";
922 cxxFile << "#include \"TSQLStatement.h\"\n";
923 cxxFile << (TString::Format("\n#include \"%s.h\"\n\n", strClassName.Data())).Data();
924
925 cxxFile << "#include <iostream>\n";
926 cxxFile << "using namespace std;\n\n";
927 }
928
929 cxxFile << "/* GENERATED CLASS MEMBERS (SHOULD NOT BE CHANGED MANUALLY) */\n";
930
931 // CONSTRUCTOR - IMPLEMENTATION
932 cxxFile << "// ----- Constructor with database connection -----------------------\n";
933 cxxFile << (TString::Format("%s::%s(%s* db_connect", strClassName.Data(), strClassName.Data(),
934 strConnectionName.Data()))
935 .Data();
936 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
937 structColumnInfo* cur_col = *it;
938 cxxFile
939 << (TString::Format(", %s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data())).Data();
940 }
941 // for join table
942 if (isJoin) {
943 TIter nextCol(curTableJoin->arrManualFieldNames);
944 structColumnInfo* cur_col;
945 while ((cur_col = (structColumnInfo*)nextCol()) != nullptr)
946 cxxFile << (TString::Format(", %s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
947 .Data();
948 } // for join table
949 cxxFile << ")\n{\n";
950
951 cxxFile << " connectionDB = db_connect;\n\n";
952 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
953 structColumnInfo* cur_col = *it;
954 cxxFile << (TString::Format(" %s = %s;\n", cur_col->strVariableName.Data(),
955 cur_col->strColumnName.Data()))
956 .Data();
957 }
958 // for join table
959 if (isJoin) {
960 TIter nextCol(curTableJoin->arrManualFieldNames);
961 structColumnInfo* cur_col;
962 while ((cur_col = (structColumnInfo*)nextCol()) != nullptr)
963 cxxFile << (TString::Format(" %s = %s;\n", cur_col->strVariableName.Data(),
964 cur_col->strColumnName.Data()))
965 .Data();
966 } // for join table
967 cxxFile << "}\n\n";
968
969 // DESTRUCTOR - IMPLEMENTATION
970 cxxFile << "// ----- Destructor -------------------------------------------------\n";
971 cxxFile << (TString::Format("%s::~%s()\n{\n if (connectionDB)\n delete connectionDB;\n",
972 strClassName.Data(), strClassName.Data()))
973 .Data();
974
975 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
976 structColumnInfo* cur_col = *it;
977
978 if (cur_col->isNullable)
979 cxxFile << (TString::Format(" if (%s)\n delete %s;\n", cur_col->strVariableName.Data(),
980 cur_col->strVariableName.Data()))
981 .Data();
982 if (cur_col->isBinary)
983 cxxFile << (TString::Format(" if (%s)\n delete [] %s;\n", cur_col->strVariableName.Data(),
984 cur_col->strVariableName.Data()))
985 .Data();
986 }
987 // for join table
988 if (isJoin) {
989 TIter nextCol(curTableJoin->arrManualFieldNames);
990 structColumnInfo* cur_col;
991 while ((cur_col = (structColumnInfo*)nextCol()) != nullptr) {
992 if (cur_col->isNullable)
993 cxxFile << (TString::Format(" if (%s)\n delete %s;\n", cur_col->strVariableName.Data(),
994 cur_col->strVariableName.Data()))
995 .Data();
996 if (cur_col->isBinary)
997 cxxFile << (TString::Format(" if (%s)\n delete [] %s;\n", cur_col->strVariableName.Data(),
998 cur_col->strVariableName.Data()))
999 .Data();
1000 }
1001 } // for join table
1002 cxxFile << "}\n\n";
1003
1004 // CREATE NEW RECORD - INPLEMENTATION
1005 cxxFile << (TString::Format("// ----- Creating new %s in the database ---------------------------\n",
1006 strTableNameSpace.Data()))
1007 .Data();
1008 cxxFile << (TString::Format("%s* %s::Create%s(", strClassName.Data(), strClassName.Data(),
1009 strShortTableName.Data()))
1010 .Data();
1011 count = 0;
1012 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1013 structColumnInfo* cur_col = *it;
1014 if (cur_col->isIdentity)
1015 continue;
1016
1017 if (count == 0)
1018 cxxFile << (TString::Format("%s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
1019 .Data();
1020 else
1021 cxxFile << (TString::Format(", %s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
1022 .Data();
1023
1024 count++;
1025 }
1026 // for join table
1027 if (isJoin) {
1028 TIter nextCol(curTableJoin->arrManualFieldNames);
1029 structColumnInfo* cur_col;
1030 while ((cur_col = (structColumnInfo*)nextCol()) != nullptr) {
1031 if (cur_col->isIdentity)
1032 continue;
1033
1034 if (count == 0)
1035 cxxFile << (TString::Format("%s %s", cur_col->strVariableType.Data(),
1036 cur_col->strColumnName.Data()))
1037 .Data();
1038 else
1039 cxxFile << (TString::Format(", %s %s", cur_col->strVariableType.Data(),
1040 cur_col->strColumnName.Data()))
1041 .Data();
1042
1043 count++;
1044 }
1045 } // for join table
1046 cxxFile << ")\n{\n";
1047 cxxFile << (TString::Format(" %s* connDb = %s::Open();\n", strConnectionName.Data(),
1048 strConnectionName.Data()))
1049 .Data();
1050 cxxFile << " if (connDb == nullptr) return nullptr;\n\n";
1051
1052 cxxFile << " TSQLServer* db_server = connDb->GetSQLServer();\n\n";
1053 cxxFile << (TString::Format(" TString sql = TString::Format(\n \"insert into %s(",
1054 strTableName.Data()))
1055 .Data();
1056 count = 0;
1057 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1058 structColumnInfo* cur_col = *it;
1059 if (cur_col->isIdentity)
1060 continue;
1061
1062 if (count == 0)
1063 cxxFile << (TString::Format("%s", cur_col->strColumnName.Data())).Data();
1064 else
1065 cxxFile << (TString::Format(", %s", cur_col->strColumnName.Data())).Data();
1066
1067 count++;
1068 if (cur_col->isBinary)
1069 ++it;
1070 }
1071 cxxFile << ") \"\n \"values (";
1072 for (int i = 1; i <= count; i++) {
1073 if (currentDBMS == 0) {
1074 if (i == 1)
1075 cxxFile << "?";
1076 else
1077 cxxFile << ", ?";
1078 } else if (currentDBMS == 1) {
1079 if (i == 1)
1080 cxxFile << "$1";
1081 else
1082 cxxFile << (TString::Format(", $%d", i)).Data();
1083 }
1084 }
1085 cxxFile << ")\");\n";
1086
1087 cxxFile << " TSQLStatement* stmt = db_server->Statement(sql);\n\n";
1088
1089 cxxFile << " stmt->NextIteration();\n";
1090 count = 0;
1091 TString strIdentityColumnName = "";
1092 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1093 structColumnInfo* cur_col = *it;
1094 if (cur_col->isIdentity) {
1095 strIdentityColumnName = cur_col->strColumnName.Data();
1096 continue;
1097 }
1098
1099 if (cur_col->isNullable)
1100 cxxFile << (TString::Format(" if (%s == nullptr)\n stmt->SetNull(%d);\n else\n ",
1101 cur_col->strColumnName.Data(), count))
1102 .Data();
1103
1104 if (!cur_col->isBinary)
1105 cxxFile << (TString::Format(" stmt->Set%s(%d, %s);\n", cur_col->strStatementType.Data(), count,
1106 cur_col->strColumnPointer.Data()))
1107 .Data();
1108 else {
1109 cxxFile << (TString::Format(" stmt->Set%s(%d, %s, ", cur_col->strStatementType.Data(), count,
1110 cur_col->strColumnName.Data()))
1111 .Data();
1112 ++it;
1113 cur_col = *it;
1114 cxxFile << (TString::Format("%s, 0x4000000);\n", cur_col->strColumnName.Data())).Data();
1115 }
1116
1117 count++;
1118 }
1119
1120 cxxFile << (TString::Format("\n // inserting new %s to the Database\n", strTableNameSpace.Data())).Data();
1121 cxxFile << " if (!stmt->Process())\n {\n";
1122 cxxFile << (TString::Format(
1123 " cout<<\"ERROR: inserting new %s to the Database has been failed\"<<endl;\n",
1124 strTableNameSpace.Data()))
1125 .Data();
1126 cxxFile << " delete stmt;\n delete connDb;\n return nullptr;\n }\n\n";
1127
1128 cxxFile << " delete stmt;\n\n";
1129
1130 if (strIdentityColumnName != "") {
1131 cxxFile << " // getting last inserted ID\n";
1132 cxxFile << (TString::Format(" int %s;\n", strIdentityColumnName.Data())).Data();
1133 if (currentDBMS == 0) {
1134 cxxFile << " TSQLStatement* stmt_last = db_server->Statement(\"SELECT LAST_INSERT_ID()\");\n";
1135 } else if (currentDBMS == 1) {
1136 cxxFile << (TString::Format(" TSQLStatement* stmt_last = db_server->Statement(\"SELECT "
1137 "currval(pg_get_serial_sequence('%s','%s'))\");\n",
1138 strTableName.Data(), strIdentityColumnName.Data()))
1139 .Data();
1140 }
1141
1142 cxxFile << "\n // process getting last id\n"
1143 " if (stmt_last->Process())\n {\n"
1144 " // store result of statement in buffer\n"
1145 " stmt_last->StoreResult();\n\n";
1146 cxxFile << " // if there is no last id then exit with error\n"
1147 " if (!stmt_last->NextResultRow())\n {\n"
1148 " cout<<\"ERROR: no last ID in DB!\"<<endl;\n"
1149 " delete stmt_last;\n"
1150 " return nullptr;\n }\n"
1151 " else\n {\n";
1152 cxxFile
1153 << (TString::Format(" %s = stmt_last->GetInt(0);\n", strIdentityColumnName.Data())).Data();
1154 cxxFile << " delete stmt_last;\n }\n }\n"
1155 " else\n {\n"
1156 " cout<<\"ERROR: getting last ID has been failed!\"<<endl;\n"
1157 " delete stmt_last;\n"
1158 " return nullptr;\n }\n\n";
1159 }
1160
1161 // for join table
1162 if (isJoin) {
1163 cxxFile << " sql = TString::Format(\n \"select";
1164 count = 0;
1165 TIter nextSel(curTableJoin->arrManualFieldNames);
1166 structColumnInfo* cur_col;
1167 while ((cur_col = (structColumnInfo*)nextSel()) != nullptr) {
1168 if (count == 0)
1169 cxxFile << (TString::Format(" %s", cur_col->strColumnName.Data())).Data();
1170 else
1171 cxxFile << (TString::Format(", %s", cur_col->strColumnName.Data())).Data();
1172
1173 count++;
1174 if (cur_col->isBinary)
1175 nextSel();
1176 }
1177 cxxFile << (TString::Format(" \"\n \"from %s \"\n \"where",
1178 curTableJoin->strJoinTableName.Data()))
1179 .Data();
1180 if (curTableJoin->strJoinField.strStatementType == "String")
1181 cxxFile << (TString::Format(" lower(%s) = lower('%%%s')",
1182 curTableJoin->strJoinField.strColumnName.Data(),
1183 curTableJoin->strJoinField.strPrintfType.Data()))
1184 .Data();
1185 else
1186 cxxFile << (TString::Format(" %s = %%%s", curTableJoin->strJoinField.strColumnName.Data(),
1187 curTableJoin->strJoinField.strPrintfType.Data()))
1188 .Data();
1189 cxxFile << "\"";
1190 if (cur_col->strStatementType == "String")
1191 cxxFile << (TString::Format(", %s.Data()", curTableJoin->strJoinField.strColumnName.Data())).Data();
1192 else
1193 cxxFile << (TString::Format(", %s", curTableJoin->strJoinField.strColumnName.Data())).Data();
1194 cxxFile << ");\n";
1195
1196 cxxFile << " stmt = db_server->Statement(sql);\n";
1197
1198 cxxFile << "\n // get join table record from DB\n";
1199 cxxFile << " if (!stmt->Process())\n {\n";
1200 cxxFile << (TString::Format(" cout<<\"ERROR: getting join record from DB has been failed for '%s' "
1201 "table\"<<endl;\n\n",
1202 curTableJoin->strJoinTableName.Data()))
1203 .Data();
1204 cxxFile << " delete stmt;\n";
1205 cxxFile << " delete connDb;\n";
1206 cxxFile << " return nullptr;\n }\n\n";
1207
1208 cxxFile << " // store result of statement in buffer\n";
1209 cxxFile << " stmt->StoreResult();\n\n";
1210
1211 cxxFile << " // extract join row\n";
1212 cxxFile << " if (!stmt->NextResultRow())\n {\n";
1213 cxxFile << (TString::Format(" cout<<\"ERROR: the record was not found in '%s' table\"<<endl;\n\n",
1214 curTableJoin->strJoinTableName.Data()))
1215 .Data();
1216 cxxFile << " delete stmt;\n";
1217 cxxFile << " delete connDb;\n";
1218
1219 count = 0;
1220 TIter nextGet(curTableJoin->arrManualFieldNames);
1221 while ((cur_col = (structColumnInfo*)nextGet()) != nullptr) {
1222 TString StatementType = cur_col->strStatementType, TempVar = cur_col->strTempVariableName,
1223 VariableTypePointer = cur_col->strVariableTypePointer;
1224 cxxFile << (TString::Format(" %s %s;\n", cur_col->strVariableType.Data(), TempVar.Data())).Data();
1225
1226 if (cur_col->isNullable) {
1227 cxxFile << (TString::Format(" if (stmt->IsNull(%d)) %s = nullptr;\n else\n ", count,
1228 TempVar.Data()))
1229 .Data();
1230 if (cur_col->isBinary) {
1231 cxxFile << (TString::Format(" {\n %s = nullptr;\n", TempVar.Data())).Data();
1232 cur_col = (structColumnInfo*)nextGet();
1233 cxxFile << (TString::Format(" %s %s = 0;\n", cur_col->strVariableType.Data(),
1234 cur_col->strTempVariableName.Data()))
1235 .Data();
1236 cxxFile << (TString::Format(" stmt->Get%s(%d, (void*&)%s, %s);\n }\n",
1237 StatementType.Data(), count, TempVar.Data(),
1238 cur_col->strTempVariableName.Data()))
1239 .Data();
1240 } else
1241 cxxFile << (TString::Format(" %s = new %s(stmt->Get%s(%d));\n", TempVar.Data(),
1242 VariableTypePointer.Data(), StatementType.Data(), count))
1243 .Data();
1244 } else {
1245 if (cur_col->isBinary) {
1246 cxxFile << (TString::Format(" %s = nullptr;\n", TempVar.Data())).Data();
1247 cur_col = (structColumnInfo*)nextGet();
1248 cxxFile << (TString::Format(" %s %s = 0;\n", cur_col->strVariableType.Data(),
1249 cur_col->strTempVariableName.Data()))
1250 .Data();
1251 cxxFile << (TString::Format(" stmt->Get%s(%d, (void*&)%s, %s);\n", StatementType.Data(),
1252 count, TempVar.Data(), cur_col->strTempVariableName.Data()))
1253 .Data();
1254 } else
1255 cxxFile << (TString::Format(" %s = stmt->Get%s(%d);\n", TempVar.Data(), StatementType.Data(),
1256 count))
1257 .Data();
1258 }
1259
1260 count++;
1261 }
1262 cxxFile << "\n delete stmt;\n\n";
1263
1264 } // for join table
1265
1266 // write to temporary variable to create separate memory copy of original variables
1267 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1268 structColumnInfo* cur_col = *it;
1269
1270 TString TempColumnName = cur_col->strColumnName, TempVar = cur_col->strTempVariableName,
1271 VariableTypePointer = cur_col->strVariableTypePointer;
1272 cxxFile << (TString::Format(" %s %s;\n", cur_col->strVariableType.Data(), TempVar.Data())).Data();
1273
1274 if (cur_col->isNullable) {
1275 cxxFile << (TString::Format(" if (%s == nullptr) %s = nullptr;\n else\n ",
1276 cur_col->strColumnName.Data(), TempVar.Data()))
1277 .Data();
1278 if (cur_col->isBinary) {
1279 ++it;
1280 cur_col = *it;
1281 cxxFile << (TString::Format(" {\n %s %s = %s;\n", cur_col->strVariableType.Data(),
1282 cur_col->strTempVariableName.Data(), cur_col->strColumnName.Data()))
1283 .Data();
1284 cxxFile << (TString::Format(" %s = new %s[%s];\n", TempVar.Data(),
1285 VariableTypePointer.Data(), cur_col->strTempVariableName.Data()))
1286 .Data();
1287 cxxFile << (TString::Format(" memcpy(%s, %s, %s);\n }\n", TempVar.Data(),
1288 TempColumnName.Data(), cur_col->strTempVariableName.Data()))
1289 .Data();
1290 } else
1291 cxxFile << (TString::Format(" %s = new %s(*%s);\n", TempVar.Data(), VariableTypePointer.Data(),
1292 cur_col->strColumnName.Data()))
1293 .Data();
1294 } else {
1295 if (cur_col->isBinary) {
1296 ++it;
1297 cur_col = *it;
1298 cxxFile << (TString::Format(" %s %s = %s;\n", cur_col->strVariableType.Data(),
1299 cur_col->strTempVariableName.Data(), cur_col->strColumnName.Data()))
1300 .Data();
1301 cxxFile << (TString::Format(" %s = new %s[%s];\n", TempVar.Data(), VariableTypePointer.Data(),
1302 cur_col->strTempVariableName.Data()))
1303 .Data();
1304 cxxFile << (TString::Format(" memcpy(%s, %s, %s);\n", TempVar.Data(), TempColumnName.Data(),
1305 cur_col->strTempVariableName.Data()))
1306 .Data();
1307 } else
1308 cxxFile
1309 << (TString::Format(" %s = %s;\n", TempVar.Data(), cur_col->strColumnName.Data())).Data();
1310 }
1311 }
1312
1313 cxxFile << (TString::Format("\n return new %s(connDb", strClassName.Data())).Data();
1314 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1315 structColumnInfo* cur_col = *it;
1316 cxxFile << (TString::Format(", %s", cur_col->strTempVariableName.Data())).Data();
1317 }
1318 // for join table
1319 if (isJoin) {
1320 TIter nextCol(curTableJoin->arrManualFieldNames);
1321 structColumnInfo* cur_col;
1322 while ((cur_col = (structColumnInfo*)nextCol()) != nullptr)
1323 cxxFile << (TString::Format(", %s", cur_col->strTempVariableName.Data())).Data();
1324 } // for join table
1325 cxxFile << ");\n}\n\n";
1326
1327 // GET RECORD - IMPLEMENTATION
1328 cxxFile << (TString::Format("// ----- Get %s from the database ---------------------------\n",
1329 strTableNameSpace.Data()))
1330 .Data();
1331 cxxFile << (TString::Format("%s* %s::Get%s(", strClassName.Data(), strClassName.Data(),
1332 strShortTableName.Data()))
1333 .Data();
1334 count = 0;
1335 is_flag = false;
1336 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1337 structColumnInfo* cur_col = *it;
1338 if (cur_col->isUnique)
1339 is_flag = true;
1340 if (!cur_col->isPrimary)
1341 continue;
1342
1343 if (count == 0)
1344 cxxFile << (TString::Format("%s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
1345 .Data();
1346 else
1347 cxxFile << (TString::Format(", %s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
1348 .Data();
1349
1350 count++;
1351 }
1352 cxxFile << ")\n{\n";
1353
1354 cxxFile << (TString::Format(" %s* connDb = %s::Open();\n", strConnectionName.Data(),
1355 strConnectionName.Data()))
1356 .Data();
1357 cxxFile << " if (connDb == nullptr) return nullptr;\n\n";
1358
1359 cxxFile << " TSQLServer* db_server = connDb->GetSQLServer();\n\n";
1360 cxxFile << " TString sql = TString::Format(\n \"select";
1361 count = 0;
1362 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1363 structColumnInfo* cur_col = *it;
1364 if (count == 0)
1365 cxxFile << (TString::Format(" %s", cur_col->strColumnName.Data())).Data();
1366 else
1367 cxxFile << (TString::Format(", %s", cur_col->strColumnName.Data())).Data();
1368
1369 count++;
1370 if (cur_col->isBinary)
1371 ++it;
1372 }
1373 // for join table
1374 if (isJoin) {
1375 TIter nextCol(curTableJoin->arrManualFieldNames);
1376 structColumnInfo* cur_col;
1377 while ((cur_col = (structColumnInfo*)nextCol()) != nullptr) {
1378 if (count == 0)
1379 cxxFile << (TString::Format(" %s", cur_col->strColumnName.Data())).Data();
1380 else
1381 cxxFile << (TString::Format(", %s", cur_col->strColumnName.Data())).Data();
1382
1383 count++;
1384 if (cur_col->isBinary)
1385 nextCol();
1386 }
1387 } // for join table
1388 cxxFile << (TString::Format(" \"\n \"from %s", strTableName.Data())).Data();
1389 // for join table
1390 if (isJoin) {
1391 cxxFile << (TString::Format(" join %s on %s.%s=%s.%s", curTableJoin->strJoinTableName.Data(),
1392 strTableName.Data(), curTableJoin->strJoinField.strColumnName.Data(),
1393 curTableJoin->strJoinTableName.Data(),
1394 curTableJoin->strJoinField.strColumnName.Data()))
1395 .Data();
1396 } // for join table
1397 cxxFile << " \"\n \"where";
1398 count = 0;
1399 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1400 structColumnInfo* cur_col = *it;
1401 if (!cur_col->isPrimary)
1402 continue;
1403
1404 if (count > 0)
1405 cxxFile << " and";
1406
1407 if (cur_col->strStatementType == "String")
1408 cxxFile << (TString::Format(" lower(%s) = lower('%%%s')", cur_col->strColumnName.Data(),
1409 cur_col->strPrintfType.Data()))
1410 .Data();
1411 else
1412 cxxFile << (TString::Format(" %s = %%%s", cur_col->strColumnName.Data(), cur_col->strPrintfType.Data()))
1413 .Data();
1414
1415 count++;
1416 }
1417
1418 cxxFile << "\"";
1419 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1420 structColumnInfo* cur_col = *it;
1421 if (!cur_col->isPrimary)
1422 continue;
1423
1424 if (cur_col->strStatementType == "String")
1425 cxxFile << (TString::Format(", %s.Data()", cur_col->strColumnName.Data())).Data();
1426 else
1427 cxxFile << (TString::Format(", %s", cur_col->strColumnName.Data())).Data();
1428 }
1429 cxxFile << ");\n";
1430
1431 cxxFile << " TSQLStatement* stmt = db_server->Statement(sql);\n";
1432
1433 cxxFile << (TString::Format("\n // get %s from the database\n", strTableNameSpace.Data())).Data();
1434 cxxFile << " if (!stmt->Process())\n {\n";
1435 cxxFile << (TString::Format(" cout<<\"ERROR: getting %s from the database has been failed\"<<endl;\n\n",
1436 strTableNameSpace.Data()))
1437 .Data();
1438 cxxFile << " delete stmt;\n";
1439 cxxFile << " delete connDb;\n";
1440 cxxFile << " return nullptr;\n }\n\n";
1441
1442 cxxFile << " // store result of statement in buffer\n";
1443 cxxFile << " stmt->StoreResult();\n\n";
1444
1445 cxxFile << " // extract row\n";
1446 cxxFile << " if (!stmt->NextResultRow())\n {\n";
1447 cxxFile << (TString::Format(" cout<<\"ERROR: %s was not found in the database\"<<endl;\n\n",
1448 strTableNameSpace.Data()))
1449 .Data();
1450 cxxFile << " delete stmt;\n";
1451 cxxFile << " delete connDb;\n";
1452 cxxFile << " return nullptr;\n }\n\n";
1453
1454 count = 0;
1455 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1456 structColumnInfo* cur_col = *it;
1457
1458 TString StatementType = cur_col->strStatementType, TempVar = cur_col->strTempVariableName,
1459 VariableTypePointer = cur_col->strVariableTypePointer;
1460 cxxFile << (TString::Format(" %s %s;\n", cur_col->strVariableType.Data(), TempVar.Data())).Data();
1461
1462 if (cur_col->isNullable) {
1463 cxxFile << (TString::Format(" if (stmt->IsNull(%d)) %s = nullptr;\n else\n ", count,
1464 TempVar.Data()))
1465 .Data();
1466 if (cur_col->isBinary) {
1467 cxxFile << (TString::Format(" {\n %s = nullptr;\n", TempVar.Data())).Data();
1468 ++it;
1469 cur_col = *it;
1470 cxxFile << (TString::Format(" %s %s = 0;\n", cur_col->strVariableType.Data(),
1471 cur_col->strTempVariableName.Data()))
1472 .Data();
1473 cxxFile << (TString::Format(" stmt->Get%s(%d, (void*&)%s, %s);\n }\n",
1474 StatementType.Data(), count, TempVar.Data(),
1475 cur_col->strTempVariableName.Data()))
1476 .Data();
1477 } else
1478 cxxFile << (TString::Format(" %s = new %s(stmt->Get%s(%d));\n", TempVar.Data(),
1479 VariableTypePointer.Data(), StatementType.Data(), count))
1480 .Data();
1481 } else {
1482 if (cur_col->isBinary) {
1483 cxxFile << (TString::Format(" %s = nullptr;\n", TempVar.Data())).Data();
1484 ++it;
1485 cur_col = *it;
1486 cxxFile << (TString::Format(" %s %s = 0;\n", cur_col->strVariableType.Data(),
1487 cur_col->strTempVariableName.Data()))
1488 .Data();
1489 cxxFile << (TString::Format(" stmt->Get%s(%d, (void*&)%s, %s);\n", StatementType.Data(), count,
1490 TempVar.Data(), cur_col->strTempVariableName.Data()))
1491 .Data();
1492 } else
1493 cxxFile << (TString::Format(" %s = stmt->Get%s(%d);\n", TempVar.Data(), StatementType.Data(),
1494 count))
1495 .Data();
1496 }
1497
1498 count++;
1499 }
1500
1501 // for join table
1502 if (isJoin) {
1503 TIter nextGet(curTableJoin->arrManualFieldNames);
1504 structColumnInfo* cur_col;
1505 while ((cur_col = (structColumnInfo*)nextGet()) != nullptr) {
1506 TString StatementType = cur_col->strStatementType, TempVar = cur_col->strTempVariableName,
1507 VariableTypePointer = cur_col->strVariableTypePointer;
1508 cxxFile << (TString::Format(" %s %s;\n", cur_col->strVariableType.Data(), TempVar.Data())).Data();
1509
1510 if (cur_col->isNullable) {
1511 cxxFile << (TString::Format(" if (stmt->IsNull(%d)) %s = nullptr;\n else\n ", count,
1512 TempVar.Data()))
1513 .Data();
1514 if (cur_col->isBinary) {
1515 cxxFile << (TString::Format(" {\n %s = nullptr;\n", TempVar.Data())).Data();
1516 cur_col = (structColumnInfo*)nextGet();
1517 cxxFile << (TString::Format(" %s %s = 0;\n", cur_col->strVariableType.Data(),
1518 cur_col->strTempVariableName.Data()))
1519 .Data();
1520 cxxFile << (TString::Format(" stmt->Get%s(%d, (void*&)%s, %s);\n }\n",
1521 StatementType.Data(), count, TempVar.Data(),
1522 cur_col->strTempVariableName.Data()))
1523 .Data();
1524 } else
1525 cxxFile << (TString::Format(" %s = new %s(stmt->Get%s(%d));\n", TempVar.Data(),
1526 VariableTypePointer.Data(), StatementType.Data(), count))
1527 .Data();
1528 } else {
1529 if (cur_col->isBinary) {
1530 cxxFile << (TString::Format(" %s = nullptr;\n", TempVar.Data())).Data();
1531 cur_col = (structColumnInfo*)nextGet();
1532 cxxFile << (TString::Format(" %s %s = 0;\n", cur_col->strVariableType.Data(),
1533 cur_col->strTempVariableName.Data()))
1534 .Data();
1535 cxxFile << (TString::Format(" stmt->Get%s(%d, (void*&)%s, %s);\n", StatementType.Data(),
1536 count, TempVar.Data(), cur_col->strTempVariableName.Data()))
1537 .Data();
1538 } else
1539 cxxFile << (TString::Format(" %s = stmt->Get%s(%d);\n", TempVar.Data(), StatementType.Data(),
1540 count))
1541 .Data();
1542 }
1543
1544 count++;
1545 }
1546
1547 } // for join table
1548
1549 cxxFile << "\n delete stmt;\n\n";
1550
1551 cxxFile << (TString::Format(" return new %s(connDb", strClassName.Data())).Data();
1552 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1553 structColumnInfo* cur_col = *it;
1554
1555 cxxFile << (TString::Format(", %s", cur_col->strTempVariableName.Data())).Data();
1556 if (cur_col->isBinary) {
1557 ++it;
1558 cur_col = *it;
1559 cxxFile << (TString::Format(", %s", cur_col->strTempVariableName.Data())).Data();
1560 }
1561 }
1562 // for join table
1563 if (isJoin) {
1564 TIter nextCol(curTableJoin->arrManualFieldNames);
1565 structColumnInfo* cur_col;
1566 while ((cur_col = (structColumnInfo*)nextCol()) != nullptr) {
1567 cxxFile << (TString::Format(", %s", cur_col->strTempVariableName.Data())).Data();
1568 if (cur_col->isBinary) {
1569 cur_col = (structColumnInfo*)nextCol();
1570 cxxFile << (TString::Format(", %s", cur_col->strTempVariableName.Data())).Data();
1571 }
1572 }
1573 } // for join table
1574 cxxFile << ");\n}\n\n";
1575
1576 // static get functions for unique fields
1577 if (is_flag) {
1578 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1579 structColumnInfo* cur_col = *it;
1580 if (!cur_col->isUnique)
1581 continue;
1582
1583 cxxFile << (TString::Format("// ----- Get %s from the database by unique key --------------\n",
1584 strTableNameSpace.Data()))
1585 .Data();
1586 cxxFile << (TString::Format("%s* %s::Get%s(%s %s)\n{\n", strClassName.Data(), strClassName.Data(),
1587 strShortTableName.Data(), cur_col->strVariableType.Data(),
1588 cur_col->strColumnName.Data()))
1589 .Data();
1590
1591 cxxFile << (TString::Format(" %s* connDb = %s::Open();\n", strConnectionName.Data(),
1592 strConnectionName.Data()))
1593 .Data();
1594 cxxFile << " if (connDb == nullptr) return nullptr;\n\n";
1595
1596 cxxFile << " TSQLServer* db_server = connDb->GetSQLServer();\n\n";
1597 cxxFile << " TString sql = TString::Format(\n \"select";
1598 count = 0;
1599 for (vector<structColumnInfo*>::iterator it_inner = vecColumns.begin(); it_inner != vecColumns.end();
1600 ++it_inner)
1601 {
1602 structColumnInfo* current_col = *it_inner;
1603 if (count == 0)
1604 cxxFile << (TString::Format(" %s", current_col->strColumnName.Data())).Data();
1605 else
1606 cxxFile << (TString::Format(", %s", current_col->strColumnName.Data())).Data();
1607
1608 count++;
1609 if (current_col->isBinary)
1610 ++it_inner;
1611 }
1612
1613 cxxFile << (TString::Format(" \"\n \"from %s", strTableName.Data())).Data();
1614 // for join table
1615 if (isJoin) {
1616 cxxFile << (TString::Format(" join %s on %s.%s=%s.%s", curTableJoin->strJoinTableName.Data(),
1617 strTableName.Data(), curTableJoin->strJoinField.strColumnName.Data(),
1618 curTableJoin->strJoinTableName.Data(),
1619 curTableJoin->strJoinField.strColumnName.Data()))
1620 .Data();
1621 } // for join table
1622 if (cur_col->strStatementType == "String")
1623 cxxFile << (TString::Format(" \"\n \"where lower(%s) = lower('%%%s')\", %s.Data());\n",
1624 cur_col->strColumnName.Data(), cur_col->strPrintfType.Data(),
1625 cur_col->strColumnName.Data()))
1626 .Data();
1627 else
1628 cxxFile << (TString::Format(" \"\n \"where %s = %%%s\", %s);\n",
1629 cur_col->strColumnName.Data(), cur_col->strPrintfType.Data(),
1630 cur_col->strColumnName.Data()))
1631 .Data();
1632
1633 cxxFile << " TSQLStatement* stmt = db_server->Statement(sql);\n";
1634
1635 cxxFile << (TString::Format("\n // get %s from the database\n", strTableNameSpace.Data())).Data();
1636 cxxFile << " if (!stmt->Process())\n {\n";
1637 cxxFile << (TString::Format(
1638 " cout<<\"ERROR: getting %s from the database has been failed\"<<endl;\n\n",
1639 strTableNameSpace.Data()))
1640 .Data();
1641 cxxFile << " delete stmt;\n";
1642 cxxFile << " delete connDb;\n";
1643 cxxFile << " return nullptr;\n }\n\n";
1644
1645 cxxFile << " // store result of statement in buffer\n";
1646 cxxFile << " stmt->StoreResult();\n\n";
1647
1648 cxxFile << " // extract row\n";
1649 cxxFile << " if (!stmt->NextResultRow())\n {\n";
1650 cxxFile << (TString::Format(" cout<<\"ERROR: %s was not found in the database\"<<endl;\n\n",
1651 strTableNameSpace.Data()))
1652 .Data();
1653 cxxFile << " delete stmt;\n";
1654 cxxFile << " delete connDb;\n";
1655 cxxFile << " return nullptr;\n }\n\n";
1656
1657 count = 0;
1658 for (vector<structColumnInfo*>::iterator it_inner = vecColumns.begin(); it_inner != vecColumns.end();
1659 ++it_inner)
1660 {
1661 structColumnInfo* current_col = *it_inner;
1662
1663 TString StatementType = current_col->strStatementType, TempVar = current_col->strTempVariableName,
1664 VariableTypePointer = current_col->strVariableTypePointer;
1665 cxxFile << (TString::Format(" %s %s;\n", current_col->strVariableType.Data(), TempVar.Data()))
1666 .Data();
1667
1668 if (current_col->isNullable) {
1669 cxxFile << (TString::Format(" if (stmt->IsNull(%d)) %s = nullptr;\n else\n ", count,
1670 TempVar.Data()))
1671 .Data();
1672 if (current_col->isBinary) {
1673 cxxFile << (TString::Format(" {\n %s = nullptr;\n", TempVar.Data())).Data();
1674 ++it_inner;
1675 current_col = *it_inner;
1676 cxxFile << (TString::Format(" %s %s = 0;\n", current_col->strVariableType.Data(),
1677 current_col->strTempVariableName.Data()))
1678 .Data();
1679 cxxFile << (TString::Format(" stmt->Get%s(%d, (void*&)%s, %s);\n }\n",
1680 StatementType.Data(), count, TempVar.Data(),
1681 current_col->strTempVariableName.Data()))
1682 .Data();
1683 } else
1684 cxxFile << (TString::Format(" %s = new %s(stmt->Get%s(%d));\n", TempVar.Data(),
1685 VariableTypePointer.Data(), StatementType.Data(), count))
1686 .Data();
1687 } else {
1688 if (current_col->isBinary) {
1689 cxxFile << (TString::Format(" %s = nullptr;\n", TempVar.Data())).Data();
1690 ++it_inner;
1691 current_col = *it_inner;
1692 cxxFile << (TString::Format(" %s %s = 0;\n", current_col->strVariableType.Data(),
1693 current_col->strTempVariableName.Data()))
1694 .Data();
1695 cxxFile << (TString::Format(" stmt->Get%s(%d, (void*&)%s, %s);\n", StatementType.Data(),
1696 count, TempVar.Data(), current_col->strTempVariableName.Data()))
1697 .Data();
1698 } else
1699 cxxFile << (TString::Format(" %s = stmt->Get%s(%d);\n", TempVar.Data(),
1700 StatementType.Data(), count))
1701 .Data();
1702 }
1703
1704 count++;
1705 }
1706
1707 // for join table
1708 if (isJoin) {
1709 TIter nextGet(curTableJoin->arrManualFieldNames);
1710 while ((cur_col = (structColumnInfo*)nextGet()) != nullptr) {
1711 TString StatementType = cur_col->strStatementType, TempVar = cur_col->strTempVariableName,
1712 VariableTypePointer = cur_col->strVariableTypePointer;
1713 cxxFile << (TString::Format(" %s %s;\n", cur_col->strVariableType.Data(), TempVar.Data()))
1714 .Data();
1715
1716 if (cur_col->isNullable) {
1717 cxxFile << (TString::Format(" if (stmt->IsNull(%d)) %s = nullptr;\n else\n ",
1718 count, TempVar.Data()))
1719 .Data();
1720 if (cur_col->isBinary) {
1721 cxxFile << (TString::Format(" {\n %s = nullptr;\n", TempVar.Data())).Data();
1722 cur_col = (structColumnInfo*)nextGet();
1723 cxxFile << (TString::Format(" %s %s = 0;\n", cur_col->strVariableType.Data(),
1724 cur_col->strTempVariableName.Data()))
1725 .Data();
1726 cxxFile << (TString::Format(" stmt->Get%s(%d, (void*&)%s, %s);\n }\n",
1727 StatementType.Data(), count, TempVar.Data(),
1728 cur_col->strTempVariableName.Data()))
1729 .Data();
1730 } else
1731 cxxFile << (TString::Format(" %s = new %s(stmt->Get%s(%d));\n", TempVar.Data(),
1732 VariableTypePointer.Data(), StatementType.Data(), count))
1733 .Data();
1734 } else {
1735 if (cur_col->isBinary) {
1736 cxxFile << (TString::Format(" %s = nullptr;\n", TempVar.Data())).Data();
1737 cur_col = (structColumnInfo*)nextGet();
1738 cxxFile << (TString::Format(" %s %s = 0;\n", cur_col->strVariableType.Data(),
1739 cur_col->strTempVariableName.Data()))
1740 .Data();
1741 cxxFile << (TString::Format(" stmt->Get%s(%d, (void*&)%s, %s);\n",
1742 StatementType.Data(), count, TempVar.Data(),
1743 cur_col->strTempVariableName.Data()))
1744 .Data();
1745 } else
1746 cxxFile << (TString::Format(" %s = stmt->Get%s(%d);\n", TempVar.Data(),
1747 StatementType.Data(), count))
1748 .Data();
1749 }
1750
1751 count++;
1752 }
1753
1754 } // for join table
1755
1756 cxxFile << "\n delete stmt;\n\n";
1757
1758 cxxFile << (TString::Format(" return new %s(connDb", strClassName.Data())).Data();
1759 for (vector<structColumnInfo*>::iterator it_inner = vecColumns.begin(); it_inner != vecColumns.end();
1760 ++it_inner)
1761 {
1762 structColumnInfo* current_col = *it_inner;
1763
1764 cxxFile << (TString::Format(", %s", current_col->strTempVariableName.Data())).Data();
1765 if (current_col->isBinary) {
1766 ++it_inner;
1767 current_col = *it_inner;
1768 cxxFile << (TString::Format(", %s", current_col->strColumnName.Data())).Data();
1769 }
1770 }
1771 // for join table
1772 if (isJoin) {
1773 TIter nextCol(curTableJoin->arrManualFieldNames);
1774 structColumnInfo* current_col;
1775 while ((current_col = (structColumnInfo*)nextCol()) != nullptr) {
1776 cxxFile << (TString::Format(", %s", current_col->strTempVariableName.Data())).Data();
1777 if (current_col->isBinary) {
1778 current_col = (structColumnInfo*)nextCol();
1779 cxxFile << (TString::Format(", %s", current_col->strColumnName.Data())).Data();
1780 }
1781 }
1782 } // for join table
1783 cxxFile << ");\n}\n\n";
1784 } // for(vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it)
1785 } // static get functions for unique fields
1786
1787 // CHECK RECORD EXISTS - IMPLEMENTATION
1788 cxxFile << (TString::Format("// ----- Check %s exists in the database ---------------------------\n",
1789 strTableNameSpace.Data()))
1790 .Data();
1791 cxxFile << (TString::Format("int %s::Check%sExists(", strClassName.Data(), strShortTableName.Data())).Data();
1792 count = 0;
1793 is_flag = false;
1794 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1795 structColumnInfo* cur_col = *it;
1796 if (cur_col->isUnique)
1797 is_flag = true;
1798 if (!cur_col->isPrimary)
1799 continue;
1800
1801 if (count == 0)
1802 cxxFile << (TString::Format("%s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
1803 .Data();
1804 else
1805 cxxFile << (TString::Format(", %s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
1806 .Data();
1807
1808 count++;
1809 }
1810 cxxFile << ")\n{\n";
1811
1812 cxxFile << (TString::Format(" %s* connDb = %s::Open();\n", strConnectionName.Data(),
1813 strConnectionName.Data()))
1814 .Data();
1815 cxxFile << " if (connDb == nullptr) return -1;\n\n";
1816
1817 cxxFile << " TSQLServer* db_server = connDb->GetSQLServer();\n\n";
1818 cxxFile << (TString::Format(" TString sql = TString::Format(\n \"select 1 \"\n \"from %s",
1819 strTableName.Data()))
1820 .Data();
1821 // for join table
1822 if (isJoin) {
1823 cxxFile << (TString::Format(" join %s on %s.%s=%s.%s", curTableJoin->strJoinTableName.Data(),
1824 strTableName.Data(), curTableJoin->strJoinField.strColumnName.Data(),
1825 curTableJoin->strJoinTableName.Data(),
1826 curTableJoin->strJoinField.strColumnName.Data()))
1827 .Data();
1828 } // for join table
1829 cxxFile << " \"\n \"where";
1830 count = 0;
1831 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1832 structColumnInfo* cur_col = *it;
1833 if (!cur_col->isPrimary)
1834 continue;
1835
1836 if (count > 0)
1837 cxxFile << " and";
1838
1839 if (cur_col->strStatementType == "String")
1840 cxxFile << (TString::Format(" lower(%s) = lower('%%%s')", cur_col->strColumnName.Data(),
1841 cur_col->strPrintfType.Data()))
1842 .Data();
1843 else
1844 cxxFile << (TString::Format(" %s = %%%s", cur_col->strColumnName.Data(), cur_col->strPrintfType.Data()))
1845 .Data();
1846
1847 count++;
1848 }
1849
1850 cxxFile << "\"";
1851 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1852 structColumnInfo* cur_col = *it;
1853 if (!cur_col->isPrimary)
1854 continue;
1855
1856 if (cur_col->strStatementType == "String")
1857 cxxFile << (TString::Format(", %s.Data()", cur_col->strColumnName.Data())).Data();
1858 else
1859 cxxFile << (TString::Format(", %s", cur_col->strColumnName.Data())).Data();
1860 }
1861 cxxFile << ");\n";
1862
1863 cxxFile << " TSQLStatement* stmt = db_server->Statement(sql);\n";
1864
1865 cxxFile << (TString::Format("\n // get %s from the database\n", strTableNameSpace.Data())).Data();
1866 cxxFile << " if (!stmt->Process())\n {\n";
1867 cxxFile << (TString::Format(" cout<<\"ERROR: checking %s in the database has been failed\"<<endl;\n\n",
1868 strTableNameSpace.Data()))
1869 .Data();
1870 cxxFile << " delete stmt;\n";
1871 cxxFile << " delete connDb;\n";
1872 cxxFile << " return -2;\n }\n\n";
1873
1874 cxxFile << " // store result of statement in buffer\n";
1875 cxxFile << " stmt->StoreResult();\n\n";
1876
1877 cxxFile << " // extract row\n";
1878 cxxFile << " if (!stmt->NextResultRow())\n {\n";
1879 cxxFile << " delete stmt;\n";
1880 cxxFile << " delete connDb;\n";
1881 cxxFile << " return 0;\n }\n\n";
1882
1883 cxxFile << " delete stmt;\n";
1884 cxxFile << " delete connDb;\n\n";
1885 cxxFile << " return 1;\n}\n\n";
1886
1887 // static get functions for unique fields
1888 if (is_flag) {
1889 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1890 structColumnInfo* cur_col = *it;
1891 if (!cur_col->isUnique)
1892 continue;
1893
1894 cxxFile << (TString::Format("// ----- Check %s exists in the database by unique key --------------\n",
1895 strTableNameSpace.Data()))
1896 .Data();
1897 cxxFile << (TString::Format("int %s::Check%sExists(%s %s)\n{\n", strClassName.Data(),
1898 strShortTableName.Data(), cur_col->strVariableType.Data(),
1899 cur_col->strColumnName.Data()))
1900 .Data();
1901
1902 cxxFile << (TString::Format(" %s* connDb = %s::Open();\n", strConnectionName.Data(),
1903 strConnectionName.Data()))
1904 .Data();
1905 cxxFile << " if (connDb == nullptr) return -1;\n\n";
1906
1907 cxxFile << " TSQLServer* db_server = connDb->GetSQLServer();\n\n";
1908 cxxFile << (TString::Format(
1909 " TString sql = TString::Format(\n \"select 1 \"\n \"from %s",
1910 strTableName.Data()))
1911 .Data();
1912 // for join table
1913 if (isJoin) {
1914 cxxFile << (TString::Format(" join %s on %s.%s=%s.%s", curTableJoin->strJoinTableName.Data(),
1915 strTableName.Data(), curTableJoin->strJoinField.strColumnName.Data(),
1916 curTableJoin->strJoinTableName.Data(),
1917 curTableJoin->strJoinField.strColumnName.Data()))
1918 .Data();
1919 } // for join table
1920 if (cur_col->strStatementType == "String")
1921 cxxFile << (TString::Format(" \"\n \"where lower(%s) = lower('%%%s')\", %s.Data());\n",
1922 cur_col->strColumnName.Data(), cur_col->strPrintfType.Data(),
1923 cur_col->strColumnName.Data()))
1924 .Data();
1925 else
1926 cxxFile << (TString::Format(" \"\n \"where %s = %%%s\", %s);\n",
1927 cur_col->strColumnName.Data(), cur_col->strPrintfType.Data(),
1928 cur_col->strColumnName.Data()))
1929 .Data();
1930
1931 cxxFile << " TSQLStatement* stmt = db_server->Statement(sql);\n";
1932
1933 cxxFile << (TString::Format("\n // get %s from the database\n", strTableNameSpace.Data())).Data();
1934 cxxFile << " if (!stmt->Process())\n {\n";
1935 cxxFile << (TString::Format(
1936 " cout<<\"ERROR: getting %s from the database has been failed\"<<endl;\n\n",
1937 strTableNameSpace.Data()))
1938 .Data();
1939 cxxFile << " delete stmt;\n";
1940 cxxFile << " delete connDb;\n";
1941 cxxFile << " return -2;\n }\n\n";
1942
1943 cxxFile << " // store result of statement in buffer\n";
1944 cxxFile << " stmt->StoreResult();\n\n";
1945
1946 cxxFile << " // extract row\n";
1947 cxxFile << " if (!stmt->NextResultRow())\n {\n";
1948 cxxFile << " delete stmt;\n";
1949 cxxFile << " delete connDb;\n";
1950 cxxFile << " return 0;\n }\n\n";
1951
1952 cxxFile << " delete stmt;\n";
1953 cxxFile << " delete connDb;\n\n";
1954 cxxFile << " return 1;\n}\n\n";
1955 } // for(vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it)
1956 } // static get functions for Unique fields
1957
1958 // DELETE RECORD - IMPLEMENTATION
1959 cxxFile << (TString::Format("// ----- Delete %s from the database ---------------------------\n",
1960 strTableNameSpace.Data()))
1961 .Data();
1962 cxxFile << (TString::Format("int %s::Delete%s(", strClassName.Data(), strShortTableName.Data())).Data();
1963 count = 0;
1964 is_flag = false;
1965 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1966 structColumnInfo* cur_col = *it;
1967 if (cur_col->isUnique)
1968 is_flag = true;
1969 if (!cur_col->isPrimary)
1970 continue;
1971
1972 if (count == 0)
1973 cxxFile << (TString::Format("%s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
1974 .Data();
1975 else
1976 cxxFile << (TString::Format(", %s %s", cur_col->strVariableType.Data(), cur_col->strColumnName.Data()))
1977 .Data();
1978
1979 count++;
1980 }
1981 cxxFile << ")\n{\n";
1982
1983 cxxFile << (TString::Format(" %s* connDb = %s::Open();\n", strConnectionName.Data(),
1984 strConnectionName.Data()))
1985 .Data();
1986 cxxFile << " if (connDb == nullptr) return -1;\n\n";
1987
1988 cxxFile << " TSQLServer* db_server = connDb->GetSQLServer();\n\n";
1989 cxxFile << (TString::Format(" TString sql = TString::Format(\n \"delete from %s \"\n \"where",
1990 strTableName.Data()))
1991 .Data();
1992 count = 0;
1993 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
1994 structColumnInfo* cur_col = *it;
1995 if (!cur_col->isPrimary)
1996 continue;
1997
1998 if (count > 0)
1999 cxxFile << " and";
2000
2001 if (currentDBMS == 0) {
2002 if (cur_col->strStatementType == "String")
2003 cxxFile << (TString::Format(" lower(%s) = lower(?)", cur_col->strColumnName.Data())).Data();
2004 else
2005 cxxFile << (TString::Format(" %s = ?", cur_col->strColumnName.Data())).Data();
2006 } else if (currentDBMS == 1) {
2007 if (cur_col->strStatementType == "String")
2008 cxxFile << (TString::Format(" lower(%s) = lower($%d)", cur_col->strColumnName.Data(), count + 1))
2009 .Data();
2010 else
2011 cxxFile << (TString::Format(" %s = $%d", cur_col->strColumnName.Data(), count + 1)).Data();
2012 }
2013
2014 count++;
2015 }
2016 cxxFile << "\");\n";
2017
2018 cxxFile << " TSQLStatement* stmt = db_server->Statement(sql);\n\n";
2019
2020 cxxFile << " stmt->NextIteration();\n";
2021 count = 0;
2022 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
2023 structColumnInfo* cur_col = *it;
2024 if (!cur_col->isPrimary)
2025 continue;
2026
2027 cxxFile << (TString::Format(" stmt->Set%s(%d, %s);\n", cur_col->strStatementType.Data(), count,
2028 cur_col->strColumnName.Data()))
2029 .Data();
2030 count++;
2031 }
2032
2033 cxxFile << (TString::Format("\n // delete %s from the dataBase\n", strTableNameSpace.Data())).Data();
2034 cxxFile << " if (!stmt->Process())\n {\n";
2035 cxxFile << (TString::Format(" cout<<\"ERROR: deleting %s from the dataBase has been failed\"<<endl;\n\n",
2036 strTableNameSpace.Data()))
2037 .Data();
2038 cxxFile << " delete stmt;\n";
2039 cxxFile << " delete connDb;\n";
2040 cxxFile << " return -2;\n }\n\n";
2041
2042 cxxFile << " delete stmt;\n";
2043 cxxFile << " delete connDb;\n";
2044 cxxFile << " return 0;\n}\n\n";
2045
2046 // static Delete functions for unique fields
2047 if (is_flag) {
2048 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
2049 structColumnInfo* cur_col = *it;
2050 if (!cur_col->isUnique)
2051 continue;
2052
2053 cxxFile << (TString::Format("// ----- Delete %s from the database by unique key --------------\n",
2054 strTableNameSpace.Data()))
2055 .Data();
2056 cxxFile << (TString::Format("int %s::Delete%s(%s %s)\n{\n", strClassName.Data(),
2057 strShortTableName.Data(), cur_col->strVariableType.Data(),
2058 cur_col->strColumnName.Data()))
2059 .Data();
2060
2061 cxxFile << (TString::Format(" %s* connDb = %s::Open();\n", strConnectionName.Data(),
2062 strConnectionName.Data()))
2063 .Data();
2064 cxxFile << " if (connDb == nullptr) return -1;\n\n";
2065
2066 cxxFile << " TSQLServer* db_server = connDb->GetSQLServer();\n\n";
2067
2068 if (currentDBMS == 0) {
2069 if (cur_col->strStatementType == "String")
2070 cxxFile << (TString::Format(" TString sql = TString::Format(\n \"delete from %s \"\n "
2071 " \"where lower(%s) = lower(?)\");\n",
2072 strTableName.Data(), cur_col->strColumnName.Data()))
2073 .Data();
2074 else
2075 cxxFile << (TString::Format(" TString sql = TString::Format(\n \"delete from %s \"\n "
2076 " \"where %s = ?\");\n",
2077 strTableName.Data(), cur_col->strColumnName.Data()))
2078 .Data();
2079 } else if (currentDBMS == 1) {
2080 if (cur_col->strStatementType == "String")
2081 cxxFile << (TString::Format(" TString sql = TString::Format(\n \"delete from %s \"\n "
2082 " \"where lower(%s) = lower($1)\");\n",
2083 strTableName.Data(), cur_col->strColumnName.Data()))
2084 .Data();
2085 else
2086 cxxFile << (TString::Format(" TString sql = TString::Format(\n \"delete from %s \"\n "
2087 " \"where %s = $1\");\n",
2088 strTableName.Data(), cur_col->strColumnName.Data()))
2089 .Data();
2090 }
2091
2092 cxxFile << " TSQLStatement* stmt = db_server->Statement(sql);\n\n";
2093
2094 cxxFile << " stmt->NextIteration();\n";
2095 cxxFile << (TString::Format(" stmt->Set%s(0, %s);\n", cur_col->strStatementType.Data(),
2096 cur_col->strColumnName.Data()))
2097 .Data();
2098
2099 cxxFile << (TString::Format("\n // delete %s from the dataBase\n", strTableNameSpace.Data())).Data();
2100 cxxFile << " if (!stmt->Process())\n {\n";
2101 cxxFile << (TString::Format(
2102 " cout<<\"ERROR: deleting %s from the database has been failed\"<<endl;\n\n",
2103 strTableNameSpace.Data()))
2104 .Data();
2105 cxxFile << " delete stmt;\n";
2106 cxxFile << " delete connDb;\n";
2107 cxxFile << " return -2;\n }\n\n";
2108
2109 cxxFile << " delete stmt;\n";
2110 cxxFile << " delete connDb;\n";
2111 cxxFile << " return 0;\n}\n\n";
2112 } // for(vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it)
2113 } // static Delete functions for unique fields
2114
2115 // PRINT ALL ROWS - IMPLEMENTATION
2116 cxxFile << (TString::Format("// ----- Print all '%ss' ---------------------------------\n",
2117 strTableNameSpace.Data()))
2118 .Data();
2119 cxxFile << (TString::Format("int %s::PrintAll()\n{\n", strClassName.Data())).Data();
2120
2121 cxxFile << (TString::Format(" %s* connDb = %s::Open();\n", strConnectionName.Data(),
2122 strConnectionName.Data()))
2123 .Data();
2124 cxxFile << " if (connDb == nullptr) return -1;\n\n";
2125
2126 cxxFile << " TSQLServer* db_server = connDb->GetSQLServer();\n\n";
2127 cxxFile << " TString sql = TString::Format(\n \"select";
2128 count = 0;
2129 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
2130 structColumnInfo* cur_col = *it;
2131 if (count == 0)
2132 cxxFile << (TString::Format(" %s", cur_col->strColumnName.Data())).Data();
2133 else
2134 cxxFile << (TString::Format(", %s", cur_col->strColumnName.Data())).Data();
2135
2136 count++;
2137 if (cur_col->isBinary)
2138 ++it;
2139 }
2140 // for join table
2141 if (isJoin) {
2142 TIter nextCol(curTableJoin->arrManualFieldNames);
2143 structColumnInfo* cur_col;
2144 while ((cur_col = (structColumnInfo*)nextCol()) != nullptr) {
2145 if (count == 0)
2146 cxxFile << (TString::Format(" %s", cur_col->strColumnName.Data())).Data();
2147 else
2148 cxxFile << (TString::Format(", %s", cur_col->strColumnName.Data())).Data();
2149
2150 count++;
2151 if (cur_col->isBinary)
2152 nextCol();
2153 }
2154 } // for join table
2155 cxxFile << (TString::Format(" \"\n \"from %s\");\n", strTableName.Data())).Data();
2156
2157 cxxFile << " TSQLStatement* stmt = db_server->Statement(sql);\n";
2158
2159 cxxFile << (TString::Format("\n // get all '%ss' from the database\n", strTableNameSpace.Data())).Data();
2160 cxxFile << " if (!stmt->Process())\n {\n";
2161 cxxFile << (TString::Format(
2162 " cout<<\"ERROR: getting all '%ss' from the dataBase has been failed\"<<endl;\n\n",
2163 strTableNameSpace.Data()))
2164 .Data();
2165 cxxFile << " delete stmt;\n";
2166 cxxFile << " delete connDb;\n";
2167 cxxFile << " return -2;\n }\n\n";
2168
2169 cxxFile << " // store result of statement in buffer\n";
2170 cxxFile << " stmt->StoreResult();\n\n";
2171
2172 cxxFile << " // print rows\n";
2173 cxxFile << (TString::Format(" cout<<\"Table '%s':\"<<endl;\n", strTableName.Data())).Data();
2174 cxxFile << " while (stmt->NextResultRow())\n {\n";
2175
2176 count = 0;
2177 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
2178 structColumnInfo* cur_col = *it;
2179
2180 cxxFile << " cout<<\"";
2181 if (count > 0)
2182 cxxFile << ", ";
2183
2184 TString StatementType = cur_col->strStatementType, TempVar = cur_col->strTempVariableName;
2185 cxxFile << (TString::Format("%s: \";\n", cur_col->strColumnName.Data())).Data();
2186
2187 if (cur_col->isNullable) {
2188 cxxFile << (TString::Format(" if (stmt->IsNull(%d)) cout<<\"nullptr\";\n else\n ",
2189 count))
2190 .Data();
2191 if (cur_col->isBinary) {
2192 cxxFile << (TString::Format(" %s %s;\n", cur_col->strVariableType.Data(), TempVar.Data()))
2193 .Data();
2194 cxxFile << (TString::Format(" {\n %s = nullptr;\n", TempVar.Data())).Data();
2195 ++it;
2196 cur_col = *it;
2197 cxxFile << (TString::Format(" %s %s=0;\n", cur_col->strVariableType.Data(),
2198 cur_col->strTempVariableName.Data()))
2199 .Data();
2200 cxxFile << (TString::Format(" stmt->Get%s(%d, (void*&)%s, %s);\n }\n",
2201 StatementType.Data(), count, TempVar.Data(),
2202 cur_col->strTempVariableName.Data()))
2203 .Data();
2204 cxxFile << (TString::Format(" cout<<(void*)%s<<\", binary size: \"<<%s;\n",
2205 TempVar.Data(), cur_col->strTempVariableName.Data()))
2206 .Data();
2207 } else {
2208 cxxFile << (TString::Format(" cout<<stmt->Get%s(%d)", StatementType.Data(), count)).Data();
2209 if (cur_col->isDateTime)
2210 cxxFile << ".AsSQLString()";
2211 if (cur_col->isTimeStamp)
2212 cxxFile << ".AsString(\"s\")";
2213 cxxFile << ";\n";
2214 }
2215 } else {
2216 if (cur_col->isBinary) {
2217 cxxFile << (TString::Format(" %s %s = nullptr;\n", cur_col->strVariableType.Data(),
2218 TempVar.Data()))
2219 .Data();
2220 ++it;
2221 cur_col = *it;
2222 cxxFile << (TString::Format(" %s %s=0;\n", cur_col->strVariableType.Data(),
2223 cur_col->strTempVariableName.Data()))
2224 .Data();
2225 cxxFile << (TString::Format(" stmt->Get%s(%d, (void*&)%s, %s);\n", StatementType.Data(),
2226 count, TempVar.Data(), cur_col->strTempVariableName.Data()))
2227 .Data();
2228 cxxFile << (TString::Format(" cout<<(void*)%s<<\", binary size: \"<<%s;\n", TempVar.Data(),
2229 cur_col->strTempVariableName.Data()))
2230 .Data();
2231 } else {
2232 cxxFile << (TString::Format(" cout<<(stmt->Get%s(%d))", StatementType.Data(), count)).Data();
2233 if (cur_col->isDateTime)
2234 cxxFile << ".AsSQLString()";
2235 if (cur_col->isTimeStamp)
2236 cxxFile << ".AsString(\"s\")";
2237 cxxFile << ";\n";
2238 }
2239 }
2240
2241 count++;
2242 }
2243 // for join table
2244 if (isJoin) {
2245 TIter nextCol(curTableJoin->arrManualFieldNames);
2246 structColumnInfo* cur_col;
2247 while ((cur_col = (structColumnInfo*)nextCol()) != nullptr) {
2248 cxxFile << " cout<<\"";
2249 if (count > 0)
2250 cxxFile << ", ";
2251
2252 TString StatementType = cur_col->strStatementType, TempVar = cur_col->strTempVariableName;
2253 cxxFile << (TString::Format("%s: \";\n", cur_col->strColumnName.Data())).Data();
2254
2255 if (cur_col->isNullable) {
2256 cxxFile << (TString::Format(" if (stmt->IsNull(%d)) cout<<\"nullptr\";\n else\n ",
2257 count))
2258 .Data();
2259 if (cur_col->isBinary) {
2260 cxxFile << (TString::Format(" %s %s;\n", cur_col->strVariableType.Data(),
2261 TempVar.Data()))
2262 .Data();
2263 cxxFile << (TString::Format(" {\n %s = nullptr;\n", TempVar.Data())).Data();
2264 cur_col = (structColumnInfo*)nextCol();
2265 cxxFile << (TString::Format(" %s %s=0;\n", cur_col->strVariableType.Data(),
2266 cur_col->strTempVariableName.Data()))
2267 .Data();
2268 cxxFile << (TString::Format(" stmt->Get%s(%d, (void*&)%s, %s);\n }\n",
2269 StatementType.Data(), count, TempVar.Data(),
2270 cur_col->strTempVariableName.Data()))
2271 .Data();
2272 cxxFile << (TString::Format(" cout<<(void*)%s<<\", binary size: \"<<%s;\n",
2273 TempVar.Data(), cur_col->strTempVariableName.Data()))
2274 .Data();
2275 } else {
2276 cxxFile
2277 << (TString::Format(" cout<<stmt->Get%s(%d)", StatementType.Data(), count)).Data();
2278 if (cur_col->isDateTime)
2279 cxxFile << ".AsSQLString()";
2280 if (cur_col->isTimeStamp)
2281 cxxFile << ".AsString(\"s\")";
2282 cxxFile << ";\n";
2283 }
2284 } else {
2285 if (cur_col->isBinary) {
2286 cxxFile << (TString::Format(" %s %s = nullptr;\n", cur_col->strVariableType.Data(),
2287 TempVar.Data()))
2288 .Data();
2289 cur_col = (structColumnInfo*)nextCol();
2290 cxxFile << (TString::Format(" %s %s=0;\n", cur_col->strVariableType.Data(),
2291 cur_col->strTempVariableName.Data()))
2292 .Data();
2293 cxxFile << (TString::Format(" stmt->Get%s(%d, (void*&)%s, %s);\n", StatementType.Data(),
2294 count, TempVar.Data(), cur_col->strTempVariableName.Data()))
2295 .Data();
2296 cxxFile << (TString::Format(" cout<<(void*)%s<<\", binary size: \"<<%s;\n",
2297 TempVar.Data(), cur_col->strTempVariableName.Data()))
2298 .Data();
2299 } else {
2300 cxxFile
2301 << (TString::Format(" cout<<(stmt->Get%s(%d))", StatementType.Data(), count)).Data();
2302 if (cur_col->isDateTime)
2303 cxxFile << ".AsSQLString()";
2304 if (cur_col->isTimeStamp)
2305 cxxFile << ".AsString(\"s\")";
2306 cxxFile << ";\n";
2307 }
2308 }
2309
2310 count++;
2311 }
2312 } // for join table
2313
2314 cxxFile << " cout<<\".\"<<endl;\n }\n\n";
2315
2316 cxxFile << " delete stmt;\n";
2317 cxxFile << " delete connDb;\n\n";
2318 cxxFile << " return 0;\n}\n\n";
2319
2320 // SETTERS FUNCTIONS - IMPLEMENTATION
2321 structColumnInfo* temp_col;
2322 cxxFile << "\n// Setters functions\n";
2323 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
2324 structColumnInfo* cur_col = *it;
2325 if (cur_col->isIdentity)
2326 continue;
2327
2328 if (!cur_col->isBinary)
2329 cxxFile << (TString::Format("int %s::Set%s(%s %s)\n{\n", strClassName.Data(),
2330 cur_col->strShortVariableName.Data(), cur_col->strVariableType.Data(),
2331 cur_col->strColumnName.Data()))
2332 .Data();
2333 else {
2334 cxxFile << (TString::Format("int %s::Set%s(%s %s, ", strClassName.Data(),
2335 cur_col->strShortVariableName.Data(), cur_col->strVariableType.Data(),
2336 cur_col->strColumnName.Data()))
2337 .Data();
2338 ++it;
2339 temp_col = *it;
2340 cxxFile << (TString::Format("%s %s)\n{\n", temp_col->strVariableType.Data(),
2341 temp_col->strColumnName.Data()))
2342 .Data();
2343 }
2344
2345 cxxFile << " if (!connectionDB)\n {\n cout<<\"CRITICAL ERROR: Connection object is "
2346 "null\"<<endl;\n return -1;\n }\n\n";
2347
2348 cxxFile << " TSQLServer* db_server = connectionDB->GetSQLServer();\n\n";
2349
2350 if (currentDBMS == 0) {
2351 cxxFile << (TString::Format(" TString sql = TString::Format(\n \"update %s \"\n \"set "
2352 "%s = ? \"\n \"where",
2353 strTableName.Data(), cur_col->strColumnName.Data()))
2354 .Data();
2355 } else if (currentDBMS == 1) {
2356 cxxFile << (TString::Format(" TString sql = TString::Format(\n \"update %s \"\n \"set "
2357 "%s = $1 \"\n \"where",
2358 strTableName.Data(), cur_col->strColumnName.Data()))
2359 .Data();
2360 }
2361 count = 0;
2362 for (vector<structColumnInfo*>::iterator it_inner = vecColumns.begin(); it_inner != vecColumns.end();
2363 ++it_inner)
2364 {
2365 structColumnInfo* current_col = *it_inner;
2366 if (!current_col->isPrimary)
2367 continue;
2368
2369 if (currentDBMS == 0) {
2370 if (count == 0)
2371 cxxFile << (TString::Format(" %s = ?", current_col->strColumnName.Data())).Data();
2372 else
2373 cxxFile << (TString::Format(" and %s = ?", current_col->strColumnName.Data())).Data();
2374 } else if (currentDBMS == 1) {
2375 if (count == 0)
2376 cxxFile << (TString::Format(" %s = $2", current_col->strColumnName.Data())).Data();
2377 else
2378 cxxFile
2379 << (TString::Format(" and %s = $%d", current_col->strColumnName.Data(), count + 2)).Data();
2380 }
2381
2382 count++;
2383 }
2384 cxxFile << "\");\n";
2385
2386 cxxFile << " TSQLStatement* stmt = db_server->Statement(sql);\n\n";
2387
2388 cxxFile << " stmt->NextIteration();\n";
2389
2390 if (cur_col->isNullable)
2391 cxxFile << (TString::Format(" if (%s == nullptr)\n stmt->SetNull(0);\n else\n ",
2392 cur_col->strColumnName.Data()))
2393 .Data();
2394
2395 if (!cur_col->isBinary)
2396 cxxFile << (TString::Format(" stmt->Set%s(0, %s);\n", cur_col->strStatementType.Data(),
2397 cur_col->strColumnPointer.Data()))
2398 .Data();
2399 else {
2400 cxxFile << (TString::Format(" stmt->Set%s(0, %s, ", cur_col->strStatementType.Data(),
2401 cur_col->strColumnName.Data()))
2402 .Data();
2403 cxxFile << (TString::Format("%s, 0x4000000);\n", temp_col->strColumnName.Data())).Data();
2404 }
2405
2406 count = 1;
2407 for (vector<structColumnInfo*>::iterator it_inner = vecColumns.begin(); it_inner != vecColumns.end();
2408 ++it_inner)
2409 {
2410 structColumnInfo* current_col = *it_inner;
2411 if (!current_col->isPrimary)
2412 continue;
2413
2414 cxxFile << (TString::Format(" stmt->Set%s(%d, %s);\n", current_col->strStatementType.Data(), count,
2415 current_col->strVariableName.Data()))
2416 .Data();
2417 count++;
2418 }
2419
2420 cxxFile << "\n // write new value to the database\n";
2421 cxxFile << " if (!stmt->Process())\n {\n";
2422 cxxFile << (TString::Format(
2423 " cout<<\"ERROR: updating information about %s has been failed\"<<endl;\n\n",
2424 strTableNameSpace.Data()))
2425 .Data();
2426 cxxFile << " delete stmt;\n";
2427 cxxFile << " return -2;\n }\n\n";
2428
2429 if (cur_col->isNullable)
2430 cxxFile << (TString::Format(" if (%s)\n delete %s;\n", cur_col->strVariableName.Data(),
2431 cur_col->strVariableName.Data()))
2432 .Data();
2433 if (cur_col->isBinary)
2434 cxxFile << (TString::Format(" if (%s)\n delete [] %s;\n", cur_col->strVariableName.Data(),
2435 cur_col->strVariableName.Data()))
2436 .Data();
2437
2438 if (cur_col->isNullable) {
2439 cxxFile << (TString::Format(" if (%s == nullptr) %s = nullptr;\n else\n ",
2440 cur_col->strColumnName.Data(), cur_col->strVariableName.Data()))
2441 .Data();
2442 if (cur_col->isBinary) {
2443 cxxFile << (TString::Format(" {\n %s %s = %s;\n", temp_col->strVariableType.Data(),
2444 temp_col->strVariableName.Data(), cur_col->strColumnName.Data()))
2445 .Data();
2446 cxxFile << (TString::Format(" %s = new %s[%s];\n", cur_col->strVariableName.Data(),
2447 cur_col->strVariableTypePointer.Data(),
2448 temp_col->strVariableName.Data()))
2449 .Data();
2450 cxxFile << (TString::Format(" memcpy(%s, %s, %s);\n }\n", cur_col->strVariableName.Data(),
2451 cur_col->strColumnName.Data(), temp_col->strVariableName.Data()))
2452 .Data();
2453 } else
2454 cxxFile << (TString::Format(" %s = new %s(*%s);\n", cur_col->strVariableName.Data(),
2455 cur_col->strVariableTypePointer.Data(), cur_col->strColumnName.Data()))
2456 .Data();
2457 } else {
2458 if (cur_col->isBinary) {
2459 cxxFile << (TString::Format(" %s = %s;\n", temp_col->strVariableName.Data(),
2460 temp_col->strColumnName.Data()))
2461 .Data();
2462 cxxFile << (TString::Format(" %s = new %s[%s];\n", cur_col->strVariableName.Data(),
2463 cur_col->strVariableTypePointer.Data(),
2464 temp_col->strVariableName.Data()))
2465 .Data();
2466 cxxFile << (TString::Format(" memcpy(%s, %s, %s);\n", cur_col->strVariableName.Data(),
2467 cur_col->strColumnName.Data(), temp_col->strVariableName.Data()))
2468 .Data();
2469 } else
2470 cxxFile << (TString::Format(" %s = %s;\n", cur_col->strVariableName.Data(),
2471 cur_col->strColumnName.Data()))
2472 .Data();
2473 }
2474
2475 cxxFile << "\n delete stmt;\n";
2476 cxxFile << " return 0;\n}\n\n";
2477 } // setters functions - implementation
2478
2479 // PRINT VALUES - IMPLEMENTATION
2480 cxxFile << (TString::Format("// ----- Print current %s ---------------------------------------\n",
2481 strTableNameSpace.Data()))
2482 .Data();
2483 cxxFile << (TString::Format("void %s::Print()\n{\n", strClassName.Data())).Data();
2484
2485 cxxFile << (TString::Format(" cout<<\"Table '%s'\";\n cout", strTableName.Data())).Data();
2486 for (vector<structColumnInfo*>::iterator it = vecColumns.begin(); it != vecColumns.end(); ++it) {
2487 structColumnInfo* cur_col = *it;
2488
2489 if (cur_col->isBinary) {
2490 cxxFile << (TString::Format("<<\". %s: \"<<(void*)%s", cur_col->strColumnName.Data(),
2491 cur_col->strVariableName.Data()))
2492 .Data();
2493 ++it;
2494 cur_col = *it;
2495 cxxFile << (TString::Format("<<\", binary size: \"<<%s", cur_col->strVariableName.Data())).Data();
2496 } else {
2497 if (cur_col->isNullable) {
2498 if (cur_col->isDateTime)
2499 cxxFile << (TString::Format("<<\". %s: \"<<(%s == nullptr? \"nullptr\": (*%s).AsSQLString())",
2500 cur_col->strColumnName.Data(), cur_col->strVariableName.Data(),
2501 cur_col->strVariableName.Data()))
2502 .Data();
2503 else {
2504 if (cur_col->isTimeStamp)
2505 cxxFile << (TString::Format(
2506 "<<\". %s: \"<<(%s == nullptr? \"nullptr\": (*%s).AsString(\"s\"))",
2507 cur_col->strColumnName.Data(), cur_col->strVariableName.Data(),
2508 cur_col->strVariableName.Data()))
2509 .Data();
2510 else {
2511 if (cur_col->strPrintfType == "s")
2512 cxxFile << (TString::Format("<<\". %s: \"<<(%s == nullptr? \"nullptr\": *%s)",
2513 cur_col->strColumnName.Data(),
2514 cur_col->strVariableName.Data(),
2515 cur_col->strVariableName.Data()))
2516 .Data();
2517 else
2518 cxxFile << (TString::Format(
2519 "<<\". %s: \"<<(%s == nullptr? \"nullptr\": TString::Format(\"%%%s\", "
2520 "*%s))",
2521 cur_col->strColumnName.Data(), cur_col->strVariableName.Data(),
2522 cur_col->strPrintfType.Data(), cur_col->strVariableName.Data()))
2523 .Data();
2524 }
2525 }
2526 } else {
2527 cxxFile << (TString::Format("<<\". %s: \"<<%s", cur_col->strColumnName.Data(),
2528 cur_col->strVariableName.Data()))
2529 .Data();
2530 if (cur_col->isDateTime)
2531 cxxFile << ".AsSQLString()";
2532 if (cur_col->isTimeStamp)
2533 cxxFile << ".AsString(\"s\")";
2534 }
2535 }
2536 }
2537 // for join table
2538 if (isJoin) {
2539 TIter nextCol(curTableJoin->arrManualFieldNames);
2540 structColumnInfo* cur_col;
2541 while ((cur_col = (structColumnInfo*)nextCol()) != nullptr) {
2542 if (cur_col->isBinary) {
2543 cxxFile << (TString::Format("<<\". %s: \"<<(void*)%s", cur_col->strColumnName.Data(),
2544 cur_col->strVariableName.Data()))
2545 .Data();
2546 cur_col = (structColumnInfo*)nextCol();
2547 cxxFile << (TString::Format("<<\", binary size: \"<<%s", cur_col->strVariableName.Data())).Data();
2548 } else {
2549 if (cur_col->isNullable) {
2550 if (cur_col->isDateTime)
2551 cxxFile << (TString::Format(
2552 "<<\". %s: \"<<(%s == nullptr? \"nullptr\": (*%s).AsSQLString())",
2553 cur_col->strColumnName.Data(), cur_col->strVariableName.Data(),
2554 cur_col->strVariableName.Data()))
2555 .Data();
2556 else {
2557 if (cur_col->isTimeStamp)
2558 cxxFile << (TString::Format(
2559 "<<\". %s: \"<<(%s == nullptr? \"nullptr\": (*%s).AsString(\"s\"))",
2560 cur_col->strColumnName.Data(), cur_col->strVariableName.Data(),
2561 cur_col->strVariableName.Data()))
2562 .Data();
2563 else {
2564 if (cur_col->strPrintfType == "s")
2565 cxxFile << (TString::Format("<<\". %s: \"<<(%s == nullptr? \"nullptr\": *%s)",
2566 cur_col->strColumnName.Data(),
2567 cur_col->strVariableName.Data(),
2568 cur_col->strVariableName.Data()))
2569 .Data();
2570 else
2571 cxxFile << (TString::Format(
2572 "<<\". %s: \"<<(%s == nullptr? \"nullptr\": "
2573 "TString::Format(\"%%%s\", *%s))",
2574 cur_col->strColumnName.Data(), cur_col->strVariableName.Data(),
2575 cur_col->strPrintfType.Data(), cur_col->strVariableName.Data()))
2576 .Data();
2577 }
2578 }
2579 } else {
2580 cxxFile << (TString::Format("<<\". %s: \"<<%s", cur_col->strColumnName.Data(),
2581 cur_col->strVariableName.Data()))
2582 .Data();
2583 if (cur_col->isDateTime)
2584 cxxFile << ".AsSQLString()";
2585 if (cur_col->isTimeStamp)
2586 cxxFile << ".AsString(\"s\")";
2587 }
2588 }
2589 }
2590 } // for join table
2591 cxxFile << "<<endl;\n\n";
2592
2593 cxxFile << " return;\n}\n";
2594 cxxFile << "/* END OF GENERATED CLASS PART (SHOULD NOT BE CHANGED MANUALLY) */\n";
2595
2596 if (isOnlyUpdate) {
2597 string cur_line;
2598 while (getline(oldFile, cur_line)) {
2599 string trim_line = trim(cur_line);
2600 if (trim_line.substr(0, 25) == "/* END OF GENERATED CLASS")
2601 break;
2602 }
2603
2604 while (getline(oldFile, cur_line))
2605 cxxFile << cur_line << endl;
2606 }
2607
2608 cxxFile.close();
2609
2610 if (isOnlyUpdate) {
2611 oldFile.close();
2612 // delete the original file
2613 remove(strFileName);
2614 // rename temporary file to original
2615 rename(strTempFileName, strFileName);
2616 }
2617 } // cycle for all database tables
2618
2619 delete lst;
2620 if (arrTableJoin)
2621 delete arrTableJoin;
2622
2623 return 0;
2624}
int i
Definition P4_F32vec4.h:22
static int GenerateClasses(TString json_configuration_file)
a class to store JSON values
Definition json.hpp:17282
exception indicating executing a member function with a wrong type
Definition json.hpp:2972
string get_current_date()
string trim(const string &str, const string &whitespace=" \t\r")
basic_json<> json
default specialization
Definition json.hpp:3337
STL namespace.
TObjArray * arrManualFieldNames
structColumnInfo strJoinField