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>
41 CompactTableStatement
,
51 char fldName
[IDENTIFIER_LENGTH
];
52 char defValBuf
[DEFAULT_VALUE_BUF_LENGTH
];
55 int paramNo
; // 0 ->not a param. It stores the param position
74 int paramNo
; // 0 ->not a param. It stores the param position
80 char fName
[IDENTIFIER_LENGTH
];
85 char fldName
[IDENTIFIER_LENGTH
];
86 AggType aType
; //used only in case of select projection
87 char aliasFldName
[IDENTIFIER_LENGTH
];
91 strcpy(aliasFldName
,"");
97 char tblName
[IDENTIFIER_LENGTH
];
98 char aliasName
[IDENTIFIER_LENGTH
];
102 strcpy(aliasName
,"");
120 JoinTypeNode(){ jType
= INNER_JOIN
; }
123 struct UpdateFieldValue
125 char fldName
[IDENTIFIER_LENGTH
];
144 char userName
[IDENTIFIER_LENGTH
];
145 char passName
[IDENTIFIER_LENGTH
];
152 char tblName
[IDENTIFIER_LENGTH
];
153 char idxName
[IDENTIFIER_LENGTH
];
154 char pkTblName
[IDENTIFIER_LENGTH
];//This is also used as DSN name when cachestatement executed and copy table statemnet
155 StatementType stmtType
;
163 //holds pointer to field names. used in insert to store field name list
164 //and for projection list of select
165 //also used to store primary or unique key fields in create statement
168 List groupFieldNameList
;
170 List havingFieldNameList
;
172 List orderFieldNameList
;
174 //holds pointer to condition values.
175 List conditionValueList
;
177 List secondaryIndexFieldList
;
178 //holds pointer to field values. used in insert to store field values
179 //used in update to store the current value returned by fetch().This gets replaced
180 //by value in updFldValList and then update() is called.
183 //used to store IN values of SELECT statement
184 //This should be a list of list. so that multiple IN shall be present
185 //in the select statement
188 //update field value list. used to store the values to be updated
189 //value in the SET clause of UPDATE statement is stored here.
192 //stores the where clause condition for SELECT, UPDATE and DELETE
194 Condition havingPredicate
;
197 //stores field information in CREATE TABLE
201 //stores list of fields for CREATE TABLE
202 FieldList creFldList
;
203 //Foreign Key storage
205 List fkFieldNameList
;
206 List pkFieldNameList
;
209 bool shouldCreateTbl
;
210 //stores index information
213 bool isAutoIncrement
;
218 char hcondition
[IDENTIFIER_LENGTH
];
219 char vcondition
[IDENTIFIER_LENGTH
];
231 ParsedData() { limit
= 0; offset
= 0; paramCounter
= 0; stmtType
= UnknownStatement
; isDistinct
= false; isExplain
=false;
232 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;
233 shouldCreateTbl
=false; userNode
= NULL
;
235 void createUserNode(char *name
, char *password
);
236 char *getUserName() { return userNode
->userName
; }
237 char *getPassWord() { return userNode
->passName
; }
238 UserNodeType
getUserType() { return userNode
->type
; }
239 void dropUserNode(char *name
);
240 void alterUserNode(char *name
, char *password
);
242 void setCreateTbl(){ shouldCreateTbl
=true; }
243 bool getCreateTbl(){ return shouldCreateTbl
; }
245 void setDSN(bool flag
){ dsn
= flag
;}
246 bool getDSN(){ return dsn
; }
247 void setNoSchema(bool flag
){ noschema
= flag
; }
248 bool getNoSchema(){return noschema
;}
249 char *getHCondition(){return hcondition
;}
250 char *getVCondition(){return vcondition
;}
251 void setHCondition(char *fld
){ strcpy(hcondition
,fld
);}
252 void setVCondition(char *fld
){ strcpy(vcondition
,fld
);}
253 void setHCondFld(bool flag
){hCondFld
= flag
;}
254 bool getHCondFld(){return hCondFld
;}
255 void setVCondFld(bool flag
){vCondFld
= flag
;}
256 bool getVCondFld(){return vCondFld
;}
257 void setPkFld(bool flag
){pkFld
= flag
;}
258 bool getPkFld(){return pkFld
;}
259 void setDirect(bool flag
){direct
=flag
;}
260 bool getDirect(){return direct
;}
261 void setUnCache(bool flag
){uncache
=flag
;}
262 bool getUnCache(){return uncache
;}
263 void setLimit(int l
, int o
) { limit
=l
; offset
=o
; }
264 int getLimit(){ return limit
; }
265 int getOffset(){ return offset
; }
268 int getBucketSize(){return bucketSize
; };
269 void setBucketSize(int bucket
){ bucketSize
= bucket
; };
270 void setStmtType(StatementType type
) { stmtType
= type
; }
271 void setTableName(char *name
) { strcpy(tblName
, name
); }
272 void setIndexName(char *name
) { strcpy(idxName
, name
); }
273 void setPKTableName(char *name
){strcpy(pkTblName
, name
); }
274 void setResultSetPlan(ResultSetPlan pl
){plan
= pl
;}
275 ResultSetPlan
getResultSetPlan(){return plan
;}
276 char* getTableName() { return tblName
; }
277 char* getIndexName() { return idxName
; }
278 char* getPKTableName(){ return pkTblName
;}
279 DbRetVal
setAutoIncreament(bool flag
);
280 bool getAutoIncreament();
281 void insertValue(char *value
);
282 void insertInValue(char *value
);
283 // third parameter is to avoid conflict between '?' between like operand and parameterized value in sql statement.
284 // eg: select * from t1 where f1 = ? and f2 like '_ti%';
285 // _ is converted to ? before it is processed
286 void** insertCondValueAndGetPtr(char *fName
, char *value
, bool opLike
=false, AggType atp
=AGG_UNKNOWN
, bool isInHaving
=false);
287 void insertCondValue(char *fldName
); //For Predecate t1.f1=t2.f1
288 void insertUpdateValue(char *fldName
, char *value
);
290 void insertField(char *fName
, AggType aggType
= AGG_UNKNOWN
);
291 void insertFieldAlias(char *name
);
292 void insertGroupField(char *fName
);
293 void insertOrderByField(char *fName
, bool isDesc
= false);
294 void clearFieldNameList();
295 void insertTableName(char *value
);
296 void insertJoinType(JoinType jType
);
297 void insertTableName(char *value
, char *alias
);
298 void insertFKField(char *fkName
);
299 void insertPKField(char *pkName
);
300 void insertForeignKeyList();
301 Predicate
* insertPredicate(char *fldName
, ComparisionOp op
, void** value
, AggType aggType
= AGG_UNKNOWN
);
302 Predicate
* insertPredicate(char *fldName
, ComparisionOp op
, char *fldName1
);
303 Predicate
* insertBetPredicate(char *fldName
, ComparisionOp op1
, void **value1
, ComparisionOp op2
, void **value2
);
304 Predicate
* insertPredicate(Predicate
*p1
, LogicalOp op
, Predicate
*p2
= NULL
);
305 Predicate
* insertNullPredicate(char *fName
, ComparisionOp op
,bool nullFlag
);
306 void setCondition(Predicate
*pred
)
308 predicate
.setPredicate(pred
);
310 void setHavingCondition(Predicate
*pred
)
312 havingPredicate
.setPredicate(pred
);
314 Condition
* getCondition() { return &predicate
; }
315 Condition
* getHavingCondition() { return &havingPredicate
; }
317 void insertFieldValue(FieldValue
*newVal
) { fieldValueList
.append(newVal
); }
319 List
getFieldNameList() { return fieldNameList
; }
320 List
getGroupFieldNameList() { return groupFieldNameList
; }
321 List
getHavingFieldNameList() { return havingFieldNameList
; }
322 List
getOrderFieldNameList() { return orderFieldNameList
; }
323 List
getConditionValueList() { return conditionValueList
; }
324 List
getFieldValueList() { return fieldValueList
; }
325 List
getInValueList() { return inValueList
; }
326 List
getUpdateFieldValueList() { return updFldValList
; }
327 List
getTableNameList() { return tableNameList
; }
328 List
getJoinTypeList() { return joinTypeList
; }
329 List
getSecondaryIndexFieldList() { return secondaryIndexFieldList
; }
330 List
getForeignKeyList(){ return foreignKeyList
;}
331 List
getPkFieldNameList(){return pkFieldNameList
;}
332 List
getFkFieldNameList(){return fkFieldNameList
;}
334 void setDistinct() { isDistinct
= true;}
335 bool getDistinct() { return isDistinct
; }
336 void setExplain() { isExplain
=true; }
337 bool getExplain() { return isExplain
; }
340 void setFldName(char *name
);
341 void setFldType(DataType type
);
342 DataType
getFldType();
343 DbRetVal
setFldLength(size_t length
);
344 void setDefaultValue(char * value
);
345 //void setFldDefaultValue -- will need two parametersers, check how u want to pass default value.
346 void setFldNotNull(bool notNull
);
347 void setForeign(bool foreign
){ isForeign
= foreign
; }
348 void setUnique(bool unique
){ isUnique
= unique
; }
349 void setPrimary(bool primary
) { isPrimary
= primary
; }
350 void setIndexType (IndexType type
) { indexType
= type
; }
351 IndexType
getIndexType(){ return indexType
; }
352 bool getUnique() { return isUnique
; }
353 bool getPrimary() { return isPrimary
; }
354 Expression
* insertExpression(char *fldName
);
355 Expression
* insertExpression(char *value
, bool flag
);
356 Expression
* insertExpression(Expression
* exp1
, ArithOperator op
,Expression
* exp2
);
357 void insertUpdateExpression(char *fName
, Expression
*exp
);
359 void insertFldDef(); //check if fldDef needs to be a part of ParsedData
361 FieldList
getCreFldList() { return creFldList
; }
363 StatementType
getStmtType() { return stmtType
; }
365 void setAutoFldName(char *fldName
);
374 //variable and function names suck, change if u want to
376 //finding out if fldDef needs to be part of parsedData, or can allocate memory and pass around