]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dbtable.h
Explicit casting/instantiation to resolve ambiguous overload.
[wxWidgets.git] / include / wx / dbtable.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: table.h
3 // Purpose: Declaration of the wxTable class.
4 // Author: Doug Card
5 // Modified by:
6 // Created: 9.96
7 // RCS-ID: $Id$
8 // Copyright: (c) 1996 Remstar International, Inc.
9 // Licence: wxWindows licence, plus:
10 // Notice: This class library and its intellectual design are free of charge for use,
11 // modification, enhancement, debugging under the following conditions:
12 // 1) These classes may only be used as part of the implementation of a
13 // wxWindows-based application
14 // 2) All enhancements and bug fixes are to be submitted back to the wxWindows
15 // user groups free of all charges for use with the wxWindows library.
16 // 3) These classes may not be distributed as part of any other class library,
17 // DLL, text (written or electronic), other than a complete distribution of
18 // the wxWindows GUI development toolkit.
19 ///////////////////////////////////////////////////////////////////////////////
20
21 /*
22 // SYNOPSIS START
23 // SYNOPSIS STOP
24 */
25
26 #ifndef TABLE_DOT_H
27 #define TABLE_DOT_H
28
29 #ifdef __GNUG__
30 #pragma interface "dbtable.h"
31 #endif
32
33 #include "wx/db.h"
34
35 const int ROWID_LEN = 24; // 18 is the max, 24 is in case it gets larger
36
37 // The following class is used to define a column of a table.
38 // The wxTable constructor will dynamically allocate as many of
39 // these as there are columns in the table. The class derived
40 // from wxTable must initialize these column definitions in it's
41 // constructor. These column definitions provide inf. to the
42 // wxTable class which allows it to create a table in the data
43 // source, exchange data between the data source and the C++
44 // object, and so on.
45
46 class WXDLLEXPORT CcolDef
47 {
48 public:
49 char ColName[DB_MAX_COLUMN_NAME_LEN+1]; // Column Name glt 4/19/97 added one for the null terminator
50 int DbDataType; // Logical Data Type; e.g. DB_DATA_TYPE_INTEGER
51 int SqlCtype; // C data type; e.g. SQL_C_LONG
52 void *PtrDataObj; // Address of the data object
53 int SzDataObj; // Size, in bytes, of the data object
54 bool KeyField; // TRUE if this column is part of the PRIMARY KEY to the table; Date fields should NOT be KeyFields.
55 bool Updateable; // Specifies whether this column is updateable
56 bool InsertAllowed; // Specifies whether this column should be included in an INSERT statement
57 bool DerivedCol; // Specifies whether this column is a derived value
58 SDWORD CbValue; // Internal use only!!!
59 }; // CcolDef
60
61 // This structure is used when creating secondary indexes.
62 class WXDLLEXPORT CidxDef
63 {
64 public:
65 char ColName[DB_MAX_COLUMN_NAME_LEN+1]; // Column Name glt 4/19/97 added one for the null terminator
66 bool Ascending;
67 }; // CidxDef
68
69 class WXDLLEXPORT wxTable
70 {
71 private:
72
73 // Private member variables
74 int currCursorNo;
75
76 // Private member functions
77 bool bindInsertParams(void);
78 bool bindUpdateParams(void);
79 bool bindCols(HSTMT cursor);
80 bool getRec(UWORD fetchType);
81 bool execDelete(char *pSqlStmt);
82 bool execUpdate(char *pSqlStmt);
83 bool query(int queryType, bool forUpdate, bool distinct, char *pSqlStmt = 0);
84
85 public:
86
87 // Pointer to the database object this table belongs to
88 wxDB *pDb;
89
90 // ODBC Handles
91 HENV henv; // ODBC Environment handle
92 HDBC hdbc; // ODBC DB Connection handle
93 HSTMT hstmt; // ODBC Statement handle
94 // HSTMT c0, c1, c2, c3, c4, c5; // Cursors 0 through 5
95 HSTMT c0, c1, c2; // Limited to Cursors 0 through 2 for now
96 HSTMT hstmtInsert; // ODBC Statement handle used specifically for inserts
97 HSTMT hstmtDelete; // ODBC Statement handle used specifically for deletes
98 HSTMT hstmtUpdate; // ODBC Statement handle used specifically for updates
99 HSTMT hstmtCount; // ODBC Statement handle used specifically for COUNT(*)
100
101 // Table Inf.
102 char tableName[DB_MAX_TABLE_NAME_LEN+1]; // Table name
103 char queryTableName[DB_MAX_TABLE_NAME_LEN+1]; // Query Table Name
104 int noCols; // # of columns in the table
105
106 // Column Definitions
107 CcolDef *colDefs; // Array of CcolDef structures
108
109 // Where, Order By and From clauses
110 char *where; // Standard SQL where clause, minus the word WHERE
111 char *orderBy; // Standard SQL order by clause, minus the ORDER BY
112 char *from; // Allows for joins in a Ctable::Query(). Format: ",tbl,tbl..."
113
114 // Flags
115 bool selectForUpdate;
116
117 // Public member functions
118 wxTable(wxDB *pwxDB, const char *tblName, const int nCols, const char *qryTblName = 0);
119 virtual ~wxTable();
120 bool Open(void);
121 bool CreateTable(void);
122 bool CreateIndex(char * idxName, bool unique, int noIdxCols, CidxDef *pIdxDefs);
123 bool CloseCursor(HSTMT cursor);
124 int Insert(void);
125 bool Update(void);
126 bool Update(char *pSqlStmt);
127 bool UpdateWhere(char *pWhereClause);
128 bool Delete(void);
129 bool DeleteWhere(char *pWhereClause);
130 bool DeleteMatching(void);
131 virtual bool Query(bool forUpdate = FALSE, bool distinct = FALSE);
132 bool QueryBySqlStmt(char *pSqlStmt);
133 bool QueryMatching(bool forUpdate = FALSE, bool distinct = FALSE);
134 bool QueryOnKeyFields(bool forUpdate = FALSE, bool distinct = FALSE);
135 bool GetNext(void) { return(getRec(SQL_FETCH_NEXT)); }
136 bool operator++(int) { return(getRec(SQL_FETCH_NEXT)); }
137 #ifndef FWD_ONLY_CURSORS
138 bool GetPrev(void) { return(getRec(SQL_FETCH_PRIOR)); }
139 bool operator--(int) { return(getRec(SQL_FETCH_PRIOR)); }
140 bool GetFirst(void) { return(getRec(SQL_FETCH_FIRST)); }
141 bool GetLast(void) { return(getRec(SQL_FETCH_LAST)); }
142 #endif
143 bool IsCursorClosedOnCommit(void);
144 bool IsColNull(int colNo);
145 UWORD GetRowNum(void);
146 void GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct);
147 void GetDeleteStmt(char *pSqlStmt, int typeOfDel, char *pWhereClause = 0);
148 void GetUpdateStmt(char *pSqlStmt, int typeOfUpd, char *pWhereClause = 0);
149 void GetWhereClause(char *pWhereClause, int typeOfWhere, char *qualTableName = 0);
150 bool CanSelectForUpdate(void);
151 bool CanUpdByROWID(void);
152 void ClearMemberVars(void);
153 bool SetQueryTimeout(UDWORD nSeconds);
154 void SetColDefs (int index, char *fieldName, int dataType, void *pData, int cType,
155 int size, bool keyField = FALSE, bool upd = TRUE,
156 bool insAllow = TRUE, bool derivedCol = FALSE);
157 bool SetCursor(int cursorNo = DB_CURSOR0);
158 int GetCursor(void) { return(currCursorNo); }
159 ULONG Count(void);
160 int DB_STATUS(void) { return(pDb->DB_STATUS); }
161 bool Refresh(void);
162
163 }; // wxTable
164
165 #endif