#include <cstdio>
#include <cassert>
#include <climits>
#include <cfloat>
#include <map>
#include <typeinfo>
#include "DBBindBasic.hpp"
//http://the-control-freak.com/DateTime/DateTime.htm
//---------------------------------------------------------------------------
namespace sfg {
//---------------------------------------------------------------------------
const long MlsInDay = (long)(1000*60*60*24);
const long SecInDay = (long)(60*60*24);
const long MinInDay = (long)(60*24);
const long HourInDay = (long)(24);
//Funções Auxiliares Date and Times
long int MDY2GD ( int nMonth, int nDay, int nYear )
{ /* Jan Feb Mar Apr May Jun Jly Aug Sep Oct Nov Dec */
static const int nDays [ 13 ] = { 0, 0, -31, 306, 275, 245, 214, 184, 153, 122, 92, 61, 31 };
static const int nBias [ 13 ] = { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
long nYears, nDate;
nYears = nYear - nBias [ nMonth ];
nDate = ( ( nYears / 100 ) * 146097l ) / 4
+ ( ( nYears % 100 ) * 1461 ) / 4
- nDays [ nMonth ]
+ nDay;
return nDate;
} /* long MDY2GD ( int nMonth, int nDay, int nYear ) */
double CAL2GD ( int nYear, int nMo, int nDy, int nHr, int nMn, int nSc, int nMs )
{
double nDate = (double)(MDY2GD(nMo, nDy, nYear))
+ ((double)nHr * (1.0 / HourInDay))
+ ((double)nMn * (1.0 / MinInDay))
+ ((double)nSc * (1.0 / SecInDay))
+ ((double)nMs * (1.0 / MlsInDay));
return nDate;
}
void GD2MDY ( long int lnDate, int * pnMonth, int * pnDay, int * pnYear )
{ /* Jan Feb Mar Apr May Jun Jly Aug Sep Oct Nov Dec */
static const int nBias [ 12 ] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -10, -10 };
long lnLD, lnYr, lnMo, lnDy;
lnLD = 4 * ( lnDate + 306 ) - 1;
lnYr = ( lnLD / 146097l ) * 100;
lnDy = ( lnLD % 146097l ) / 4;
lnLD = 4 * lnDy + 3;
lnYr = ( lnLD / 1461 ) + lnYr;
lnDy = ( lnLD % 1461 ) / 4 + 1;
lnLD = 5 * lnDy - 3;
lnMo = ( lnLD / 153 ) + 1;
lnDy = ( lnLD % 153 ) / 5 + 1;
* pnMonth = ( int ) ( lnMo + nBias [ lnMo - 1 ] );
* pnDay = ( int ) ( lnDy );
* pnYear = ( int ) ( lnYr + lnMo/11 );
} /* void GD2MDY ( long lnDate, int * pnMonth, int * pnDay, int * pnYear ) */
void GD2CAL ( double gdDateTime, int * lpnYear, int * lpnMo, int * lpnDy, int * lpnHr, int * lpnMn, int * lpnSc, int * lpnMs )
{
GD2MDY((long)gdDateTime, lpnMo, lpnDy, lpnYear);
long lnTime = ( long ) ( ( gdDateTime - ( double ) ( ( long ) gdDateTime ) ) * 86400000.0 );
if ( lpnHr ) * lpnHr = ( int ) ( ( lnTime / 3600000L ) % 24L ); /* Hours */
if ( lpnMn ) * lpnMn = ( int ) ( ( lnTime / 60000L ) % 60L ); /* Minutes */
if ( lpnSc ) * lpnSc = ( int ) ( ( lnTime / 1000L ) % 60L ); /* Seconds */
if ( lpnMs ) * lpnMs = ( int ) ( ( lnTime / 1L ) % 1000L ); /* Milliseconds */
}
//---------------------------------------------------------------------------
double DateTimeToDouble(const SQL_DATETIME_STRUCT *sqldt)
{
return CAL2GD(sqldt->year, sqldt->month, sqldt->day,
sqldt->hour, sqldt->minute, sqldt->second, sqldt->fraction);
}
//---------------------------------------------------------------------------
void DoubleToDateTime(double dDateTime, SQL_DATETIME_STRUCT *sqldt)
{
int y,m,d,h,n,s,f;
GD2CAL(dDateTime,&y,&m,&d,&h,&n,&s,&f);
SgZeroMemory(sqldt,sizeof(SQL_DATETIME_STRUCT));
sqldt->year = y;
sqldt->month = m;
sqldt->day = d;
sqldt->hour = h;
sqldt->minute = n;
sqldt->second = s;
sqldt->fraction = f;
}
//---------------------------------------------------------------------------
DBException::DBException(const String& _sMethod, const String& _sErrMsg,
const String& _sSQLState, const String& _sSQLMsg, SQLINTEGER _nSqlErr)
: std::exception(), sExType(_T("DBException")), sMethod(_sMethod), sErrMsg(_sErrMsg),
sSQLState(_sSQLState), sSQLMsg(_sSQLMsg), nSQLErr(_nSqlErr) {}
//---------------------------------------------------------------------------
const TCHAR *DBException::twhat() const throw()
{
SgOStringStream oErrMsg;
oErrMsg << _T("Exception type: ") << sExType << std::endl;
oErrMsg << _T("Method: ") << sMethod << std::endl;
oErrMsg << _T("Error Message: ") << sErrMsg << std::endl;
oErrMsg << _T("SQL State: ") << sSQLState << std::endl;
oErrMsg << _T("Native Error: ") << nSQLErr << std::endl;
oErrMsg << _T("Native Message: ") << sSQLMsg << std::endl;
oErrMsg << std::ends;
// this gymnastics is needed so result isn't destroyed
// paste these two lines into all what() code
whatbuf = oErrMsg.str();
return whatbuf.c_str();
}
//---------------------------------------------------------------------------
const char *DBException::what() const throw()
{
#if defined(UNICODE)
String sBuffer = twhat();
size_t nLength = sBuffer.length();
whatcbuf.reserve(nLength);
nLength = wcstombs(const_cast<char*>(whatcbuf.c_str()), sBuffer.c_str(), nLength);
if (nLength > 0)
return whatcbuf.c_str();
else
return (char*)NULL;
#else
return twhat();
#endif
}
//---------------------------------------------------------------------------
TypeTranslation::TypeTranslation(DataType eDataType, SQLSMALLINT nSQLType,
SQLSMALLINT nNativeType, DataKind eDataKind, SQLULEN nNativeSize)
{
this->eDataType = eDataType;
this->nSQLType = nSQLType;
this->nNativeType = nNativeType;
this->eDataKind = eDataKind;
this->nNativeSize = nNativeSize;
}
//---------------------------------------------------------------------------
DataType GetTypeBySQL(SQLSMALLINT nSQLType, bool bUnsigned)
{
switch(nSQLType) {
case SQL_CHAR : return TYPE_CHAR ;
case SQL_VARCHAR : return TYPE_VARCHAR ;
case SQL_LONGVARCHAR : return TYPE_LONGVARCHAR ;
case SQL_DECIMAL : return TYPE_DECIMAL ;
case SQL_NUMERIC : return TYPE_NUMERIC ;
case SQL_WCHAR : return TYPE_WCHAR ;
case SQL_WVARCHAR : return TYPE_WVARCHAR ;
case SQL_WLONGVARCHAR : return TYPE_WLONGVARCHAR ;
case SQL_BIT : return TYPE_BIT ;
case SQL_TINYINT : return (bUnsigned) ? TYPE_UTINYINT : TYPE_STINYINT ;
case SQL_SMALLINT : return (bUnsigned) ? TYPE_USMALLINT : TYPE_SSMALLINT;
case SQL_INTEGER : return (bUnsigned) ? TYPE_UINTEGER : TYPE_SINTEGER ;
case SQL_BIGINT : return (bUnsigned) ? TYPE_UBIGINT : TYPE_SBIGINT ;
case SQL_REAL : return TYPE_REAL ;
case SQL_DOUBLE : return TYPE_DOUBLE ;
case SQL_FLOAT : return TYPE_FLOAT ;
case SQL_BINARY : return TYPE_BINARY ;
case SQL_VARBINARY : return TYPE_VARBINARY ;
case SQL_LONGVARBINARY : return TYPE_LONGVARBINARY;
case SQL_TYPE_DATE : return TYPE_DATE ;
case SQL_TYPE_TIME : return TYPE_TIME ;
case SQL_TYPE_TIMESTAMP: return TYPE_TIMESTAMP ;
}
return TYPE_UNKNOWN;
}
//---------------------------------------------------------------------------
//Converting Data from C to SQL Data Types
//http://msdn.microsoft.com/en-us/library/windows/desktop/ms716298(v=vs.85).aspx
//C Data Types
//http://msdn.microsoft.com/en-us/library/windows/desktop/ms714556(v=vs.85).aspx
//Mapeando os tipos de SQL para C
class TypeMap : public std::map<int, TypeTranslation*>
{
private:
void Build();
public:
TypeMap();
~TypeMap();
TypeTranslation* getData
四散
- 粉丝: 68
- 资源: 1万+
最新资源
- 基于MATLAB的简单网络编码模拟器。.rar
- 基于MATLAB的简单网络编码模拟器.rar
- 基于Matlab模拟了MPSK(理论和模拟)使用格雷编码.rar
- 基于Matlab模拟了一个带通QPSK的平坦瑞利衰落信道,并且还模拟了AWGN的误码率.rar
- 基于Matlab模拟或演示M-QAM调制解调器,以测试误码率、信道模型、时域和频域信号.rar
- 基于Matlab使用QPSK对高优先级和低优先级进行分层调制16 QAM。解调后也会计算误码率.rar
- 基于Matlab生成MPSK误码率与信噪比.rar
- 基于Matlab生成双边带抑制载波信号.rar
- 基于PN序列的信道估计和OFDM中Reed-Solomon码的实现.rar
- 基于多用户柯特兹值的盲源分离Matlab代码.rar
- 基于多重输入理论的多重相干函数matlabdiamond.rar
- 基于特征值最大最小值组合(CMME)的认知无线电频谱感知Matlab代码.rar
- 基于维特比算法的前向维特比算法Matlab代码.rar
- 基于模型的信道估计在MIMO中Matlab代码.rar
- 基于线性最小均方误差(LMMSE)的OFDM系统信道估计使用导频Matlab代码.rar
- 基于栈的顺序优先级解码器,用于具有边界控制的球形LAST码Matlab代码.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈