1 /***************************************************************************
2 * Copyright (C) 2007 by Prabakaran Thirumalai *
3 * praba_tuty@yahoo.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
23 #include <AggTableImpl.h>
24 #include <JoinTableImpl.h>
42 CompactTableStatement
,
54 char fldName
[IDENTIFIER_LENGTH
];
55 char defValBuf
[DEFAULT_VALUE_BUF_LENGTH
];
58 int paramNo
; // 0 ->not a param. It stores the param position
77 int paramNo
; // 0 ->not a param. It stores the param position
83 char fName
[IDENTIFIER_LENGTH
];
84 bool isFunctionInvolve
;
89 char fldName
[IDENTIFIER_LENGTH
];
90 AggType aType
; //used only in case of select projection
91 char aliasFldName
[IDENTIFIER_LENGTH
];
95 strcpy(aliasFldName
,"");
101 char tblName
[IDENTIFIER_LENGTH
];
102 char aliasName
[IDENTIFIER_LENGTH
];
106 strcpy(aliasName
,"");
124 JoinTypeNode(){ jType
= INNER_JOIN
; }
127 struct UpdateFieldValue
129 char fldName
[IDENTIFIER_LENGTH
];
159 char userName
[IDENTIFIER_LENGTH
];
160 char passName
[IDENTIFIER_LENGTH
];
164 class DllExport ParsedData
167 char tblName
[IDENTIFIER_LENGTH
];
168 char idxName
[IDENTIFIER_LENGTH
]; //Also used for rename table
169 char pkTblName
[IDENTIFIER_LENGTH
];//This is also used as DSN name when cachestatement executed and copy table statemnet
170 StatementType stmtType
;
178 //holds pointer to field names. used in insert to store field name list
179 //and for projection list of select
180 //also used to store primary or unique key fields in create statement
183 List groupFieldNameList
;
185 List havingFieldNameList
;
187 List orderFieldNameList
;
189 //holds pointer to condition values.
190 List conditionValueList
;
192 List secondaryIndexFieldList
;
193 //holds pointer to field values. used in insert to store field values
194 //used in update to store the current value returned by fetch().This gets replaced
195 //by value in updFldValList and then update() is called.
198 //used to store IN values of SELECT statement
199 //This should be a list of list. so that multiple IN shall be present
200 //in the select statement
203 //update field value list. used to store the values to be updated
204 //value in the SET clause of UPDATE statement is stored here.
207 //stores the where clause condition for SELECT, UPDATE and DELETE
209 Condition havingPredicate
;
212 //stores field information in CREATE TABLE
216 //stores list of fields for CREATE TABLE
217 FieldList creFldList
;
218 //Foreign Key storage
220 List fkFieldNameList
;
221 List pkFieldNameList
;
224 bool shouldCreateTbl
;
226 AlterTableType aTblType
;
227 //stores index information
230 bool isAutoIncrement
;
235 char hcondition
[IDENTIFIER_LENGTH
];
236 char vcondition
[IDENTIFIER_LENGTH
];
247 bool isWorthyToCache
;
250 ParsedData() { limit
= 0; offset
= 0; paramCounter
= 0; stmtType
= UnknownStatement
; isDistinct
= false; isExplain
=false;
251 isUnique
= false; isPrimary
= false; isAutoIncrement
=false ;indexType
= hashIndex
; plan
= Normal
; bucketSize
=0; isForeign
=false; hCondFld
=false; vCondFld
=false;pkFld
=false;forceOption
=false; direct
=false; uncache
=false; noschema
=false; dsn
=false;
252 shouldCreateTbl
=false; userNode
= NULL
; isWorthyToCache
=false; ftype
= UNKNOWN_FUNCTION
;
254 void setFunctionType(FunctionType type
) { ftype
= type
; }
255 FunctionType
getFunctionType(){ return ftype
;}
256 void setAlterType(AlterTableType type
){ aTblType
= type
;}
257 AlterTableType
getAlterType(){ return aTblType
; }
259 void createUserNode(char *name
, char *password
);
260 char *getUserName() { return userNode
->userName
; }
261 char *getPassWord() { return userNode
->passName
; }
262 UserNodeType
getUserType() { return userNode
->type
; }
263 void dropUserNode(char *name
);
264 void alterUserNode(char *name
, char *password
);
266 void setCreateTbl(){ shouldCreateTbl
=true; }
267 bool getCreateTbl(){ return shouldCreateTbl
; }
269 void setDSN(bool flag
){ dsn
= flag
;}
270 bool getDSN(){ return dsn
; }
271 void setNoSchema(bool flag
){ noschema
= flag
; }
272 bool getNoSchema(){return noschema
;}
273 char *getHCondition(){return hcondition
;}
274 char *getVCondition(){return vcondition
;}
275 void setHCondition(char *fld
){ strcpy(hcondition
,fld
);}
276 void setVCondition(char *fld
){ strcpy(vcondition
,fld
);}
277 void setHCondFld(bool flag
){hCondFld
= flag
;}
278 bool getHCondFld(){return hCondFld
;}
279 void setVCondFld(bool flag
){vCondFld
= flag
;}
280 bool getVCondFld(){return vCondFld
;}
281 void setPkFld(bool flag
){pkFld
= flag
;}
282 bool getPkFld(){return pkFld
;}
283 void setDirect(bool flag
){direct
=flag
;}
284 bool getDirect(){return direct
;}
285 void setUnCache(bool flag
){uncache
=flag
;}
286 bool getUnCache(){return uncache
;}
287 void setLimit(int l
, int o
) { limit
=l
; offset
=o
; }
288 int getLimit(){ return limit
; }
289 int getOffset(){ return offset
; }
292 int getBucketSize(){return bucketSize
; };
293 void setBucketSize(int bucket
){ bucketSize
= bucket
; };
294 void setStmtType(StatementType type
) { stmtType
= type
; }
295 void setTableName(char *name
) { strcpy(tblName
, name
); }
296 void setIndexName(char *name
) { strcpy(idxName
, name
); }
297 void setPKTableName(char *name
){strcpy(pkTblName
, name
); }
298 void setResultSetPlan(ResultSetPlan pl
){plan
= pl
;}
299 ResultSetPlan
getResultSetPlan(){return plan
;}
300 char* getTableName() { return tblName
; }
301 char* getIndexName() { return idxName
; }
302 char* getPKTableName(){ return pkTblName
;}
303 DbRetVal
setAutoIncreament(bool flag
);
304 bool getAutoIncreament();
305 void insertValue(char *value
);
306 void insertInValue(char *value
);
307 // third parameter is to avoid conflict between '?' between like operand and parameterized value in sql statement.
308 // eg: select * from t1 where f1 = ? and f2 like '_ti%';
309 // _ is converted to ? before it is processed
310 void** insertCondValueAndGetPtr(char *fName
, char *value
, bool opLike
=false, AggType atp
=AGG_UNKNOWN
, bool isInHaving
=false,bool function
=false);
311 void insertCondValue(char *fldName
); //For Predecate t1.f1=t2.f1
312 void insertUpdateValue(char *fldName
, char *value
);
314 void insertField(char *fName
, AggType aggType
= AGG_UNKNOWN
);
315 void insertFieldAlias(char *name
);
316 void insertGroupField(char *fName
);
317 void insertOrderByField(char *fName
, bool isDesc
= false);
318 void clearFieldNameList();
319 void insertTableName(char *value
);
320 void insertJoinType(JoinType jType
);
321 void insertTableName(char *value
, char *alias
);
322 void insertFKField(char *fkName
);
323 void insertPKField(char *pkName
);
324 void insertForeignKeyList();
325 Predicate
* insertPredicate(char *fldName
, ComparisionOp op
, void** value
, AggType aggType
= AGG_UNKNOWN
);
326 Predicate
* insertPredicate(char *fldName
, ComparisionOp op
, char *fldName1
);
327 Predicate
* insertBetPredicate(char *fldName
, ComparisionOp op1
, void **value1
, ComparisionOp op2
, void **value2
);
328 Predicate
* insertPredicate(Predicate
*p1
, LogicalOp op
, Predicate
*p2
= NULL
);
329 Predicate
* insertPredicate(Expression
*exp
, ComparisionOp op
,void **val
);
330 Predicate
* insertPredicate(Expression
*exp
, ComparisionOp op
,char *fName2
);
331 Predicate
* insertPredicate(Expression
*exp1
, ComparisionOp op
,Expression
*exp2
);
332 Predicate
* insertNullPredicate(char *fName
, ComparisionOp op
,bool nullFlag
);
333 void setCondition(Predicate
*pred
)
335 predicate
.setPredicate(pred
);
337 void setHavingCondition(Predicate
*pred
)
339 havingPredicate
.setPredicate(pred
);
341 Condition
* getCondition() { return &predicate
; }
342 Condition
* getHavingCondition() { return &havingPredicate
; }
344 void insertFieldValue(FieldValue
*newVal
) { fieldValueList
.append(newVal
); }
346 List
getFieldNameList() { return fieldNameList
; }
347 List
getGroupFieldNameList() { return groupFieldNameList
; }
348 List
getHavingFieldNameList() { return havingFieldNameList
; }
349 List
getOrderFieldNameList() { return orderFieldNameList
; }
350 List
getConditionValueList() { return conditionValueList
; }
351 List
getFieldValueList() { return fieldValueList
; }
352 List
getInValueList() { return inValueList
; }
353 List
getUpdateFieldValueList() { return updFldValList
; }
354 List
getTableNameList() { return tableNameList
; }
355 List
getJoinTypeList() { return joinTypeList
; }
356 List
getSecondaryIndexFieldList() { return secondaryIndexFieldList
; }
357 List
getForeignKeyList(){ return foreignKeyList
;}
358 List
getPkFieldNameList(){return pkFieldNameList
;}
359 List
getFkFieldNameList(){return fkFieldNameList
;}
361 void setDistinct() { isDistinct
= true;}
362 bool getDistinct() { return isDistinct
; }
363 void setExplain() { isExplain
=true; }
364 bool getExplain() { return isExplain
; }
365 bool getCacheWorthy() { return isWorthyToCache
; }
366 void setCacheWorthy(bool flag
) { isWorthyToCache
= flag
;}
369 void setFldName(char *name
);
370 void setFldType(DataType type
);
371 DataType
getFldType();
372 DbRetVal
setFldLength(size_t length
);
373 DbRetVal
setDefaultValue(char * value
);
374 DbRetVal
validateDefaultValue(char* value
);
375 //void setFldDefaultValue -- will need two parametersers, check how u want to pass default value.
376 void setFldNotNull(bool notNull
);
377 void setForeign(bool foreign
){ isForeign
= foreign
; }
378 void setUnique(bool unique
){ isUnique
= unique
; }
379 void setPrimary(bool primary
) { isPrimary
= primary
; }
380 void setIndexType (IndexType type
) { indexType
= type
; }
381 IndexType
getIndexType(){ return indexType
; }
382 bool getUnique() { return isUnique
; }
383 bool getPrimary() { return isPrimary
; }
384 Expression
* insertExpression(char *fldName
);
385 Expression
* insertExpression(char *value
, bool flag
);
386 Expression
* insertExpression(Expression
* exp1
, ArithOperator op
,Expression
* exp2
);
387 Expression
* insertExpression(Expression
* exp1
, FunctionType type
,Expression
* exp2
);
388 void insertUpdateExpression(char *fName
, Expression
*exp
);
390 void insertFldDef(); //check if fldDef needs to be a part of ParsedData
392 FieldList
getCreFldList() { return creFldList
; }
394 StatementType
getStmtType() { return stmtType
; }
396 void setAutoFldName(char *fldName
);
398 void resetInValueList();
406 //variable and function names suck, change if u want to
408 //finding out if fldDef needs to be part of parsedData, or can allocate memory and pass around