src/Common/ODBC/Buffer.h

Go to the documentation of this file.
00001 #pragma once
00002 
00003 namespace AppSecInc
00004 {
00005         namespace Databases
00006         {
00007                 namespace ODBC
00008                 {
00010                         class ODBCBuffer
00011                         {
00012             protected:
00014                                 SQLSMALLINT _type;
00016                                 SQLINTEGER _size;
00018                                 std::vector<char> _buffer;
00020                 static SQLINTEGER GetSize(SQLSMALLINT type);
00021                         public:
00023                                 static const SQLINTEGER INVALID_SIZE = 0;
00025                 virtual void operator=(const ODBCBuffer&);
00027                                 SQLINTEGER GetDataSize() const { return _size; }
00029                                 int GetBufferSize() const { return _buffer.size(); }
00031                                 SQLSMALLINT GetType() const { return _type; }
00033                 static std::wstring SQLTypeToString(SQLSMALLINT type);
00035                 static SQLSMALLINT StringToSQLType(const std::wstring& type);
00037                 ODBCBuffer();
00042                 ODBCBuffer(SQLSMALLINT type, SQLINTEGER size);
00043                                 ODBCBuffer(const std::wstring& value);
00044                                 ODBCBuffer(const std::string& value);
00045                                 ODBCBuffer(const SYSTEMTIME& value);
00046                                 ODBCBuffer(const GUID& value);
00047                                 ODBCBuffer(bool value);
00048                                 ODBCBuffer(int value);
00049                                 ODBCBuffer(char value);
00050                                 ODBCBuffer(wchar_t value);
00051                                 ODBCBuffer(short value);
00052                                 ODBCBuffer(double value);
00053                                 ODBCBuffer(float value);
00054                                 ODBCBuffer(const ODBCBuffer& Buffer);
00055                                 virtual ~ODBCBuffer();
00057                 std::string ToString() const;
00059                 std::wstring ToWString() const;
00061                                 std::string GetStringValue() const { return std::string(static_cast<const char *>(& * _buffer.begin())); }
00063                                 std::wstring GetWStringValue() const { return std::wstring(reinterpret_cast<const wchar_t *>(& * _buffer.begin())); }
00065                                 const std::vector<char>& GetValue() const { return _buffer; }
00067                                 int GetIntValue() const { return * (int *) & * _buffer.begin(); }
00069                                 int GetShortValue() const { return * (short *) & * _buffer.begin(); }
00071                                 bool GetBoolValue() const { return * (bool *) & * _buffer.begin(); }
00073                                 LONGLONG GetLongLongValue() const { return * (LONGLONG *) & * _buffer.begin(); }                
00075                                 GUID GetGUIDValue() const { return * (GUID *) & * _buffer.begin(); }
00077                                 double GetDoubleValue() const { return * (double *) & * _buffer.begin(); }
00079                                 float GetFloatValue() const { return * (float *) & * _buffer.begin(); }
00081                                 char GetCharValue() const { return * (char *) & * _buffer.begin(); }
00083                 wchar_t GetVarCharValue() const { return * (wchar_t *) & * _buffer.begin(); }
00085                                 DATE_STRUCT GetDate() const { return * (DATE_STRUCT *) & * _buffer.begin(); }
00087                                 TIME_STRUCT GetTime() const { return * (TIME_STRUCT *) & * _buffer.begin(); }
00089                                 TIMESTAMP_STRUCT GetTimeStamp() const { return * (TIMESTAMP_STRUCT *) & * _buffer.begin(); }
00090                         };
00091                 }
00092         }
00093 }


© Application Security Inc. - All Rights Reserved http://msiext.codeplex.com