Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cSQLStatement.h
Go to the documentation of this file.
1 //
6 //
7 
8 #ifndef _INC_cSQLStatement_H
9 #define _INC_cSQLStatement_H
10 #ifndef NO_PRAGMA_ONCE
11 #pragma once
12 #endif
13 
14 #include "cSQLBase.h"
15 #include "../Variant/cVariant.h"
16 #include "../Scriptable/IScriptableObj.h"
19 #ifdef USE_ISCRIPTABLE
20 #include "../ScriptContext/cScriptSourceCurrent.h"
21 #endif
22 
23 namespace GrayLib
24 {
27  class GRAYLIB_LINK cSQLCmd;
29 
31  : public cSQLBase
32  , public IScriptableEnumerator
33  {
38 
39  friend class cSQLDatabase;
40 
41  public:
43 
44  protected:
47 
48  private:
49  static const TIMESYSD_t k_FetchWait = 500;
50 
51  protected:
52  ISQLStatement* get_ISQLStatement() const;
53 
54  ITERATE_t ReadColumnCount();
55  bool ReadColumnInfo(SQL_COLUMN_t iColumn, OUT cSQLColumnInfo& info);
56  bool AllocISQLStatement(const cSQLCmd& oCmd);
57 
58  public:
59  cSQLStatement();
60  virtual ~cSQLStatement();
61 
62  bool isConnected() const;
63 
64  virtual cSQLDriver* get_SQLDriver() const;
65  virtual cSQLBase* get_SQLParent() const;
66 
67  virtual HRESULT ExecuteAndFetch(cSQLDatabase* pDatabase, cSQLCmd& oCmd, cExceptionHolder* pExceptionRet = nullptr);
68  virtual HRESULT FetchNext(bool bWaitIfBusy = false);
69 
70  void ExecCancel();
71  bool CloseStatement(bool bDrop = true, bool bThrowOnError = false);
72  bool Close();
73 
74  SQL_COLUMN_t GetColumnCount();
75  cSQLColumnInfo* GetColumnInfo(SQL_COLUMN_t iColumn = k_SQL_COL_FIRST);
76  SQL_COLUMN_t FindColumn(const char* pszFieldName);
77  SQL_COLUMN_t VerifyColumn(SQL_COLUMN_t iColumn, const char* pszFieldName);
78 
80  bool GetColumnString(SQL_COLUMN_t iColumn, OUT cStringA& sResult);
81  cStringA GetColumnStr(SQL_COLUMN_t iColumn = k_SQL_COL_FIRST);
82  int GetColumnInt(SQL_COLUMN_t iColumn = k_SQL_COL_FIRST);
83  virtual bool GetColumnVar(SQL_COLUMN_t iColumn, OUT cVariant& vValRet);
84 
85  STDMETHOD(s_GetEnum)(ITERATE_t i, OUT cStringA& rsPropName, OUT cVariant& vValRet) override;
86 
88  cStringA GetColumnStr(const char* pszFieldName)
89  {
92  return GetColumnStr(FindColumn(pszFieldName));
93  }
94  int GetColumnInt(const char* pszFieldName)
95  {
97  return GetColumnInt(FindColumn(pszFieldName));
98  }
99  bool GetColumnVar(const char* pszFieldName, OUT cVariant& vVal)
100  {
102  return GetColumnVar(FindColumn(pszFieldName), vVal);
103  }
104  };
105 
107  : public cSQLStatement
108  , public IScriptableGetter
109  {
114  typedef cSQLStatement SUPER_t;
115 
116  public:
118 
119  protected:
120  int ReadRecordset();
121  public:
122  cSQLStatementQ();
123  virtual ~cSQLStatementQ();
124 
125  SQL_TYPE_t SetColumnType(SQL_COLUMN_t iColumn, SQL_TYPE_t eType);
126  SQL_TYPE_t RemoveColumn(SQL_COLUMN_t iColumn);
127 
128  virtual HRESULT ExecuteAndFetch(cSQLDatabase* pDatabase, cSQLCmd& oCmd, cExceptionHolder* pExceptionRet = nullptr) override;
129  virtual HRESULT FetchNext(bool bWaitIfBusy = false) override;
130  virtual bool GetColumnVar(SQL_COLUMN_t iColumn, OUT cVariant& vVal) override;
131 
132  bool GetColumnVar(const char* pszFieldName, OUT cVariant& vVal)
133  {
135  return GetColumnVar(FindColumn(pszFieldName), vVal);
136  }
137 
138  STDMETHOD(s_GetEnum)(ITERATE_t i, OUT cStringA& rsPropName, OUT cVariant& rvValRet) override;
139  STDMETHOD(s_GetByName)(const ATOMCHAR_t* pszPropName, OUT cVariant& vValRet) override;
140  };
141 
142 #ifdef USE_ISCRIPTABLE
144  {
148  public:
151  virtual cStringA get_SourceDesc() const;
152  };
153 #endif
154 };
155 #endif // !_INC_cSQLStatement_H
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
Definition: cSQLBase.h:78
Definition: cSQLCmd.h:36
Definition: cSQLDatabase.h:30
Definition: cSQLMgr.h:25
Definition: cSQLStatement.h:109
bool GetColumnVar(const char *pszFieldName, OUT cVariant &vVal)
Definition: cSQLStatement.h:132
cArrayStruct< cVariant > m_aColumnData
store data values for fields/columns. SQL_COLUMN_t = 1 based array
Definition: cSQLStatement.h:117
Definition: cSQLStatement.h:33
cStringA GetColumnStr(const char *pszFieldName)
These are slightly dangerous to use. you MUST know the order of the select in advance!...
Definition: cSQLStatement.h:88
cArrayStruct< cSQLColumnInfo > m_aColumnInfo
store metadata/description of the fields selected. 1 based.
Definition: cSQLStatement.h:46
cStringA m_sFromTable
usually the table name. used for error text.
Definition: cSQLStatement.h:42
cSQLDatabasePtr m_pDatabase
parent/source Database.
Definition: cSQLStatement.h:45
int GetColumnInt(const char *pszFieldName)
Definition: cSQLStatement.h:94
bool GetColumnVar(const char *pszFieldName, OUT cVariant &vVal)
Definition: cSQLStatement.h:99
Definition: cScriptSourceCurrent.h:17
Definition: cSQLStatement.h:144
virtual cStringA get_SourceDesc() const
Definition: cVariant.h:26
Definition: cArray.h:932
Definition: cException.h:28
Definition: ISQLDriver.h:30
Definition: IScriptableObj.h:38
Definition: IScriptableObj.h:51
Definition: cMesh.h:22
cRefPtr< cSQLDatabase > cSQLDatabasePtr
Definition: cSQLDatabase.h:84
class __DECL_IMPORT cSQLStatementQ
Definition: cUIDManagerTable.h:26
INT16 SQL_TYPE_t
Internal/Native/driver type code. enum SWORD = SQL_TYPE_NULL = 0, short int.
Definition: cSQLConfig.h:19
class __DECL_IMPORT cSQLStatement
Definition: cSQLDatabase.h:24
int SQL_COLUMN_t
what field/column/parameter number. 1 based. SQLUSMALLINT
Definition: cSQLBase.h:23
DECLARE_INTERFACE(IScriptableSetter)
INT32 TIMESYSD_t
Time delta. signed milli-Seconds Span. cTimeSys::k_DMAX, cTimeSys::k_INF = MAILSLOT_WAIT_FOREVER.
Definition: cTimeSys.h:28
int ITERATE_t
like size_t but signed
Definition: Index.h:28
char ATOMCHAR_t
the char form (UNICODE or not) for an atom. (for symbolic names)
Definition: StrConst.h:15
Definition: cSQLConfig.h:29