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
];
158 char userName
[IDENTIFIER_LENGTH
];
159 char passName
[IDENTIFIER_LENGTH
];
166 char tblName
[IDENTIFIER_LENGTH
];
167 char idxName
[IDENTIFIER_LENGTH
]; //Also used for rename table
168 char pkTblName
[IDENTIFIER_LENGTH
];//This is also used as DSN name when cachestatement executed and copy table statemnet
169 StatementType stmtType
;
177 //holds pointer to field names. used in insert to store field name list
178 //and for projection list of select
179 //also used to store primary or unique key fields in create statement
182 List groupFieldNameList
;
184 List havingFieldNameList
;
186 List orderFieldNameList
;
188 //holds pointer to condition values.
189 List conditionValueList
;
191 List secondaryIndexFieldList
;
192 //holds pointer to field values. used in insert to store field values
193 //used in update to store the current value returned by fetch().This gets replaced
194 //by value in updFldValList and then update() is called.
197 //used to store IN values of SELECT statement
198 //This should be a list of list. so that multiple IN shall be present
199 //in the select statement
202 //update field value list. used to store the values to be updated
203 //value in the SET clause of UPDATE statement is stored here.
206 //stores the where clause condition for SELECT, UPDATE and DELETE
208 Condition havingPredicate
;
211 //stores field information in CREATE TABLE
215 //stores list of fields for CREATE TABLE
216 FieldList creFldList
;
217 //Foreign Key storage
219 List fkFieldNameList
;
220 List pkFieldNameList
;
223 bool shouldCreateTbl
;
225 AlterTableType aTblType
;
226 //stores index information
229 bool isAutoIncrement
;
234 char hcondition
[IDENTIFIER_LENGTH
];
235 char vcondition
[IDENTIFIER_LENGTH
];
246 bool isWorthyToCache
;
249 ParsedData() { limit
= 0; offset
= 0; paramCounter
= 0; stmtType
= UnknownStatement
; isDistinct
= false; isExplain
=false;
250 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;
251 shouldCreateTbl
=false; userNode
= NULL
; isWorthyToCache
=false; ftype
= UNKNOWN_FUNCTION
;
253 void setFunctionType(FunctionType type
) { ftype
= type
; }
254 FunctionType
getFunctionType(){ return ftype
;}
255 void setAlterType(AlterTableType type
){ aTblType
= type
;}
256 AlterTableType
getAlterType(){ return aTblType
; }
258 void createUserNode(char *name
, char *password
);
259 char *getUserName() { return userNode
->userName
; }
260 char *getPassWord() { return userNode
->passName
; }
261 UserNodeType
getUserType() { return userNode
->type
; }
262 void dropUserNode(char *name
);
263 void alterUserNode(char *name
, char *password
);
265 void setCreateTbl(){ shouldCreateTbl
=true; }
266 bool getCreateTbl(){ return shouldCreateTbl
; }
268 void setDSN(bool flag
){ dsn
= flag
;}
269 bool getDSN(){ return dsn
; }
270 void setNoSchema(bool flag
){ noschema
= flag
; }
271 bool getNoSchema(){return noschema
;}
272 char *getHCondition(){return hcondition
;}
273 char *getVCondition(){return vcondition
;}
274 void setHCondition(char *fld
){ strcpy(hcondition
,fld
);}
275 void setVCondition(char *fld
){ strcpy(vcondition
,fld
);}
276 void setHCondFld(bool flag
){hCondFld
= flag
;}
277 bool getHCondFld(){return hCondFld
;}
278 void setVCondFld(bool flag
){vCondFld
= flag
;}
279 bool getVCondFld(){return vCondFld
;}
280 void setPkFld(bool flag
){pkFld
= flag
;}
281 bool getPkFld(){return pkFld
;}
282 void setDirect(bool flag
){direct
=flag
;}
283 bool getDirect(){return direct
;}
284 void setUnCache(bool flag
){uncache
=flag
;}
285 bool getUnCache(){return uncache
;}
286 void setLimit(int l
, int o
) { limit
=l
; offset
=o
; }
287 int getLimit(){ return limit
; }
288 int getOffset(){ return offset
; }
291 int getBucketSize(){return bucketSize
; };
292 void setBucketSize(int bucket
){ bucketSize
= bucket
; };
293 void setStmtType(StatementType type
) { stmtType
= type
; }
294 void setTableName(char *name
) { strcpy(tblName
, name
); }
295 void setIndexName(char *name
) { strcpy(idxName
, name
); }
296 void setPKTableName(char *name
){strcpy(pkTblName
, name
); }
297 void setResultSetPlan(ResultSetPlan pl
){plan
= pl
;}
298 ResultSetPlan
getResultSetPlan(){return plan
;}
299 char* getTableName() { return tblName
; }
300 char* getIndexName() { return idxName
; }
301 char* getPKTableName(){ return pkTblName
;}
302 DbRetVal
setAutoIncreament(bool flag
);
303 bool getAutoIncreament();
304 void insertValue(char *value
);
305 void insertInValue(char *value
);
306 // third parameter is to avoid conflict between '?' between like operand and parameterized value in sql statement.
307 // eg: select * from t1 where f1 = ? and f2 like '_ti%';
308 // _ is converted to ? before it is processed
309 void** insertCondValueAndGetPtr(char *fName
, char *value
, bool opLike
=false, AggType atp
=AGG_UNKNOWN
, bool isInHaving
=false,bool function
=false);
310 void insertCondValue(char *fldName
); //For Predecate t1.f1=t2.f1
311 void insertUpdateValue(char *fldName
, char *value
);
313 void insertField(char *fName
, AggType aggType
= AGG_UNKNOWN
);
314 void insertFieldAlias(char *name
);
315 void insertGroupField(char *fName
);
316 void insertOrderByField(char *fName
, bool isDesc
= false);
317 void clearFieldNameList();
318 void insertTableName(char *value
);
319 void insertJoinType(JoinType jType
);
320 void insertTableName(char *value
, char *alias
);
321 void insertFKField(char *fkName
);
322 void insertPKField(char *pkName
);
323 void insertForeignKeyList();
324 Predicate
* insertPredicate(char *fldName
, ComparisionOp op
, void** value
, AggType aggType
= AGG_UNKNOWN
);
325 Predicate
* insertPredicate(char *fldName
, ComparisionOp op
, char *fldName1
);
326 Predicate
* insertBetPredicate(char *fldName
, ComparisionOp op1
, void **value1
, ComparisionOp op2
, void **value2
);
327 Predicate
* insertPredicate(Predicate
*p1
, LogicalOp op
, Predicate
*p2
= NULL
);
328 Predicate
* insertPredicate(Expression
*exp
, ComparisionOp op
,void **val
);
329 Predicate
* insertPredicate(Expression
*exp
, ComparisionOp op
,char *fName2
);
330 Predicate
* insertPredicate(Expression
*exp1
, ComparisionOp op
,Expression
*exp2
);
331 Predicate
* insertNullPredicate(char *fName
, ComparisionOp op
,bool nullFlag
);
332 void setCondition(Predicate
*pred
)
334 predicate
.setPredicate(pred
);
336 void setHavingCondition(Predicate
*pred
)
338 havingPredicate
.setPredicate(pred
);
340 Condition
* getCondition() { return &predicate
; }
341 Condition
* getHavingCondition() { return &havingPredicate
; }
343 void insertFieldValue(FieldValue
*newVal
) { fieldValueList
.append(newVal
); }
345 List
getFieldNameList() { return fieldNameList
; }
346 List
getGroupFieldNameList() { return groupFieldNameList
; }
347 List
getHavingFieldNameList() { return havingFieldNameList
; }
348 List
getOrderFieldNameList() { return orderFieldNameList
; }
349 List
getConditionValueList() { return conditionValueList
; }
350 List
getFieldValueList() { return fieldValueList
; }
351 List
getInValueList() { return inValueList
; }
352 List
getUpdateFieldValueList() { return updFldValList
; }
353 List
getTableNameList() { return tableNameList
; }
354 List
getJoinTypeList() { return joinTypeList
; }
355 List
getSecondaryIndexFieldList() { return secondaryIndexFieldList
; }
356 List
getForeignKeyList(){ return foreignKeyList
;}
357 List
getPkFieldNameList(){return pkFieldNameList
;}
358 List
getFkFieldNameList(){return fkFieldNameList
;}
360 void setDistinct() { isDistinct
= true;}
361 bool getDistinct() { return isDistinct
; }
362 void setExplain() { isExplain
=true; }
363 bool getExplain() { return isExplain
; }
364 bool getCacheWorthy() { return isWorthyToCache
; }
365 void setCacheWorthy(bool flag
) { isWorthyToCache
= flag
;}
368 void setFldName(char *name
);
369 void setFldType(DataType type
);
370 DataType
getFldType();
371 DbRetVal
setFldLength(size_t length
);
372 DbRetVal
setDefaultValue(char * value
);
373 DbRetVal
validateDefaultValue(char* value
);
374 //void setFldDefaultValue -- will need two parametersers, check how u want to pass default value.
375 void setFldNotNull(bool notNull
);
376 void setForeign(bool foreign
){ isForeign
= foreign
; }
377 void setUnique(bool unique
){ isUnique
= unique
; }
378 void setPrimary(bool primary
) { isPrimary
= primary
; }
379 void setIndexType (IndexType type
) { indexType
= type
; }
380 IndexType
getIndexType(){ return indexType
; }
381 bool getUnique() { return isUnique
; }
382 bool getPrimary() { return isPrimary
; }
383 Expression
* insertExpression(char *fldName
);
384 Expression
* insertExpression(char *value
, bool flag
);
385 Expression
* insertExpression(Expression
* exp1
, ArithOperator op
,Expression
* exp2
);
386 Expression
* insertExpression(Expression
* exp1
, FunctionType type
,Expression
* exp2
);
387 void insertUpdateExpression(char *fName
, Expression
*exp
);
389 void insertFldDef(); //check if fldDef needs to be a part of ParsedData
391 FieldList
getCreFldList() { return creFldList
; }
393 StatementType
getStmtType() { return stmtType
; }
395 void setAutoFldName(char *fldName
);
404 //variable and function names suck, change if u want to
406 //finding out if fldDef needs to be part of parsedData, or can allocate memory and pass around