Bug in putting the prepare packet in the list
[csql.git] / src / sql / SqlStatement.cxx
blob5ad5c9366c32cedd032d126d21a896d3224a7a7b
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 * 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 ***************************************************************************/
20 #include "Statement.h"
21 #include <SqlStatement.h>
22 #include <dmllex.h>
24 char *lexInput;
25 extern ParsedData *parsedData;
27 int yyparse ();
29 SqlStatement::SqlStatement()
31 sqlCon = NULL;
32 stmt = NULL;
34 void SqlStatement::setConnection(AbsSqlConnection *conn)
36 sqlCon = (SqlConnection*)conn;
37 con = conn;
40 void SqlStatement::setSqlConnection(SqlConnection *conn)
42 sqlCon = conn;
45 DbRetVal SqlStatement::prepare(char *stmtstr)
47 DbRetVal rv = OK;
48 lexInput = stmtstr;
49 parsedData = &pData;
50 yy_scan_string( stmtstr );
51 int rc = yyparse();
52 if (rc != 0)
54 free();
55 parsedData = NULL;
56 yyrestart(yyin);
57 return ErrSyntaxError;
59 stmt = StatementFactory::getStatement(parsedData);
60 stmt->setDbMgr(sqlCon->getConnObject().getDatabaseManager());
61 rv = stmt->resolve();
62 if (rv != OK)
64 free();
65 parsedData = NULL;
66 yyrestart(yyin);
67 return rv;
69 parsedData = NULL;
70 yyrestart(yyin);
71 return OK;
74 char* SqlStatement::getTableName()
76 return pData.getTableName();
79 bool SqlStatement::isSelect()
81 if (pData.getStmtType() == SelectStatement) return true;
82 return false;
85 DbRetVal SqlStatement::execute(int &rowsAffected)
87 DbRetVal rv = OK;
88 rv = stmt->execute(rowsAffected);
89 return rv;
92 void* SqlStatement::fetch()
94 if (pData.getStmtType() != SelectStatement) return NULL;
95 SelStatement *selStmt = (SelStatement*) stmt;
96 return selStmt->fetch();
99 void* SqlStatement::fetchAndPrint()
101 if (pData.getStmtType() != SelectStatement) return NULL;
102 SelStatement *selStmt = (SelStatement*) stmt;
103 return selStmt->fetchAndPrint();
106 DbRetVal SqlStatement::bindParam(int pos, void* value)
108 DbRetVal rv = OK;
109 rv = stmt->setParam(pos, value);
110 return rv;
113 DbRetVal SqlStatement::bindField(int pos, void* value)
115 DbRetVal rv = OK;
116 if (pData.getStmtType() != SelectStatement) return ErrBadCall;
117 SelStatement *selStmt = (SelStatement*) stmt;
118 rv = selStmt->setBindField(pos, value);
119 return rv;
121 void* SqlStatement::next()
123 if (pData.getStmtType() != SelectStatement) return 0;
124 SelStatement *selStmt = (SelStatement*) stmt;
125 return( (void*) selStmt->next() );
128 DbRetVal SqlStatement::close()
130 if (pData.getStmtType() != SelectStatement) return OK;
131 SelStatement *selStmt = (SelStatement*) stmt;
132 return selStmt->close();
135 void* SqlStatement::getFieldValuePtr( int pos )
137 if (pData.getStmtType() != SelectStatement) return 0;
138 SelStatement *selStmt = (SelStatement*) stmt;
139 return( (void*) selStmt->getFieldValuePtr( pos ) );
142 int SqlStatement::noOfProjFields()
144 if (pData.getStmtType() != SelectStatement) return 0;
145 SelStatement *selStmt = (SelStatement*) stmt;
146 return selStmt->noOfProjFields();
149 int SqlStatement::noOfParamFields()
151 return stmt->noOfParamFields();
154 DbRetVal SqlStatement::getProjFldInfo (int projpos, FieldInfo *&fInfo)
156 DbRetVal rv = OK;
157 if (pData.getStmtType() != SelectStatement) return ErrBadCall;
158 SelStatement *selStmt = (SelStatement*) stmt;
159 rv = selStmt->getProjFldInfo(projpos, fInfo);
160 return rv;
163 DbRetVal SqlStatement::getParamFldInfo (int parampos, FieldInfo *&fInfo)
165 DbRetVal rv = OK;
166 if (pData.getStmtType() ==SelectStatement ||
167 pData.getStmtType() ==InsertStatement ||
168 pData.getStmtType() ==UpdateStatement ||
169 pData.getStmtType() ==DeleteStatement)
172 DmlStatement *dmlStmt = (DmlStatement*) stmt;
173 rv = dmlStmt->getParamFldInfo(parampos, fInfo);
175 return rv;
178 DbRetVal SqlStatement::free()
180 delete stmt;
181 stmt = NULL;
182 pData.reset();
185 void SqlStatement::setShortParam(int paramPos, short value)
187 stmt->setShortParam(paramPos, value);
189 void SqlStatement::setIntParam(int paramPos, int value)
191 stmt->setIntParam(paramPos, value);
193 void SqlStatement::setLongParam(int paramPos, long value)
195 stmt->setLongParam(paramPos, value);
197 void SqlStatement::setLongLongParam(int paramPos, long long value)
199 stmt->setLongLongParam(paramPos, value);
201 void SqlStatement::setByteIntParam(int paramPos, ByteInt value)
203 stmt->setByteIntParam(paramPos, value);
205 void SqlStatement::setFloatParam(int paramPos, float value)
207 stmt->setFloatParam(paramPos, value);
209 void SqlStatement::setDoubleParam(int paramPos, double value)
211 stmt->setDoubleParam(paramPos, value);
213 void SqlStatement::setStringParam(int paramPos, char *value)
215 stmt->setStringParam(paramPos, value);
217 void SqlStatement::setDateParam(int paramPos, Date value)
219 stmt->setDateParam(paramPos, value);
221 void SqlStatement::setTimeParam(int paramPos, Time value)
223 stmt->setTimeParam(paramPos, value);
225 void SqlStatement::setTimeStampParam(int paramPos, TimeStamp value)
227 stmt->setTimeStampParam(paramPos, value);