Files
Work/sql/SQLSTMT.HPP
2024-08-07 09:16:27 -04:00

120 lines
2.4 KiB
C++

#ifndef _SQL_SQLSTATEMENT_HPP_
#define _SQL_SQLSTATEMENT_HPP_
#ifndef _COMMON_STRING_HPP_
#include <common/string.hpp>
#endif
#ifndef _COMMON_BLOCK_HPP_
#include <common/block.hpp>
#endif
#ifndef _COMMON_ASSERT_HPP_
#include <common/assert.hpp>
#endif
#ifndef _SQL_SQLDATA_HPP_
#include <sql/sqldata.hpp>
#endif
#ifndef _SQL_SQLDB_HPP_
#include <sql/sqldb.hpp>
#endif
#ifndef _SQL_SQL_HPP_
#include <sql/sql.hpp>
#endif
class SQLBind;
class SQLStatement
{
friend class SQLErr;
public:
class SQLColumnNotFound{};
SQLStatement(void);
SQLStatement(SQLDb &someSQLDb,SQLBind &sqlBind);
SQLStatement(SQLDb &someSQLDb);
virtual ~SQLStatement();
SQLStatement &operator=(const SQLDb &someSQLDb);
SQLData &operator[](int colIndex);
SQLData &operator[](const String &strNameData);
DWORD size(void)const;
BOOL executeDirect(const String &sqlStatementString);
BOOL executeDirect(const String &sqlStatementString,String &strResult);
BOOL call(const String &procName);
WORD sqlResults(void);
WORD tables(String database,String owner,String name,String type);
WORD tables(void);
void close(void);
WORD open(void);
WORD commit(void);
WORD fetch(bool silent=false)const;
WORD cancel(void)const;
int rowCount(void)const;
WORD isOkay(void)const;
private:
enum {MaxColName=255,MaxImageLength=768000};
operator HSTMT(void)const;
WORD mIsOkay;
HSTMT mhStatement;
Block<SQLData> mSQLColumnData;
SQLDb mSQLDb;
};
inline
SQLData &SQLStatement::operator[](int colIndex)
{
assert(colIndex<mSQLColumnData.size());
return mSQLColumnData[colIndex];
}
inline
SQLStatement::operator HSTMT(void)const
{
if(!isOkay())return FALSE;
return mhStatement;
}
inline
void SQLStatement::close(void)
{
if(!isOkay())return;
if(mhStatement){::SQLFreeStmt(mhStatement,SQL_DROP);mhStatement=FALSE;}
mIsOkay=FALSE;
}
inline
WORD SQLStatement::open(void)
{
close();
if(SQL_SUCCESS==::SQLAllocStmt((HandleDatabase)mSQLDb,&mhStatement))return (mIsOkay=TRUE);
return (mIsOkay=FALSE);
}
inline
WORD SQLStatement::commit(void)
{
return executeDirect("commit");
}
inline
WORD SQLStatement::tables(void)
{
return tables(String(),String(),String(),String());
}
inline
BOOL SQLStatement::call(const String &procName)
{
if(!isOkay())return FALSE;
return executeDirect(String("call ")+procName);
}
inline
DWORD SQLStatement::size(void)const
{
return mSQLColumnData.size();
}
inline
WORD SQLStatement::isOkay(void)const
{
return mIsOkay;
}
#endif