moving server source files to server folder
[csql.git] / patches / setunion.patch
blob55b844ce3217f9f5dd781a0de049735546ae81d7
1 Index: include/Parser.h
2 ===================================================================
3 RCS file: /cvsroot/csql/csql/include/Parser.h,v
4 retrieving revision 1.22
5 diff -r1.22 Parser.h
6 33a34
7 > SetSelectStatement,
8 120a122,127
9 > enum SubQueryType
10 > {
11 > UNION_TYPE = 1,
12 > UNION_ALL_TYPE,
13 > UNKNOWN_QUERY_TYPE = 100
14 > };
15 161a169,174
16 > class ParsedData;
17 > class ParsedDataSub {
18 > public:
19 > List parsedDataList;
20 > void append(ParsedData *data);
21 > };
22 248a262,263
23 > SubQueryType qType;
24 > ParsedData *innerParsedData;
25 251c266
26 < shouldCreateTbl=false; userNode = NULL; isWorthyToCache=false; ftype = UNKNOWN_FUNCTION;
27 ---
28 > shouldCreateTbl=false; userNode = NULL; isWorthyToCache=false; ftype = UNKNOWN_FUNCTION; qType=UNKNOWN_QUERY_TYPE; innerParsedData = NULL;
29 252a268,269
30 > void setSubQueryType(SubQueryType type) { qType = type; }
31 > void setInnerParsedData(ParsedData *data) { innerParsedData = data; }
32 397a415
33 > void print();
34 Index: include/SqlStatement.h
35 ===================================================================
36 RCS file: /cvsroot/csql/csql/include/SqlStatement.h,v
37 retrieving revision 1.36
38 diff -r1.36 SqlStatement.h
39 245c245
40 < StatementType getStmtType() { return pData.getStmtType(); }
41 ---
42 > StatementType getStmtType() { return pData->getStmtType(); }
43 285c285
44 < ParsedData pData;
45 ---
46 > ParsedData *pData;
47 Index: include/Statement.h
48 ===================================================================
49 RCS file: /cvsroot/csql/csql/include/Statement.h,v
50 retrieving revision 1.21
51 diff -r1.21 Statement.h
52 31,32c31,32
53 < void setParsedData(ParsedData *pData) { parsedData = pData; }
54 < void setDbMgr(DatabaseManager *dbmgr) { dbMgr = dbmgr; }
55 ---
56 > virtual void setParsedData(ParsedData *pData) { parsedData = pData; }
57 > virtual void setDbMgr(DatabaseManager *dbmgr) { dbMgr = dbmgr; }
58 139d138
60 211,214c210,213
61 < void *fetch();
62 < void *fetch(DbRetVal &rv);
63 < void *fetchAndPrint(bool SQL);
64 < void *next();
65 ---
66 > virtual void *fetch();
67 > virtual void *fetch(DbRetVal &rv);
68 > virtual void *fetchAndPrint(bool SQL);
69 > virtual void *next();
70 220a220,261
71 > class SetStatement : public SelStatement
72 > {
73 > public:
74 > int curStmt;
75 > SelStatement *rightStmt;
76 > bool baseRecOver;
77 > void setParsedData(ParsedData *pData);
78 > void setRightStmt(SelStatement *stmt){ rightStmt = stmt; }
79 > DbRetVal execute(int &rowsAffected);
80 > void *fetch();
81 > void *fetch(DbRetVal &rv);
82 > void *fetchAndPrint(bool SQL);
83 > void *next();
84 > void setDbMgr(DatabaseManager *dbmgr);
86 > DbRetVal setBindField(int pos, void* value);
87 > DbRetVal setShortParam(int paramNo, short value);
88 > DbRetVal setParam(int paramNo, void *value);
89 > DbRetVal setIntParam(int paramNo, int value);
90 > DbRetVal setLongParam(int paramNo, long value);
91 > DbRetVal setLongLongParam(int paramNo, long long value);
92 > DbRetVal setByteIntParam(int paramNo, ByteInt value);
93 > DbRetVal setFloatParam(int paramNo, float value);
94 > DbRetVal setDoubleParam(int paramNo, double value);
95 > DbRetVal setStringParam(int paramNo, char *value);
96 > DbRetVal setDateParam(int paramNo, Date value);
97 > DbRetVal setTimeParam(int paramNo, Time value);
98 > DbRetVal setTimeStampParam(int paramNo, TimeStamp value);
99 > DbRetVal setBinaryParam(int paramNo, void *value, int length);
100 > bool isFldNull(int pos);
101 > bool isFldNull(char *fldName);
102 > int getFldPos(char *name);
104 > DbRetVal getProjFldInfo (int projpos, FieldInfo *&fInfo);
105 > DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
107 > DbRetVal close();
108 > DbRetVal resolve();
109 > SetStatement();
110 > ~SetStatement();
111 > };
113 Index: src/Makefile.am
114 ===================================================================
115 RCS file: /cvsroot/csql/csql/src/Makefile.am,v
116 retrieving revision 1.15
117 diff -r1.15 Makefile.am
119 < SUBDIRS = storage adapter gateway sqllog sqlnetwork sql cache network jdbc odbc tools
121 > SUBDIRS = storage adapter gateway sqllog sqlnetwork sql cache network jdbc odbc tools
122 Index: src/sql/DelStatement.cxx
123 ===================================================================
124 RCS file: /cvsroot/csql/csql/src/sql/DelStatement.cxx,v
125 retrieving revision 1.22
126 diff -r1.22 DelStatement.cxx
127 331c331
128 < if(!(p>=48 && p<=57 || p==45))
130 > if(!(p>=48 && p<=57 || p==45)) {
131 333a334
133 Index: src/sql/InsStatement.cxx
134 ===================================================================
135 RCS file: /cvsroot/csql/csql/src/sql/InsStatement.cxx,v
136 retrieving revision 1.28
137 diff -r1.28 InsStatement.cxx
138 368c368
139 < if(!(p>=48 && p<=57 || p==45) )
141 > if(!(p>=48 && p<=57 || p==45) ) {
142 370a371
144 Index: src/sql/Makefile.am
145 ===================================================================
146 RCS file: /cvsroot/csql/csql/src/sql/Makefile.am,v
147 retrieving revision 1.13
148 diff -r1.13 Makefile.am
149 11c11
150 < AlterTblStatement.cxx
152 > AlterTblStatement.cxx SetStatement.cxx
153 Index: src/sql/ParsedData.cxx
154 ===================================================================
155 RCS file: /cvsroot/csql/csql/src/sql/ParsedData.cxx,v
156 retrieving revision 1.35
157 diff -r1.35 ParsedData.cxx
158 613a614,631
159 > void ParsedData::print()
161 > printf("PARSED DATA - START \n");
162 > if (getTableName() != NULL) printf ("Table Name : %s\n", getTableName());
163 > printf ("Statement Type : %d\n", getStmtType());
164 > printf ("Query Type : %d\n", qType);
165 > ListIterator iter = tableNameList.getIterator();
166 > TableName *tname;
167 > while (iter.hasElement())
169 > tname = (TableName*)iter.nextElement();
170 > printf("TABLE NAME %s Alias %s\n", tname->tblName, tname->aliasName);
172 > printf ("INNER=START\n");
173 > if (innerParsedData) innerParsedData->print();
174 > printf ("INNER=END\n");
175 > printf("PARSED DATA - END \n");
177 Index: src/sql/SqlStatement.cxx
178 ===================================================================
179 RCS file: /cvsroot/csql/csql/src/sql/SqlStatement.cxx,v
180 retrieving revision 1.44
181 diff -r1.44 SqlStatement.cxx
182 39a40
183 > if (pData){ delete pData; }
184 260c261
185 < return pData.getTableNameList();
187 > return pData->getTableNameList();
188 270a272
189 > pData= new ParsedData();
190 326c328
191 < this->stmt->setParsedData(&this->pData);
193 > this->stmt->setParsedData(this->pData);
194 342c344
195 < parsedData = &pData;
197 > parsedData = pData;
198 398c400
199 < return pData.getTableName();
201 > return pData->getTableName();
202 403c405,407
203 < if ((pData.getStmtType() == SelectStatement) || (pData.getStmtType() == MetaStatement)) return true;
205 > if ((pData->getStmtType() == SelectStatement) ||
206 > (pData->getStmtType() == SetSelectStatement) ||
207 > (pData->getStmtType() == MetaStatement)) return true;
208 427c431,434
209 < if (rv == ErrAlready && pData.getStmtType() == SelectStatement )
211 > if (rv == ErrAlready && (
212 > ( pData->getStmtType() == SelectStatement ) ||
213 > ( pData->getStmtType() == SetSelectStatement )))
215 447c454,455
216 < if (pData.getStmtType() == SelectStatement ) {
218 > if (pData->getStmtType() == SelectStatement ||
219 > pData->getStmtType() == SetSelectStatement ) {
220 451c459
221 < else if(pData.getStmtType() == MetaStatement){
223 > else if(pData->getStmtType() == MetaStatement){
224 469c477,478
225 < if (pData.getStmtType() == SelectStatement ) {
227 > if (pData->getStmtType() == SelectStatement ||
228 > pData->getStmtType() == SetSelectStatement ) {
229 473c482
230 < else if(pData.getStmtType() == MetaStatement){
232 > else if(pData->getStmtType() == MetaStatement){
233 490c499,500
234 < if (pData.getStmtType() != SelectStatement) return NULL;
236 > if (pData->getStmtType() != SelectStatement &&
237 > pData->getStmtType() != SetSelectStatement ) return NULL;
238 505c515,516
239 < if (pData.getStmtType() == SelectStatement ) {
241 > if (pData->getStmtType() == SelectStatement ||
242 > pData->getStmtType() == SetSelectStatement ) {
243 509c520
244 < else if(pData.getStmtType() == MetaStatement){
246 > else if(pData->getStmtType() == MetaStatement){
247 517c528,529
248 < if (pData.getStmtType() == SelectStatement ) {
250 > if (pData->getStmtType() == SelectStatement ||
251 > pData->getStmtType() == SetSelectStatement) {
252 521c533
253 < else if(pData.getStmtType() == MetaStatement){
255 > else if(pData->getStmtType() == MetaStatement){
256 530c542,543
257 < if (pData.getStmtType() != SelectStatement) return 0;
259 > if (pData->getStmtType() != SelectStatement &&
260 > pData->getStmtType() != SetSelectStatement ) return 0;
261 536c549,550
262 < if (pData.getStmtType() != SelectStatement) return 0;
264 > if (pData->getStmtType() != SelectStatement &&
265 > pData->getStmtType() != SetSelectStatement ) return 0;
266 542c556,557
267 < if (pData.getStmtType() == SelectStatement ) {
269 > if (pData->getStmtType() == SelectStatement ||
270 > pData->getStmtType() == SetSelectStatement ) {
271 547c562
272 < else if(pData.getStmtType() == MetaStatement){
274 > else if(pData->getStmtType() == MetaStatement){
275 557c572
276 < //if (pData.getStmtType() != SelectStatement) return 0;
278 > //if (pData->getStmtType() != SelectStatement) return 0;
279 564c579,580
280 < if (pData.getStmtType() == SelectStatement ) {
282 > if (pData->getStmtType() == SelectStatement ||
283 > pData->getStmtType() == SetSelectStatement ) {
284 568c584
285 < else if(pData.getStmtType() == MetaStatement){
287 > else if(pData->getStmtType() == MetaStatement){
288 577c593,594
289 < if (pData.getStmtType() == SelectStatement ) {
291 > if (pData->getStmtType() == SelectStatement ||
292 > pData->getStmtType() == SetSelectStatement ) {
293 581c598
294 < else if(pData.getStmtType() == MetaStatement){
296 > else if(pData->getStmtType() == MetaStatement){
297 589c606,607
298 < if (pData.getStmtType() == SelectStatement ) {
300 > if (pData->getStmtType() == SelectStatement ||
301 > pData->getStmtType() == SetSelectStatement ) {
302 593c611
303 < else if(pData.getStmtType() == MetaStatement){
305 > else if(pData->getStmtType() == MetaStatement){
306 602c620,621
307 < if (pData.getStmtType() == SelectStatement ) {
309 > if (pData->getStmtType() == SelectStatement ||
310 > pData->getStmtType() == SetSelectStatement ) {
311 606c625
312 < else if(pData.getStmtType() == MetaStatement){
314 > else if(pData->getStmtType() == MetaStatement){
315 614c633,634
316 < if (pData.getStmtType() == SelectStatement ) {
318 > if (pData->getStmtType() == SelectStatement ||
319 > pData->getStmtType() == SetSelectStatement ) {
320 618c638
321 < else if(pData.getStmtType() == MetaStatement){
323 > else if(pData->getStmtType() == MetaStatement){
324 627c647,648
325 < if (pData.getStmtType() == SelectStatement ) {
327 > if (pData->getStmtType() == SelectStatement ||
328 > pData->getStmtType() == SetSelectStatement ) {
329 631c652
330 < else if(pData.getStmtType() == MetaStatement){
332 > else if(pData->getStmtType() == MetaStatement){
333 640c661,662
334 < if (pData.getStmtType() == SelectStatement ) {
336 > if (pData->getStmtType() == SelectStatement ||
337 > pData->getStmtType() == SetSelectStatement ) {
338 644c666
339 < else if(pData.getStmtType() == MetaStatement){
341 > else if(pData->getStmtType() == MetaStatement){
342 661c683,684
343 < if (pData.getStmtType() == SelectStatement ) {
345 > if (pData->getStmtType() == SelectStatement ||
346 > pData->getStmtType() == SetSelectStatement ) {
347 665c688
348 < else if(pData.getStmtType() == MetaStatement){
350 > else if(pData->getStmtType() == MetaStatement){
351 675,678c698,702
352 < if (pData.getStmtType() ==SelectStatement ||
353 < pData.getStmtType() ==InsertStatement ||
354 < pData.getStmtType() ==UpdateStatement ||
355 < pData.getStmtType() ==DeleteStatement)
357 > if (pData->getStmtType() ==SelectStatement ||
358 > pData->getStmtType() ==SetSelectStatement ||
359 > pData->getStmtType() ==InsertStatement ||
360 > pData->getStmtType() ==UpdateStatement ||
361 > pData->getStmtType() ==DeleteStatement)
362 692c716
363 < pData.init();
365 > pData->init();
366 703c727
367 < pData.reset();
369 > pData->reset();
370 830,832c854,856
371 < if (pData.getStmtType() == InsertStatement||
372 < pData.getStmtType() == UpdateStatement||
373 < pData.getStmtType() == DeleteStatement)
375 > if (pData->getStmtType() == InsertStatement||
376 > pData->getStmtType() == UpdateStatement||
377 > pData->getStmtType() == DeleteStatement)
378 Index: src/sql/StatementFactory.cxx
379 ===================================================================
380 RCS file: /cvsroot/csql/csql/src/sql/StatementFactory.cxx,v
381 retrieving revision 1.6
382 diff -r1.6 StatementFactory.cxx
383 28a29,49
384 > case SetSelectStatement: {
385 > ParsedData *iter = data;
386 > Statement *subStmt = new SetStatement();
387 > SelStatement *inStmt = NULL;
388 > //TODO:: the below works only for two table union
389 > while(iter->innerParsedData)
391 > if (iter->innerParsedData->innerParsedData) {
392 > inStmt = new SetStatement();
393 > inStmt->setParsedData(iter->innerParsedData);
394 > ((SetStatement*)subStmt)->setRightStmt(inStmt);
395 > } else {
396 > inStmt = new SelStatement();
397 > inStmt->setParsedData(iter->innerParsedData);
398 > ((SetStatement*)subStmt)->setRightStmt(inStmt);
400 > iter = iter->innerParsedData;
402 > stmt = subStmt;
403 > break;
405 Index: src/sql/dmllex.lxx
406 ===================================================================
407 RCS file: /cvsroot/csql/csql/src/sql/dmllex.lxx,v
408 retrieving revision 1.23
409 diff -r1.23 dmllex.lxx
410 205a206,207
411 > if(strcasecmp(yytext,"UNION") ==0) token = UNION;
412 > if(strcasecmp(yytext,"ALL") ==0) token = ALL;
413 Index: src/sql/dmlyacc.h
414 ===================================================================
415 RCS file: /cvsroot/csql/csql/src/sql/dmlyacc.h,v
416 retrieving revision 1.30
417 diff -r1.30 dmlyacc.h
418 99,119c99,121
419 < #define USER 355
420 < #define PASSWORD 356
421 < #define ALTER 357
422 < #define FLUSH 358
423 < #define ADD 359
424 < #define COLUMN 360
425 < #define MODIFY 361
426 < #define RENAME 362
427 < #define TO 363
428 < #define MIN 364
429 < #define MAX 365
430 < #define AVG 366
431 < #define SUM 367
432 < #define COUNT 368
433 < #define GROUP 369
434 < #define BY 370
435 < #define HAVING 371
436 < #define ORDER 372
437 < #define ASC 373
438 < #define DESC 374
439 < #define DISTINCT 375
441 > #define UNION 355
442 > #define ALL 356
443 > #define USER 357
444 > #define PASSWORD 358
445 > #define ALTER 359
446 > #define FLUSH 360
447 > #define ADD 361
448 > #define COLUMN 362
449 > #define MODIFY 363
450 > #define RENAME 364
451 > #define TO 365
452 > #define MIN 366
453 > #define MAX 367
454 > #define AVG 368
455 > #define SUM 369
456 > #define COUNT 370
457 > #define GROUP 371
458 > #define BY 372
459 > #define HAVING 373
460 > #define ORDER 374
461 > #define ASC 375
462 > #define DESC 376
463 > #define DISTINCT 377
464 125a128,129
465 > void *pData;
466 > int intVal;
467 Index: src/sql/dmlyacc.yxx
468 ===================================================================
469 RCS file: /cvsroot/csql/csql/src/sql/dmlyacc.yxx,v
470 retrieving revision 1.48
471 diff -r1.48 dmlyacc.yxx
472 19a20,21
473 > void *pData;
474 > int intVal;
475 34c36
476 < %token <stringval> DATE_DIFF DATE_ADD DATE_SUB HOUR MINUTE SECOND YEAR MONTH DAY INTERVAL TIME_DIFF TIME_ADD TIME_SUB TIMESTAMP_DIFF TIMESTAMP_ADD TIMESTAMP_SUB EXTRACT NOW
478 > %token <stringval> DATE_DIFF DATE_ADD DATE_SUB HOUR MINUTE SECOND YEAR MONTH DAY INTERVAL TIME_DIFF TIME_ADD TIME_SUB TIMESTAMP_DIFF TIMESTAMP_ADD TIMESTAMP_SUB EXTRACT NOW UNION ALL
479 39a42
480 > %type <pData> select_statement select_query_term select_query_expression subquery
481 42a46
482 > %type <intVal> set_op
483 44c48
484 < command: select_statement { YYACCEPT; }
486 > command: select_query_expression { YYACCEPT; }
487 191c195,240
488 < select_statement: opt_explain SELECT opt_distinct field_list FROM table_list where_clause_opt group_by_opt having_opt order_by_opt limit_opt semicolon_opt
490 > select_query_expression: select_query_term semicolon_opt
492 > printf("select_query_expression evaluated\n");
493 > *parsedData = *(ParsedData*)$1;
494 > $$=$1;
496 > |select_query_term set_op select_query_term semicolon_opt
497 > //|select_query_expression set_op select_query_term semicolon_opt
499 > printf("UNION evaluated %s\n", ((ParsedData*)$3)->getTableName());
500 > //parsedData->print();
501 > *parsedData = * ((ParsedData*)$1);
502 > parsedData->setInnerParsedData((ParsedData*)$3);
503 > parsedData->setSubQueryType((SubQueryType)$2);
504 > parsedData->setStmtType(SetSelectStatement);
505 > $$=parsedData;
508 > set_op: UNION
510 > $$=UNION_TYPE;
513 > UNION ALL
515 > $$=UNION_TYPE;
518 > select_query_term: select_statement
520 > printf("select_query_term evaluated\n");
521 > $$=$1;
523 > | '(' select_statement ')'
525 > printf("select_query_term bracket evaluated\n");
526 > $$=$2;
529 > subquery: '(' select_statement ')'
531 > printf("subquery evaluated\n");
532 > $$=$2;
535 > select_statement: opt_explain SELECT opt_distinct field_list FROM table_list where_clause_opt group_by_opt having_opt order_by_opt limit_opt
536 192a242
537 > printf("select_statement evaluated\n");
538 194a245,248
539 > ParsedData *newP = new ParsedData();
540 > *newP = *parsedData;
541 > parsedData->init();
542 > $$=newP;
543 805a860,867
544 > | ident not_opt IN subquery
546 > printf("IN SUBQUERY TODO\n");
548 > | ident OPERATOR subquery
550 > printf("OPERATOR SUBQUERY TODO\n");