Feature: 1501518
[csql.git] / include / SqlStatement.h
blob7ad79efb5f46858f9a3bc25c8facdd15c751361e
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 #ifndef SQLSTATEMENT_H
21 #define SQLSTATEMENT_H
22 #include <SqlConnection.h>
23 //#include "Statement.h"
24 //#include<CSql.h>
25 class Statement;
26 class ParsedData;
28 /**
29 * @class SqlStatement
31 * @brief Handle to the sql statement.
32 * It is used to execute queries and return the values from the database<br>
33 * Sql Statement is fed to the prepare method first and then it should be executed. <br/>
34 * Functionality: <br/>
35 * 1.Input values for insert statement <br/>
36 * 2.Iterator for retrieving rows from the table <br/>
37 * 3.Parameter support for performance.<br/>
38 * <br/>
39 * @author Prabakaran Thirumalai
41 class SqlStatement
43 public:
44 /** Default constructor
46 SqlStatement();
47 /** sets connection handle to be used for subsequent operations
48 * @param con SqlConnection*
50 void setConnection(SqlConnection *con);
52 /** compiles the sql statement. It calls the parser and tokenizes the statement
53 * into logical plan. This method sets the statement string which needs to be executed.
54 * free method needs to be called, if application wants to use the same handle to compile
55 * another sql statement.
56 * @param stmt sql statement string
57 * @returns DbRetVal
59 DbRetVal prepare(char *stmt);
61 /** executes the sql statement. For insert, update, delete queries execute performs the
62 * required operation on the table.
63 * For Select queries, application should call execute before they start fetching
64 * the values from the table.This starts scan on the table.
65 * @param rowsAffect number of rows affected by the sql statement
66 * @returns DbRetVal
68 DbRetVal execute(int &rowsAffect);
70 /**fetches the next tuple from the result of the execution of sql select query.
71 * execute should be called before calling this method. Application buffer should be
72 * binded to get the tuple values.
73 * @returns void* NULL if there is no tuple.
75 void* fetch();
77 /** binds application buffer to the specified parameter position in the sql statement.
78 * This method should be called for all the parameters in the sql statement.If not
79 * execute will return error.
80 * <br/>
81 * @param pos position of the parameter in the statement
82 * @param val address of the application buffer. Memory should be allocated by
83 * the application before binding the buffer.
85 DbRetVal bindParam(int pos, void*);
87 /** binds application buffer to the specified field position of the projection list
88 * in the select query. This method should be called only for select queries.
89 * Before executing select queries, required fields must be binded first.
90 * <br/>
91 * @param pos position in the projection list
92 * @param val address of the application buffer. Memory should be allocated by
93 * the application before binding the buffer.
95 DbRetVal bindField(int pos, void* val);
97 /**Fres all the resources held for the sql statement. Needs to be called before calling prepare again on the same statement handle.
98 * @returns DbRetVal
100 DbRetVal free();
102 /**Retrieves the total number of projection fields in the statement
103 * @returns int no of projection fields
105 int noOfProjFields();
107 /**Retrieves the total number of parameters in the statement
108 * @returns int no of parameters
110 int noOfParamFields();
112 /**Retrieves the field info for the required projection field position in statement
113 * @param projPos int - projection field position
114 * @param info FieldInfo*& - OUT parameter
115 * @returns DbRetVal
117 DbRetVal getProjFldInfo(int projPos, FieldInfo *&info);
119 /**Retrieves the field info for the required parameter position in statement
120 * @param projPos int - parameter position
121 * @param info FieldInfo*& - OUT parameter
122 * @returns DbRetVal
124 DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
126 private:
127 SqlConnection *con;
128 Statement *stmt;
129 ParsedData pData;
132 #endif