📄 sqldata.h
字号:
//////////////////////////////////////////////////////////////////////
//
// DB2 Access Object Version 1.0
//
// Developer: Jeff Lee
// Jan 10, 2003
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_SQLDATA_H__CA4CC4FF_1B45_434F_9368_59E1B8AC250D__INCLUDED_)
#define AFX_SQLDATA_H__CA4CC4FF_1B45_434F_9368_59E1B8AC250D__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <string>
// to make sqlcli.h happy for AIX
#if !defined(WINDOWS) && !defined(_MSC_VER)
#undef FAR
#define SQLWIN;
#endif
#include <sqlcli1.h>
#include <sqlutil.h>
#include <sqlenv.h>
#include "BaseDef.h"
//////////////////////////////////////////////////////////////////////
// class CSqlVariant - The base class that represents a variant
// which has standard SQL data type
#define MAX_SQL_TYPE 26
class CSqlCommand;
class CSqlVariant
{
public:
CSqlVariant();
CSqlVariant(const CSqlVariant& rVar);
virtual ~CSqlVariant();
protected:
struct CDataType
{
SQLSMALLINT nSqlType; // symbolic SQL data type
SQLSMALLINT nDataType; // symbolic C data type
SQLINTEGER nDataSize; // length of data
SQLINTEGER nDisplaySize; // the maximum size to display data in character form
};
static const CDataType m_tblDataType[MAX_SQL_TYPE];
protected:
struct CSqlBuffer
{
SQLSMALLINT nSqlType; // SQL data type
SQLUINTEGER nPrecision; // precision
SQLSMALLINT nScale; // scale
SQLSMALLINT nDataType; // C data type
SQLINTEGER nBufferSize; // length of the data buffer
SQLSMALLINT nRefs; // reference count to this object
SQLINTEGER nIndicator; // indicator or length of data
union // buffer of the variant
{
SQLCHAR pVal[1];
SQLSMALLINT iVal;
SQLINTEGER nVal;
SQLBIGINT lVal;
SQLREAL fltVal;
SQLDOUBLE dbVal;
DATE_STRUCT dtVal;
TIME_STRUCT tmVal;
SQLDBCHAR pwVal[1];
};
};
static const CSqlBuffer m_defData;
CSqlBuffer *m_pData; // the buffer of the variant
protected:
BOOL IsDefault() const;
void InitData();
BOOL AllocBuffer(SQLINTEGER nDataSize);
void FreeBuffer();
BOOL CreateBuffer(SQLSMALLINT nSqlType, SQLUINTEGER nPrecision);
public:
void CopyData(const CSqlVariant& rValue);
CSqlVariant& operator=(const CSqlVariant& rValue);
SQLSMALLINT GetSqlType() const;
SQLSMALLINT GetDataType() const;
SQLUINTEGER GetPrecision() const;
SQLSMALLINT GetScale() const;
SQLINTEGER GetMaxSize() const;
SQLINTEGER GetDisplaySize() const;
BOOL SetValue(const void* pValue, SQLINTEGER nValueSize=0);
BOOL FromInteger(int nValue);
BOOL FromDouble(double nValue);
BOOL FromString(const char* pszValue);
SQLINTEGER GetLength() const;
BOOL IsNull() const;
void SetNull();
operator short() const;
operator int() const;
operator double() const;
operator const char*() const;
int ToString(std::string& strValue);
SQLCHAR* GetBuffer() const;
const DATE_STRUCT* GetDate() const;
const TIME_STRUCT* GetTime() const;
const TIMESTAMP_STRUCT* GetTimeStamp() const;
virtual BOOL Bind(CSqlCommand* pStmt, int nOrdinal) = 0;
virtual BOOL Unbind(CSqlCommand* pStmt, int nOrdinal) = 0;
};
inline BOOL CSqlVariant::IsDefault() const
{ return m_pData == &m_defData; }
inline void CSqlVariant::InitData()
{ m_pData = (CSqlBuffer*)&m_defData; }
inline CSqlVariant& CSqlVariant::operator=(const CSqlVariant& rValue)
{
CopyData(rValue);
return *this;
}
inline SQLSMALLINT CSqlVariant::GetSqlType() const
{ return m_pData->nSqlType; }
inline SQLSMALLINT CSqlVariant::GetDataType() const
{ return m_pData->nDataType; }
inline SQLUINTEGER CSqlVariant::GetPrecision() const
{ return m_pData->nPrecision; }
inline SQLSMALLINT CSqlVariant::GetScale() const
{ return m_pData->nScale; }
inline SQLINTEGER CSqlVariant::GetMaxSize() const
{ return m_pData->nBufferSize; }
inline SQLINTEGER CSqlVariant::GetLength() const
{ return m_pData->nIndicator; }
inline BOOL CSqlVariant::IsNull() const
{ return m_pData->nIndicator == SQL_NULL_DATA; }
inline void CSqlVariant::SetNull()
{
if (!IsDefault())
m_pData->nIndicator = SQL_NULL_DATA;
}
inline CSqlVariant::operator short() const
{ return m_pData->iVal; }
inline CSqlVariant::operator int() const
{ return m_pData->nVal; }
inline CSqlVariant::operator double() const
{ return m_pData->dbVal; }
inline CSqlVariant::operator const char*() const
{ return (const char*) GetBuffer(); }
inline SQLCHAR* CSqlVariant::GetBuffer() const
{ return m_pData->pVal; }
inline const DATE_STRUCT* CSqlVariant::GetDate() const
{ return &(m_pData->dtVal); }
inline const TIME_STRUCT* CSqlVariant::GetTime() const
{ return &(m_pData->tmVal); }
inline const TIMESTAMP_STRUCT* CSqlVariant::GetTimeStamp() const
{ return (const TIMESTAMP_STRUCT*) GetBuffer(); }
//////////////////////////////////////////////////////////////////////
// class CSqlParameter - Represents a Represents a parameter or
// argument associated with a SQL statement or stored procedure
class CSqlParameter : public CSqlVariant
{
public:
CSqlParameter();
CSqlParameter(const CSqlParameter& rData);
virtual ~CSqlParameter();
private:
// Attributes for file binding:
BOOL m_bBindFile; // whether this is a file-binding parameter
SQLUINTEGER m_nFileOptions; // file option: SQL_FILE_READ
SQLSMALLINT m_nSqlType; // SQL data type
public:
SQLSMALLINT m_nIoType; // input/output type
public:
BOOL CreateParameter(SQLSMALLINT nSqlType, SQLSMALLINT nIoType,
SQLUINTEGER nPrecision=0, SQLSMALLINT nScale=0);
BOOL CreateFileParam(SQLSMALLINT nSqlType);
CSqlParameter& operator=(const CSqlParameter& rValue);
CSqlParameter& operator=(int nValue);
CSqlParameter& operator=(double nValue);
CSqlParameter& operator=(const char* pszValue);
virtual BOOL Bind(CSqlCommand* pStmt, int nOrdinal);
virtual BOOL Unbind(CSqlCommand* pStmt, int nOrdinal);
};
inline CSqlParameter& CSqlParameter::operator=(int nValue)
{
FromInteger(nValue);
return *this;
}
inline CSqlParameter& CSqlParameter::operator=(double nValue)
{
FromDouble(nValue);
return *this;
}
inline CSqlParameter& CSqlParameter::operator=(const char* pszValue)
{
FromString(pszValue);
return *this;
}
//////////////////////////////////////////////////////////////////////
// class CSqlField - Represents a column of data in a recordset
class CSqlFieldCache;
class CSqlRecordset;
class CSqlField : public CSqlVariant
{
friend class CSqlFieldCache;
friend class CSqlRecordset;
public:
CSqlField();
CSqlField(const CSqlField& rData);
virtual ~CSqlField();
private:
// Attributes for file binding:
BOOL m_bBindFile; // whether this is a file-binding field
SQLUINTEGER m_nFileOptions; // file access option
public:
std::string m_strName; // column name
BOOL m_bNullable; // whether the column can be null
SQLUSMALLINT m_nOrdinal; // the ordinal number of the column in the recordset
public:
BOOL CreateField(PCSTR pszFieldName, SQLSMALLINT nDataType, SQLINTEGER nDataSize=0);
BOOL CreateField(CSqlCommand* pStmt, int nOrdinal);
BOOL CreateFileField(PCSTR pszFieldName, SQLUINTEGER nFileOption=SQL_FILE_OVERWRITE);
CSqlField& operator=(const CSqlField& rValue);
CSqlField& operator=(int nValue);
CSqlField& operator=(double nValue);
CSqlField& operator=(const char* pszValue);
virtual BOOL Bind(CSqlCommand* pStmt, int nOrdinal);
virtual BOOL Unbind(CSqlCommand* pStmt, int nOrdinal);
};
inline CSqlField& CSqlField::operator=(int nValue)
{
FromInteger(nValue);
return *this;
}
inline CSqlField& CSqlField::operator=(double nValue)
{
FromDouble(nValue);
return *this;
}
inline CSqlField& CSqlField::operator=(const char* pszValue)
{
FromString(pszValue);
return *this;
}
#endif // !defined(AFX_SQLDATA_H__CA4CC4FF_1B45_434F_9368_59E1B8AC250D__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -