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 ***************************************************************************/
18 #include<PredicateImpl.h>
21 void ParsedData::insertValue(char *val
)
23 FieldValue
*newVal
= new FieldValue();
25 newVal
->parsedString
= NULL
;
27 newVal
->parsedString
= strdup(val
);
28 strcpy(newVal
->fldName
," ");
31 newVal
->type
= typeUnknown
;
33 newVal
->isAllocVal
=false;
34 fieldValueList
.append(newVal
);
37 void ParsedData::insertInValue(char *val
)
39 FieldValue
*newVal
= new FieldValue();
41 newVal
->parsedString
= NULL
;
43 newVal
->parsedString
= strdup(val
);
44 strcpy(newVal
->fldName
," ");
47 newVal
->type
= typeUnknown
;
49 newVal
->isAllocVal
=false;
50 inValueList
.append(newVal
);
53 void** ParsedData::insertCondValueAndGetPtr(char *fldName
, char *val
, bool opLike
)
55 ConditionValue
*newVal
= new ConditionValue();
57 newVal
->parsedString
= NULL
;
59 newVal
->parsedString
= strdup(val
);
62 newVal
->type
= typeUnknown
;
64 strcpy(newVal
->fName
, fldName
);
65 newVal
->opLike
= opLike
;
66 conditionValueList
.append(newVal
);
67 return &(newVal
->value
);
71 void ParsedData::insertField(char *fName
, AggType type
)
73 FieldName
*newVal
= new FieldName();
74 strcpy(newVal
->fldName
, fName
);
76 fieldNameList
.append(newVal
);
78 void ParsedData::insertTableName(char *tName
)
80 TableName
*newVal
= new TableName();
81 strcpy(newVal
->tblName
, tName
);
82 tableNameList
.append(newVal
);
84 void ParsedData::insertGroupField(char *fName
)
86 FieldName
*newVal
= new FieldName();
87 strcpy(newVal
->fldName
, fName
);
88 groupFieldNameList
.append(newVal
);
91 void ParsedData::insertUpdateValue(char *fName
, char *val
)
93 UpdateFieldValue
*newVal
= new UpdateFieldValue();
94 strcpy(newVal
->fldName
, fName
);
96 newVal
->parsedString
= NULL
;
98 newVal
->parsedString
= strdup(val
);
100 newVal
->expre
= NULL
;
102 updFldValList
.append(newVal
);
105 Predicate
* ParsedData::insertPredicate(char *fName
, ComparisionOp op
, void **val
)
107 PredicateImpl
*pImpl
= new PredicateImpl();
108 pImpl
->setTerm(fName
, op
, val
);
109 return (Predicate
*) pImpl
;
111 Predicate
* ParsedData::insertBetPredicate(char *fName
, ComparisionOp op1
,
112 void **val1
, ComparisionOp op2
, void **val2
)
114 PredicateImpl
*pImpl
= new PredicateImpl();
115 pImpl
->setTerm(fName
, op1
, val1
, op2
, val2
);
116 return (Predicate
*) pImpl
;
118 Predicate
* ParsedData::insertPredicate(char *fName1
, ComparisionOp op
, char *fName2
)
120 PredicateImpl
*pImpl
= new PredicateImpl();
121 pImpl
->setTerm(fName1
, op
, fName2
);
122 return (Predicate
*) pImpl
;
125 Predicate
* ParsedData::insertPredicate(Predicate
*p1
, LogicalOp op
, Predicate
*p2
)
127 PredicateImpl
*pImpl
= new PredicateImpl();
128 pImpl
->setTerm(p1
, op
, p2
);
129 return (Predicate
*) pImpl
;
132 void ParsedData::reset()
134 ListIterator fNameIter
= fieldNameList
.getIterator();
136 while (fNameIter
.hasElement())
137 delete ((FieldName
*) fNameIter
.nextElement());
138 fieldNameList
.reset();
139 ListIterator iter
= fieldValueList
.getIterator();
141 while (iter
.hasElement())
143 value
= (FieldValue
*)iter
.nextElement();
144 free(value
->parsedString
);
145 if (value
->isAllocVal
) free(value
->value
);
148 fieldValueList
.reset();
149 ListIterator inIter
= inValueList
.getIterator();
150 while (inIter
.hasElement()) {
151 value
= (FieldValue
*) inIter
.nextElement();
152 if (value
->parsedString
) free(value
->parsedString
);
159 iter
= conditionValueList
.getIterator();
160 ConditionValue
*condVal
;
161 while (iter
.hasElement())
163 condVal
= (ConditionValue
*)iter
.nextElement();
164 free(condVal
->parsedString
);
165 free(condVal
->value
);
168 conditionValueList
.reset();
170 iter
= updFldValList
.getIterator();
171 UpdateFieldValue
*updFldVal
;
172 while (iter
.hasElement())
174 updFldVal
= (UpdateFieldValue
*)iter
.nextElement();
175 if(updFldVal
->parsedString
!=NULL
)
176 free(updFldVal
->parsedString
);
177 if(updFldVal
->expre
!=NULL
)
178 updFldVal
->expre
->freeVal();
179 free(updFldVal
->value
);
182 updFldValList
.reset();
183 iter
= groupFieldNameList
.getIterator();
184 while(iter
.hasElement())
186 delete iter
.nextElement();
188 groupFieldNameList
.reset();
190 iter
= tableNameList
.getIterator();
192 while (iter
.hasElement())
194 tname
= (TableName
*)iter
.nextElement();
197 tableNameList
.reset();
199 creFldList
.removeAll();
202 indexType
= hashIndex
;
204 void ParsedData::clearFieldNameList()
206 ListIterator it
= fieldNameList
.getIterator();
207 while (it
.hasElement()) delete ((FieldName
*) it
.nextElement());
208 fieldNameList
.reset();
211 void ParsedData::setFldName(char *name
)
213 strcpy(fldDef
.fldName_
, name
);
214 fldDef
.fldName_
[IDENTIFIER_LENGTH
] = '\0';
217 void ParsedData::setFldType(DataType type
)
222 DbRetVal
ParsedData::setFldLength(size_t length
)
224 if(fldDef
.type_
== typeBinary
&& (length
-1) && (length
-1) <= 256) {
225 fldDef
.length_
= length
- 1; return OK
;
227 else if (fldDef
.type_
== typeBinary
&& (length
-1) > 256) {
230 else { fldDef
.length_
= length
; return OK
; }
233 void ParsedData::setFldNotNull(bool notNull
)
235 fldDef
.isNull_
= notNull
;
237 void ParsedData::setDefaultValue(char *value
)
239 fldDef
.isDefault_
= true;
240 if (strlen(value
) > DEFAULT_VALUE_BUF_LENGTH
-1)
242 strncpy(fldDef
.defaultValueBuf_
, value
, DEFAULT_VALUE_BUF_LENGTH
-1);
243 fldDef
.defaultValueBuf_
[DEFAULT_VALUE_BUF_LENGTH
] ='\0';
245 strcpy(fldDef
.defaultValueBuf_
, value
);
250 void ParsedData::insertFldDef()
252 DbRetVal rv
= creFldList
.append(fldDef
);
256 Expression
* ParsedData::insertExpression(char *fldName
)
258 Expression
*exp
=new Expression();
259 exp
->setExpr(fldName
);
262 Expression
* ParsedData::insertExpression(char *value
,bool flag
)
264 Expression
*exp
=new Expression();
265 exp
->setExpr(strdup(value
),flag
);
268 Expression
* ParsedData::insertExpression(Expression
* exp1
, ArithOperator op
,Expression
* exp2
)
270 Expression
*exp
=new Expression();
271 exp
->setExpr(exp1
, op
, exp2
);
274 void ParsedData::insertUpdateExpression(char *fName
, Expression
*exp
)
276 UpdateFieldValue
*newVal
= new UpdateFieldValue();
277 strcpy(newVal
->fldName
, fName
);
278 newVal
->parsedString
= NULL
;
279 newVal
->value
= NULL
;
282 updFldValList
.append(newVal
);