24 #ifndef Safir_Databases_Statement_h
25 #define Safir_Databases_Statement_h
28 #include "Safir/Databases/Odbc/Internal/InternalDefs.h"
29 #include "Safir/Databases/Odbc/Internal/Parameter.h"
30 #include "Safir/Databases/Odbc/Internal/Column.h"
31 #include "Safir/Databases/Odbc/Internal/BufferedWideStringParameter.h"
32 #include "Safir/Databases/Odbc/Internal/NonBufferedWideStringParameter.h"
33 #include "Safir/Databases/Odbc/Internal/BufferedBinaryParameter.h"
34 #include "Safir/Databases/Odbc/Internal/NonBufferedBinaryParameter.h"
35 #include "Safir/Databases/Odbc/Internal/BinaryColumn.h"
36 #include "Safir/Databases/Odbc/Internal/WideStringColumn.h"
38 #include <boost/noncopyable.hpp>
51 #pragma warning(disable: 4275)
59 class OLIB_API
Statement :
private boost::noncopyable
116 void Prepare(
const std::wstring & wszSqlCommand);
127 void ExecDirect(
const std::wstring & wszSqlCommand);
159 int GetNumberOfColumns()
const;
169 void SetStmtAttr(
long lAttribute,
long lValue);
179 void SetStmtAttr(
long lAttribute,
const std::wstring & wszValue);
189 void GetStmtAttr(
long lAttribute,
long & lValue)
const;
200 void GetStmtAttr(
long lAttribute,
wchar_t * wszValue,
unsigned long ulLength)
const;
211 bool ParamData(
unsigned short & lParameter)
const;
224 template<
short sCType,
short sSqlType,
class Type,
short sInputOutputType,
unsigned long lColumnSize>
225 void BindParameter(
unsigned short usParameterNumber,
226 Internal::Parameter<sCType, sSqlType, Type, sInputOutputType,lColumnSize> & param );
227 template<
short sSqlType,
short sInputOutputType>
228 void BindParameter(
unsigned short usParameterNumber,
229 Internal::NonBufferedWideStringParameter<sSqlType, sInputOutputType> & param );
243 template<
short sCType,
short sSqlType,
class Type,
short sInputOutputType,
unsigned long lColumnSize>
244 void BindLongParameter(
unsigned short usParameterNumber,
245 Internal::Parameter<sCType, sSqlType, Type, sInputOutputType,lColumnSize> & param );
257 template<
short sValueType,
class Type>
258 void BindColumn(
unsigned short usColumnNumber,
259 Internal::Column<sValueType, Type> & column );
271 template<
short sValueType,
class Type>
272 bool GetData(
unsigned short usColumnNumber,
273 Internal::Column<sValueType, Type> & column );
283 template<
short sCType,
short sSqlType,
class Type,
short sInputOutputType,
unsigned long lColumnSize>
284 void PutData(Internal::Parameter<sCType, sSqlType, Type, sInputOutputType,lColumnSize> & param );
296 bool GetDiagRec(
short sRecNumber,
297 std::wstring & SqlState,
298 boost::int32_t & NativeError,
299 std::wstring & MessageText,
300 bool & bDataRead)
const;
306 bool IsValid()
const;
312 SQLHDBC Handle()
const;
314 SQLHSTMT m_hStatement;
318 void ThrowException(
const std::wstring & fileName,
320 SQLRETURN original_returncode)
const;
321 void ThrowException(SQLSMALLINT HandleType,
323 const std::wstring & fileName,
325 SQLRETURN original_returncode)
const;
343 return m_hStatement != SQL_NULL_HSTMT;
347 void Statement::SetNotValid()
349 m_hStatement = SQL_NULL_HSTMT;
352 template<
short sValueType,
class Type>
354 Internal::Column<sValueType, Type> & column )
357 bool bDataFound =
true;
362 ret = ::SQLGetData( m_hStatement,
364 column.m_csValueType,
365 column.GetValuePtr(),
367 column.GetLengthOrIndPtr());
368 if (ret==SQL_NO_DATA_FOUND)
370 else if (!SQL_SUCCEEDED(ret))
378 template<
short sValueType,
class Type>
380 Internal::Column<sValueType, Type> & column )
387 ret = ::SQLBindCol( m_hStatement,
389 column.m_csValueType,
390 column.GetValuePtr(),
392 column.GetLengthOrIndPtr());
393 if (!SQL_SUCCEEDED(ret))
399 template<
short sCType,
short sSqlType,
class Type,
short sInputOutputType,
unsigned long lColumnSize>
401 Internal::Parameter<sCType, sSqlType, Type, sInputOutputType,lColumnSize> & param )
408 ret = ::SQLBindParameter( m_hStatement,
410 param.m_csInputOutputType,
413 param.GetColumnSize(),
417 param.GetLengthOrIndPtr() );
418 if (!SQL_SUCCEEDED(ret))
424 template<
short sSqlType,
short sInputOutputType>
426 Internal::NonBufferedWideStringParameter<sSqlType, sInputOutputType> & )
432 template<
short sCType,
short sSqlType,
class Type,
short sInputOutputType,
unsigned long lColumnSize>
434 Internal::Parameter<sCType, sSqlType, Type, sInputOutputType,lColumnSize> & param )
441 ret = ::SQLBindParameter( m_hStatement,
443 param.m_csInputOutputType,
446 param.GetColumnSize(),
448 reinterpret_cast<SQLPOINTER
>(usParameterNumber),
450 param.GetLengthOrIndPtr() );
451 if (!SQL_SUCCEEDED(ret))
457 template<
short sCType,
short sSqlType,
class Type,
short sInputOutputType,
unsigned long lColumnSize>
458 void Statement::PutData(Internal::Parameter<sCType, sSqlType, Type, sInputOutputType,lColumnSize> & param )
465 ret = ::SQLPutData( m_hStatement,
469 if (!SQL_SUCCEEDED(ret))
481 #endif // Safir_Databases_Statement_h
Meant to be used when something goes very wrong.
Definition: Exceptions.h:360
SQLHDBC Handle() const
Returns the ODBC Handle of the statement.
Definition: Statement.h:335
DotsC_Int64 Int64
64 bit integer type.
Definition: Defs.h:70
#define __WFILE__
Definition: Exceptions.h:31
void BindParameter(unsigned short usParameterNumber, Internal::Parameter< sCType, sSqlType, Type, sInputOutputType, lColumnSize > ¶m)
Binds a parameter to a statement.
Definition: Statement.h:400
bool IsValid() const
Checks if this statement is a valid allocated statement.
Definition: Statement.h:341
void PutData(Internal::Parameter< sCType, sSqlType, Type, sInputOutputType, lColumnSize > ¶m)
Put data into a parameter.
Definition: Statement.h:458
The Statement class models a statement made to the database engine and one statement object should be...
Definition: Statement.h:59
bool GetData(unsigned short usColumnNumber, Internal::Column< sValueType, Type > &column)
Get data from a column.
Definition: Statement.h:353
void BindColumn(unsigned short usColumnNumber, Internal::Column< sValueType, Type > &column)
Binds a column to a statement.
Definition: Statement.h:379
The Connection class models a connection made to the database engine.
Definition: Connection.h:53
void BindLongParameter(unsigned short usParameterNumber, Internal::Parameter< sCType, sSqlType, Type, sInputOutputType, lColumnSize > ¶m)
Binds a long parameter to a statement.
Definition: Statement.h:433