src/sql/ParsedData.cxx

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Prabakaran Thirumalai   *
00003  *   praba_tuty@yahoo.com   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015   ***************************************************************************/
00016 #include "Parser.h"
00017 #include <CSql.h>
00018 #include<PredicateImpl.h>
00019 
00020 
00021 void ParsedData::insertValue(char *val)
00022 {
00023     FieldValue *newVal = new FieldValue();
00024     if (val == NULL) 
00025         newVal->parsedString = NULL;
00026     else 
00027         newVal->parsedString = strdup(val);
00028     newVal->value = NULL;
00029     newVal->paramNo = 0;
00030     newVal->type = typeUnknown;
00031     newVal->length = 0;
00032     fieldValueList.append(newVal);
00033 }
00034 
00035 void ParsedData::insertInValue(char *val)
00036 {
00037     FieldValue *newVal = new FieldValue();
00038     if (val == NULL) 
00039         newVal->parsedString = NULL;
00040     else 
00041         newVal->parsedString = strdup(val);
00042     newVal->value = NULL;
00043     newVal->paramNo = 0;
00044     newVal->type = typeUnknown;
00045     newVal->length = 0;
00046     inValueList.append(newVal);
00047 }
00048 
00049 void** ParsedData::insertCondValueAndGetPtr(char *fldName, char *val)
00050 {
00051     ConditionValue *newVal = new ConditionValue();
00052     if (val == NULL) 
00053         newVal->parsedString = NULL;
00054     else
00055         newVal->parsedString = strdup(val);
00056     newVal->value = NULL;
00057     newVal->paramNo = 0;
00058     newVal->type = typeUnknown;
00059     newVal->length = 0;
00060     strcpy(newVal->fName, fldName);
00061     conditionValueList.append(newVal);
00062     return &(newVal->value);
00063 
00064 }
00065 
00066 void ParsedData::insertField(char *fName)
00067 {
00068     FieldName *newVal = new FieldName();
00069     strcpy(newVal->fldName , fName);
00070     fieldNameList.append(newVal);
00071 }
00072 
00073 void ParsedData::insertUpdateValue(char *fName, char *val)
00074 {
00075     UpdateFieldValue *newVal = new UpdateFieldValue();
00076     strcpy(newVal->fldName, fName);
00077     if (val == NULL) 
00078         newVal->parsedString = NULL;
00079     else 
00080         newVal->parsedString = strdup(val);
00081     newVal->value = NULL;
00082     newVal->paramNo = 0;
00083     updFldValList.append(newVal);
00084 }
00085 
00086 Predicate* ParsedData::insertPredicate(char *fName, ComparisionOp op, void **val)
00087 {
00088     PredicateImpl *pImpl = new PredicateImpl();
00089     pImpl->setTerm(fName, op, val);
00090     return (Predicate*) pImpl;
00091 }
00092 Predicate* ParsedData::insertPredicate(char *fName1, ComparisionOp op, char *fName2)
00093 {
00094     PredicateImpl *pImpl = new PredicateImpl();
00095     pImpl->setTerm(fName1, op, fName2);
00096     return (Predicate*) pImpl;
00097 }
00098 
00099 Predicate* ParsedData::insertPredicate(Predicate *p1, LogicalOp op, Predicate *p2)
00100 {
00101     PredicateImpl *pImpl = new PredicateImpl();
00102     pImpl->setTerm(p1, op, p2);
00103     return (Predicate*) pImpl;
00104 }
00105 
00106 void ParsedData::reset()
00107 {
00108     ListIterator fNameIter = fieldNameList.getIterator();
00109     fNameIter.reset();
00110     while (fNameIter.hasElement())
00111         delete (Identifier *) fNameIter.nextElement();
00112     fieldNameList.reset();
00113     ListIterator iter = fieldValueList.getIterator();
00114     FieldValue *value;
00115     while (iter.hasElement())
00116     {
00117         value = (FieldValue*)iter.nextElement();
00118         free(value->parsedString);
00119         free(value->value);
00120         delete value;
00121     }
00122     fieldValueList.reset();
00123     inValueList.reset();
00124     predicate.reset();
00125 
00126     iter = conditionValueList.getIterator();
00127     ConditionValue *condVal;
00128     while (iter.hasElement())
00129     {
00130         condVal = (ConditionValue*)iter.nextElement();
00131         free(condVal->parsedString);
00132         free(condVal->value);
00133         delete condVal;
00134     }
00135     conditionValueList.reset();
00136 
00137     iter = updFldValList.getIterator();
00138     UpdateFieldValue *updFldVal;
00139     while (iter.hasElement())
00140     {
00141         updFldVal = (UpdateFieldValue*)iter.nextElement();
00142         free(updFldVal->parsedString);
00143         free(updFldVal->value);
00144         delete updFldVal;
00145     }
00146     updFldValList.reset();
00147     
00148     creFldList.removeAll();
00149     isUnique = false; 
00150     isPrimary = false; 
00151     indexType = hashIndex;
00152 }
00153 void ParsedData::clearFieldNameList()
00154 {
00155     fieldNameList.reset();
00156 }
00157 
00158 void ParsedData::setFldName(char *name)
00159 {
00160     strcpy(fldDef.fldName_, name);
00161     fldDef.fldName_[IDENTIFIER_LENGTH] = '\0';
00162 }
00163 
00164 void ParsedData::setFldType(DataType type)
00165 {
00166     fldDef.type_ = type;
00167 }
00168 
00169 void ParsedData::setFldLength(size_t length)
00170 {
00171     fldDef.length_ = length;
00172 }
00173 
00174 void ParsedData::setFldNotNull(bool notNull)
00175 {
00176     fldDef.isNull_ = notNull;
00177 }
00178 void ParsedData::setDefaultValue(char *value)
00179 {
00180     fldDef.isDefault_ = true;
00181     if (strlen(value) > DEFAULT_VALUE_BUF_LENGTH -1) 
00182     {
00183         strncpy(fldDef.defaultValueBuf_, value, DEFAULT_VALUE_BUF_LENGTH -1);
00184         fldDef.defaultValueBuf_[DEFAULT_VALUE_BUF_LENGTH] ='\0';
00185     } else
00186         strcpy(fldDef.defaultValueBuf_, value);
00187     return;
00188 }
00189 
00190 
00191 void ParsedData::insertFldDef()
00192 {
00193     DbRetVal rv = creFldList.append(fldDef);
00194     fldDef.init();
00195 }

Generated on Mon Jun 9 22:37:15 2008 for csql by  doxygen 1.4.7