Buffer.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace AppSecInc
4 {
5  namespace Databases
6  {
7  namespace ODBC
8  {
10  class ODBCBuffer
11  {
12  protected:
14  SQLSMALLINT _type;
16  SQLINTEGER _size;
18  std::vector<char> _buffer;
20  static SQLINTEGER GetSize(SQLSMALLINT type);
21  public:
23  static const SQLINTEGER INVALID_SIZE = 0;
25  virtual void operator=(const ODBCBuffer&);
27  SQLINTEGER GetDataSize() const { return _size; }
29  int GetBufferSize() const { return _buffer.size(); }
31  SQLSMALLINT GetType() const { return _type; }
33  static std::wstring SQLTypeToString(SQLSMALLINT type);
35  static SQLSMALLINT StringToSQLType(const std::wstring& type);
37  ODBCBuffer();
42  ODBCBuffer(SQLSMALLINT type, SQLINTEGER size);
43  ODBCBuffer(const std::wstring& value);
44  ODBCBuffer(const std::string& value);
45  ODBCBuffer(const SYSTEMTIME& value);
46  ODBCBuffer(const GUID& value);
47  ODBCBuffer(bool value);
48  ODBCBuffer(int value);
49  ODBCBuffer(char value);
50  ODBCBuffer(wchar_t value);
51  ODBCBuffer(short value);
52  ODBCBuffer(double value);
53  ODBCBuffer(float value);
54  ODBCBuffer(const ODBCBuffer& Buffer);
55  virtual ~ODBCBuffer();
57  std::string ToString() const;
59  std::wstring ToWString() const;
61  std::string GetStringValue() const { return std::string(static_cast<const char *>(& * _buffer.begin())); }
63  std::wstring GetWStringValue() const { return std::wstring(reinterpret_cast<const wchar_t *>(& * _buffer.begin())); }
65  const std::vector<char>& GetValue() const { return _buffer; }
67  int GetIntValue() const { return * (int *) & * _buffer.begin(); }
69  int GetShortValue() const { return * (short *) & * _buffer.begin(); }
71  bool GetBoolValue() const { return * (bool *) & * _buffer.begin(); }
73  LONGLONG GetLongLongValue() const { return * (LONGLONG *) & * _buffer.begin(); }
75  GUID GetGUIDValue() const { return * (GUID *) & * _buffer.begin(); }
77  double GetDoubleValue() const { return * (double *) & * _buffer.begin(); }
79  float GetFloatValue() const { return * (float *) & * _buffer.begin(); }
81  char GetCharValue() const { return * (char *) & * _buffer.begin(); }
83  wchar_t GetVarCharValue() const { return * (wchar_t *) & * _buffer.begin(); }
85  DATE_STRUCT GetDate() const { return * (DATE_STRUCT *) & * _buffer.begin(); }
87  TIME_STRUCT GetTime() const { return * (TIME_STRUCT *) & * _buffer.begin(); }
89  TIMESTAMP_STRUCT GetTimeStamp() const { return * (TIMESTAMP_STRUCT *) & * _buffer.begin(); }
90  };
91  }
92  }
93 }
int GetShortValue() const
get a value of type short (SQL_SMALLINT)
Definition: Buffer.h:69
wchar_t GetVarCharValue() const
get a single unicode character value
Definition: Buffer.h:83
bool GetBoolValue() const
get a value of type bool (SQL_BIT)
Definition: Buffer.h:71
char GetCharValue() const
get a single character value
Definition: Buffer.h:81
SQLSMALLINT _type
column type, eg. SQL_C_CHAR
Definition: Buffer.h:14
std::string ToString() const
convert the value to a string regardless of its internal type
Definition: Buffer.cpp:159
LONGLONG GetLongLongValue() const
get a value of type longlong (SQL_BIGINT, etc.)
Definition: Buffer.h:73
std::vector< char > _buffer
the data buffer
Definition: Buffer.h:18
static const SQLINTEGER INVALID_SIZE
invalid data size
Definition: Buffer.h:23
virtual ~ODBCBuffer()
Definition: Buffer.cpp:153
TIMESTAMP_STRUCT GetTimeStamp() const
get a timestamp structure
Definition: Buffer.h:89
float GetFloatValue() const
get the value of type float
Definition: Buffer.h:79
GUID GetGUIDValue() const
get a value of type uniqueidentifier
Definition: Buffer.h:75
DATE_STRUCT GetDate() const
get a date structure
Definition: Buffer.h:85
int GetIntValue() const
get a value of type integer (SQL_INTEGER, SQL_DECIMAL, etc.)
Definition: Buffer.h:67
virtual void operator=(const ODBCBuffer &)
copy operator, data will be copied
Definition: Buffer.cpp:146
int GetBufferSize() const
get the size of the buffer
Definition: Buffer.h:29
TIME_STRUCT GetTime() const
get a time structure
Definition: Buffer.h:87
std::string GetStringValue() const
get the data as a null-terminated string, disregarding fetched data size
Definition: Buffer.h:61
double GetDoubleValue() const
get a value of type double
Definition: Buffer.h:77
const std::vector< char > & GetValue() const
get the raw data buffer
Definition: Buffer.h:65
SQLINTEGER GetDataSize() const
get the size of the data
Definition: Buffer.h:27
static SQLINTEGER GetSize(SQLSMALLINT type)
returns the size for default types, zero otherwise
Definition: Buffer.cpp:291
SQLINTEGER _size
the data size after a Fetch
Definition: Buffer.h:16
std::wstring GetWStringValue() const
get the data as a null-terminated unicode string, disregarding fetched data size
Definition: Buffer.h:63
ODBCBuffer()
constructors
Definition: Buffer.cpp:6
std::wstring ToWString() const
convert the value to a unicode string regardless of its internal type
Definition: Buffer.cpp:225
An ODBC column.
Definition: Buffer.h:10
static SQLSMALLINT StringToSQLType(const std::wstring &type)
translate a string to its SQL type
Definition: Buffer.cpp:365
SQLSMALLINT GetType() const
get the type of data
Definition: Buffer.h:31
static std::wstring SQLTypeToString(SQLSMALLINT type)
translate a SQL type to its string representation
Definition: Buffer.cpp:378


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