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 * 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>
25 extern ParsedData
*parsedData
;
29 SqlStatement::SqlStatement()
34 void SqlStatement::setConnection(AbsSqlConnection
*conn
)
36 sqlCon
= (SqlConnection
*)conn
;
40 void SqlStatement::setSqlConnection(SqlConnection
*conn
)
45 DbRetVal
SqlStatement::prepare(char *stmtstr
)
50 yy_scan_string( stmtstr
);
57 return ErrSyntaxError
;
59 stmt
= StatementFactory::getStatement(parsedData
);
60 stmt
->setDbMgr(sqlCon
->getConnObject().getDatabaseManager());
74 char* SqlStatement::getTableName()
76 return pData
.getTableName();
79 bool SqlStatement::isSelect()
81 if (pData
.getStmtType() == SelectStatement
) return true;
85 DbRetVal
SqlStatement::execute(int &rowsAffected
)
88 rv
= stmt
->execute(rowsAffected
);
92 void* SqlStatement::fetch()
94 if (pData
.getStmtType() != SelectStatement
) return NULL
;
95 SelStatement
*selStmt
= (SelStatement
*) stmt
;
96 return selStmt
->fetch();
99 void* SqlStatement::fetchAndPrint(bool SQL
)
101 if (pData
.getStmtType() != SelectStatement
) return NULL
;
102 SelStatement
*selStmt
= (SelStatement
*) stmt
;
103 return selStmt
->fetchAndPrint(SQL
);
106 DbRetVal
SqlStatement::bindParam(int pos
, void* value
)
109 rv
= stmt
->setParam(pos
, value
);
113 DbRetVal
SqlStatement::bindField(int pos
, void* value
)
116 if (pData
.getStmtType() != SelectStatement
) return ErrBadCall
;
117 SelStatement
*selStmt
= (SelStatement
*) stmt
;
118 rv
= selStmt
->setBindField(pos
, value
);
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
)
157 if (pData
.getStmtType() != SelectStatement
) return ErrBadCall
;
158 SelStatement
*selStmt
= (SelStatement
*) stmt
;
159 rv
= selStmt
->getProjFldInfo(projpos
, fInfo
);
163 DbRetVal
SqlStatement::getParamFldInfo (int parampos
, FieldInfo
*&fInfo
)
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
);
178 DbRetVal
SqlStatement::free()
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
);