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
);
101 updFldValList
.append(newVal
);
104 Predicate
* ParsedData::insertPredicate(char *fName
, ComparisionOp op
, void **val
)
106 PredicateImpl
*pImpl
= new PredicateImpl();
107 pImpl
->setTerm(fName
, op
, val
);
108 return (Predicate
*) pImpl
;
110 Predicate
* ParsedData::insertPredicate(char *fName1
, ComparisionOp op
, char *fName2
)
112 PredicateImpl
*pImpl
= new PredicateImpl();
113 pImpl
->setTerm(fName1
, op
, fName2
);
114 return (Predicate
*) pImpl
;
117 Predicate
* ParsedData::insertPredicate(Predicate
*p1
, LogicalOp op
, Predicate
*p2
)
119 PredicateImpl
*pImpl
= new PredicateImpl();
120 pImpl
->setTerm(p1
, op
, p2
);
121 return (Predicate
*) pImpl
;
124 void ParsedData::reset()
126 ListIterator fNameIter
= fieldNameList
.getIterator();
128 while (fNameIter
.hasElement())
129 delete (Identifier
*) fNameIter
.nextElement();
130 fieldNameList
.reset();
131 ListIterator iter
= fieldValueList
.getIterator();
133 while (iter
.hasElement())
135 value
= (FieldValue
*)iter
.nextElement();
136 free(value
->parsedString
);
137 if (value
->isAllocVal
) free(value
->value
);
140 fieldValueList
.reset();
144 iter
= conditionValueList
.getIterator();
145 ConditionValue
*condVal
;
146 while (iter
.hasElement())
148 condVal
= (ConditionValue
*)iter
.nextElement();
149 free(condVal
->parsedString
);
150 free(condVal
->value
);
153 conditionValueList
.reset();
155 iter
= updFldValList
.getIterator();
156 UpdateFieldValue
*updFldVal
;
157 while (iter
.hasElement())
159 updFldVal
= (UpdateFieldValue
*)iter
.nextElement();
160 free(updFldVal
->parsedString
);
161 free(updFldVal
->value
);
164 updFldValList
.reset();
165 groupFieldNameList
.reset();
166 iter
= tableNameList
.getIterator();
168 while (iter
.hasElement())
170 tname
= (TableName
*)iter
.nextElement();
173 tableNameList
.reset();
175 creFldList
.removeAll();
178 indexType
= hashIndex
;
180 void ParsedData::clearFieldNameList()
182 fieldNameList
.reset();
185 void ParsedData::setFldName(char *name
)
187 strcpy(fldDef
.fldName_
, name
);
188 fldDef
.fldName_
[IDENTIFIER_LENGTH
] = '\0';
191 void ParsedData::setFldType(DataType type
)
196 void ParsedData::setFldLength(size_t length
)
198 if(fldDef
.type_
== typeBinary
) fldDef
.length_
= length
- 1;
199 else fldDef
.length_
= length
;
202 void ParsedData::setFldNotNull(bool notNull
)
204 fldDef
.isNull_
= notNull
;
206 void ParsedData::setDefaultValue(char *value
)
208 fldDef
.isDefault_
= true;
209 if (strlen(value
) > DEFAULT_VALUE_BUF_LENGTH
-1)
211 strncpy(fldDef
.defaultValueBuf_
, value
, DEFAULT_VALUE_BUF_LENGTH
-1);
212 fldDef
.defaultValueBuf_
[DEFAULT_VALUE_BUF_LENGTH
] ='\0';
214 strcpy(fldDef
.defaultValueBuf_
, value
);
219 void ParsedData::insertFldDef()
221 DbRetVal rv
= creFldList
.append(fldDef
);