Bug in putting the prepare packet in the list
[csql.git] / src / sql / DdlStatement.cxx
blob71ebc15cf120c6aacb8f836f03e0b8872adf586a
1 /***************************************************************************
2 * Copyright (C) 2007 by Prabakaran Thirumalai *
3 * praba_tuty@yahoo.com *
4 * *
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. *
9 * *
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. *
14 * *
15 ***************************************************************************/
16 #include "Statement.h"
17 #include <Info.h>
18 CreateTblStatement::CreateTblStatement()
20 parsedData = NULL;
21 dbMgr = NULL;
24 CreateTblStatement::~CreateTblStatement()
26 tblDef.reset();
28 DbRetVal CreateTblStatement::execute(int &rowsAffected)
30 DbRetVal rv = OK;
31 rv = dbMgr->createTable(tblName, tblDef);
32 if (rv != OK) return rv;
33 if (parsedData->getFieldNameList().size() > 0)
35 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
36 strcpy(idxInfo->tableName, tblName);
37 ListIterator iter = parsedData->getFieldNameList().getIterator();
38 FieldName *name = NULL;
39 while (iter.hasElement())
41 name = (FieldName*)iter.nextElement();
42 idxInfo->list.append(name->fldName);
44 idxInfo->indType = hashIndex;
45 idxInfo->isPrimary = true;
46 idxInfo->isUnique = true;
48 char indName[IDENTIFIER_LENGTH];
49 sprintf(indName, "%s_idx1_Primary", tblName);
50 rv = dbMgr->createIndex(indName, idxInfo);
51 delete idxInfo;
53 return rv;
56 DbRetVal CreateTblStatement::resolve()
58 DbRetVal rv = OK;
59 strcpy(tblName, parsedData->getTableName());
60 FieldIterator iter = parsedData->getCreFldList().getIterator();
61 FieldDef fDef;
63 int i = 0;
64 FieldName *name = NULL;
65 ListIterator nIter = parsedData->getFieldNameList().getIterator();
66 while (iter.hasElement())
68 fDef = iter.nextElement();
69 nIter.reset();
70 while (nIter.hasElement())
72 name = (FieldName*)nIter.nextElement();
73 if (strcmp(name->fldName, fDef.fldName_) == 0) fDef.isNull_ = true;
77 //TODO : need a new addField function which can take FieldDef as parameter.
78 if (!fDef.isDefault_) {
79 i = tblDef.addField(fDef.fldName_, fDef.type_, fDef.length_,
80 NULL,fDef.isNull_);
81 } else {
82 i = tblDef.addField(fDef.fldName_, fDef.type_, fDef.length_,
83 fDef.defaultValueBuf_,fDef.isNull_);
85 if( 0 != i )
87 printError(ErrUnknown, "Error while adding field");
88 rv = ErrUnknown;
89 break;
92 return rv;
95 ///////////////////////////////////////
96 CreateIdxStatement::CreateIdxStatement()
98 parsedData = NULL;
99 dbMgr = NULL;
102 CreateIdxStatement::~CreateIdxStatement()
107 DbRetVal CreateIdxStatement::execute(int &rowsAffected)
109 DbRetVal rv = OK;
110 if (parsedData->getFieldNameList().size() > 0)
112 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
113 strcpy(idxInfo->tableName, parsedData->getTableName());
114 ListIterator iter = parsedData->getFieldNameList().getIterator();
115 FieldName *name = NULL;
116 while (iter.hasElement())
118 name = (FieldName*)iter.nextElement();
119 idxInfo->list.append(name->fldName);
121 idxInfo->indType = parsedData->getIndexType();
122 idxInfo->isPrimary = parsedData->getPrimary();
123 idxInfo->isUnique = parsedData->getUnique();
124 rv = dbMgr->createIndex(parsedData->getIndexName(), idxInfo);
125 delete idxInfo;
127 return rv;
130 DbRetVal DropTblStatement::execute(int &rowsAffected)
132 DbRetVal rv = OK;
133 rv = dbMgr->dropTable(parsedData->getTableName());
134 return rv;
137 DbRetVal DropIdxStatement::execute(int &rowsAffected)
139 DbRetVal rv = OK;
140 rv = dbMgr->dropIndex(parsedData->getIndexName());
141 return rv;