]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dbtable.h
FloodFill correction, wxQuantize correction
[wxWidgets.git] / include / wx / dbtable.h
CommitLineData
108106cf 1///////////////////////////////////////////////////////////////////////////////
a2115c88 2// Name: dbtable.h
f6bcfd97 3// Purpose: Declaration of the wxDbTable class.
108106cf 4// Author: Doug Card
30a6d2d2 5// Modified by: George Tasker
108106cf
JS
6// Created: 9.96
7// RCS-ID: $Id$
8// Copyright: (c) 1996 Remstar International, Inc.
9// Licence: wxWindows licence, plus:
95ca6a20 10// Notice: This class library and its intellectual design are free of charge for use,
108106cf
JS
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
a2115c88
GT
26#ifndef DBTABLE_DOT_H
27#define DBTABLE_DOT_H
108106cf 28
a2115c88
GT
29// Use this line for wxWindows v1.x
30//#include "wx_ver.h"
31// Use this line for wxWindows v2.x
32#include "wx/version.h"
33
34#if wxMAJOR_VERSION == 2
95ca6a20
GT
35 #ifdef __GNUG__
36 #pragma interface "dbtable.h"
37 #endif
108106cf
JS
38#endif
39
a2115c88 40#if wxMAJOR_VERSION == 2
95ca6a20 41 #include "wx/db.h"
a2115c88 42#else
95ca6a20 43 #include "db.h"
a2115c88 44#endif
108106cf 45
f6bcfd97
BP
46const int wxDB_ROWID_LEN = 24; // 18 is the max, 24 is in case it gets larger
47const int wxDB_DEFAULT_CURSOR = 0;
48const bool wxDB_QUERY_ONLY = TRUE;
49const bool wxDB_DISABLE_VIEW = TRUE;
108106cf
JS
50
51// The following class is used to define a column of a table.
f6bcfd97 52// The wxDbTable constructor will dynamically allocate as many of
108106cf 53// these as there are columns in the table. The class derived
f6bcfd97 54// from wxDbTable must initialize these column definitions in it's
108106cf 55// constructor. These column definitions provide inf. to the
f6bcfd97 56// wxDbTable class which allows it to create a table in the data
108106cf
JS
57// source, exchange data between the data source and the C++
58// object, and so on.
f6bcfd97 59class WXDLLEXPORT wxDbColDef
108106cf
JS
60{
61public:
95ca6a20
GT
62 char ColName[DB_MAX_COLUMN_NAME_LEN+1]; // Column Name
63 int DbDataType; // Logical Data Type; e.g. DB_DATA_TYPE_INTEGER
64 int SqlCtype; // C data type; e.g. SQL_C_LONG
65 void *PtrDataObj; // Address of the data object
66 int SzDataObj; // Size, in bytes, of the data object
67 bool KeyField; // TRUE if this column is part of the PRIMARY KEY to the table; Date fields should NOT be KeyFields.
68 bool Updateable; // Specifies whether this column is updateable
69 bool InsertAllowed; // Specifies whether this column should be included in an INSERT statement
70 bool DerivedCol; // Specifies whether this column is a derived value
71 SDWORD CbValue; // Internal use only!!!
72 bool Null; // NOT FULLY IMPLEMENTED - Allows NULL values in Inserts and Updates
f6bcfd97 73}; // wxDbColDef
30a6d2d2 74
95ca6a20 75
f6bcfd97 76class WXDLLEXPORT wxDbColDataPtr
30a6d2d2
GT
77{
78public:
95ca6a20
GT
79 void *PtrDataObj;
80 int SzDataObj;
81 int SqlCtype;
f6bcfd97 82}; // wxDbColDataPtr
30a6d2d2
GT
83
84
108106cf 85// This structure is used when creating secondary indexes.
f6bcfd97 86class WXDLLEXPORT wxDbIdxDef
108106cf
JS
87{
88public:
95ca6a20
GT
89 char ColName[DB_MAX_COLUMN_NAME_LEN+1];
90 bool Ascending;
f6bcfd97 91}; // wxDbIdxDef
108106cf 92
95ca6a20 93
f6bcfd97 94class WXDLLEXPORT wxDbTable
108106cf
JS
95{
96private:
95ca6a20 97 ULONG tableID; // Used for debugging. This can help to match up mismatched constructors/destructors
108106cf 98
95ca6a20
GT
99 // Private member variables
100 UDWORD cursorType;
f6bcfd97 101 bool insertable;
a2115c88 102
95ca6a20
GT
103 // Private member functions
104 bool bindInsertParams(void);
105 bool bindUpdateParams(void);
106 bool bindCols(HSTMT cursor);
107 bool getRec(UWORD fetchType);
108 bool execDelete(const char *pSqlStmt);
109 bool execUpdate(const char *pSqlStmt);
f6bcfd97 110 bool query(int queryType, bool forUpdate, bool distinct, const char *pSqlStmt = 0);
108106cf 111
f6bcfd97
BP
112#if !wxODBC_BACKWARD_COMPATABILITY
113// these were public
114 // Where, Order By and From clauses
115 wxString where; // Standard SQL where clause, minus the word WHERE
116 wxString orderBy; // Standard SQL order by clause, minus the ORDER BY
117 wxString from; // Allows for joins in a wxDbTable::Query(). Format: ",tbl,tbl..."
95ca6a20
GT
118
119 // ODBC Handles
f6bcfd97
BP
120 HENV henv; // ODBC Environment handle
121 HDBC hdbc; // ODBC DB Connection handle
122 HSTMT hstmt; // ODBC Statement handle
123 HSTMT *hstmtDefault; // Default cursor
124 HSTMT hstmtInsert; // ODBC Statement handle used specifically for inserts
125 HSTMT hstmtDelete; // ODBC Statement handle used specifically for deletes
126 HSTMT hstmtUpdate; // ODBC Statement handle used specifically for updates
127 HSTMT hstmtInternal; // ODBC Statement handle used internally only
128 HSTMT *hstmtCount; // ODBC Statement handle used by Count() function (No binding of columns)
95ca6a20 129
f6bcfd97
BP
130 // Flags
131 bool selectForUpdate;
95ca6a20 132
f6bcfd97
BP
133 // Pointer to the database object this table belongs to
134 wxDb *pDb;
95ca6a20 135
f6bcfd97
BP
136 // Table Inf.
137 char tablePath[wxDB_PATH_MAX]; // needed for dBase tables
138 char tableName[DB_MAX_TABLE_NAME_LEN+1]; // Table name
139 char queryTableName[DB_MAX_TABLE_NAME_LEN+1]; // Query Table Name
140 int noCols; // # of columns in the table
141 bool queryOnly; // Query Only, no inserts, updates or deletes
95ca6a20 142
f6bcfd97
BP
143 // Column Definitions
144 wxDbColDef *colDefs; // Array of wxDbColDef structures
145#endif
146public:
147#if wxODBC_BACKWARD_COMPATABILITY
95ca6a20 148 // Where, Order By and From clauses
f6bcfd97
BP
149 char *where; // Standard SQL where clause, minus the word WHERE
150 char *orderBy; // Standard SQL order by clause, minus the ORDER BY
151 char *from; // Allows for joins in a wxDbTable::Query(). Format: ",tbl,tbl..."
152
153 // ODBC Handles
154 HENV henv; // ODBC Environment handle
155 HDBC hdbc; // ODBC DB Connection handle
156 HSTMT hstmt; // ODBC Statement handle
157 HSTMT *hstmtDefault; // Default cursor
158 HSTMT hstmtInsert; // ODBC Statement handle used specifically for inserts
159 HSTMT hstmtDelete; // ODBC Statement handle used specifically for deletes
160 HSTMT hstmtUpdate; // ODBC Statement handle used specifically for updates
161 HSTMT hstmtInternal; // ODBC Statement handle used internally only
162 HSTMT *hstmtCount; // ODBC Statement handle used by Count() function (No binding of columns)
95ca6a20
GT
163
164 // Flags
f6bcfd97 165 bool selectForUpdate;
95ca6a20 166
f6bcfd97
BP
167 // Pointer to the database object this table belongs to
168 wxDb *pDb;
169
170 // Table Inf.
171 char tablePath[wxDB_PATH_MAX]; // needed for dBase tables
172 char tableName[DB_MAX_TABLE_NAME_LEN+1]; // Table name
173 char queryTableName[DB_MAX_TABLE_NAME_LEN+1]; // Query Table Name
174 int noCols; // # of columns in the table
175 bool queryOnly; // Query Only, no inserts, updates or deletes
176
177 // Column Definitions
178 wxDbColDef *colDefs; // Array of wxDbColDef structures
179#endif
95ca6a20 180 // Public member functions
f6bcfd97
BP
181 wxDbTable(wxDb *pwxDb, const char *tblName, const int nCols,
182 const char *qryTblName = 0, bool qryOnly = !wxDB_QUERY_ONLY, const char *tblPath=NULL);
183 virtual ~wxDbTable();
184
185 bool Open(void);
186 bool CreateTable(bool attemptDrop=TRUE);
187 bool DropTable(void);
188 bool CreateIndex(const char * idxName, bool unique, int noIdxCols, wxDbIdxDef *pIdxDefs, bool attemptDrop=TRUE);
189 bool DropIndex(const char * idxName);
190
191// Accessors
192
193 // The member variables returned by these accessors are all
194 // set when the wxDbTable instance is createand cannot be
195 // changed, hence there is no corresponding SetXxxx function
196 wxDb *GetDb() { return pDb; }
197 const char *GetTableName() { return tableName; }
198 const char *GetQueryTableName() { return queryTableName; }
199 const char *GetTablePath() { return tablePath; }
200
201 int GetNumberOfColumns() { return noCols; } // number of "defined" columns for this wxDbTable instance
202
203
204 const char *GetFromClause() { return from; }
205 const char *GetOrderByClause() { return orderBy; }
206 const char *GetWhereClause() { return where; }
207
208 bool IsQueryOnly() { return queryOnly; }
209#if wxODBC_BACKWARD_COMPATABILITY
210 void SetFromClause(const char *From) { from = (char *)From; }
211 void SetOrderByClause(const char *OrderBy) { orderBy = (char *)OrderBy; }
212 void SetWhereClause(const char *Where) { where = (char *)Where; }
213#else
214 void SetFromClause(const wxString& From) { from = From; }
215 void SetOrderByClause(const wxString& OrderBy) { orderBy = OrderBy; }
216 void SetWhereClause(const wxString& Where) { where = Where; }
217#endif
218 int Insert(void);
219 bool Update(void);
220 bool Update(const char *pSqlStmt);
221 bool UpdateWhere(const char *pWhereClause);
222 bool Delete(void);
223 bool DeleteWhere(const char *pWhereClause);
224 bool DeleteMatching(void);
225 virtual bool Query(bool forUpdate = FALSE, bool distinct = FALSE);
226 bool QueryBySqlStmt(const char *pSqlStmt);
227 bool QueryMatching(bool forUpdate = FALSE, bool distinct = FALSE);
228 bool QueryOnKeyFields(bool forUpdate = FALSE, bool distinct = FALSE);
229 bool Refresh(void);
230 bool GetNext(void) { return(getRec(SQL_FETCH_NEXT)); }
231 bool operator++(int) { return(getRec(SQL_FETCH_NEXT)); }
232
233 /***** These four functions only work with wxDb instances that are defined *****
95ca6a20 234 ***** as not being FwdOnlyCursors *****/
f6bcfd97
BP
235 bool GetPrev(void);
236 bool operator--(int);
237 bool GetFirst(void);
238 bool GetLast(void);
239
240 bool IsCursorClosedOnCommit(void);
241 UWORD GetRowNum(void);
242
243 void BuildSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct);
244 void BuildDeleteStmt(char *pSqlStmt, int typeOfDel, const char *pWhereClause = 0);
245 void BuildUpdateStmt(char *pSqlStmt, int typeOfUpd, const char *pWhereClause = 0);
246 void BuildWhereClause(char *pWhereClause, int typeOfWhere, const char *qualTableName = 0, bool useLikeComparison=FALSE);
247#if wxODBC_BACKWARD_COMPATABILITY
248// The following member functions are deprecated. You should use the BuildXxxxxStmt functions (above)
249 void GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct)
250 { BuildSelectStmt(pSqlStmt,typeOfSelect,distinct); }
251 void GetDeleteStmt(char *pSqlStmt, int typeOfDel, const char *pWhereClause = 0)
252 { BuildDeleteStmt(pSqlStmt,typeOfDel,pWhereClause); }
253 void GetUpdateStmt(char *pSqlStmt, int typeOfUpd, const char *pWhereClause = 0)
254 { BuildUpdateStmt(pSqlStmt,typeOfUpd,pWhereClause); }
255 void GetWhereClause(char *pWhereClause, int typeOfWhere,
256 const char *qualTableName = 0, bool useLikeComparison=FALSE)
257 { BuildWhereClause(pWhereClause,typeOfWhere,qualTableName,useLikeComparison); }
258#endif
259 bool CanSelectForUpdate(void);
260 bool CanUpdByROWID(void);
261 void ClearMemberVars(void);
262 bool SetQueryTimeout(UDWORD nSeconds);
263
264 wxDbColDef *GetColDefs() { return colDefs; }
265 void SetColDefs(int index, const char *fieldName, int dataType, void *pData, int cType,
266 int size, bool keyField = FALSE, bool upd = TRUE,
267 bool insAllow = TRUE, bool derivedCol = FALSE);
268 wxDbColDataPtr *SetColDefs(wxDbColInf *colInfs, ULONG numCols);
269
270 bool CloseCursor(HSTMT cursor);
271 bool DeleteCursor(HSTMT *hstmtDel);
272 void SetCursor(HSTMT *hstmtActivate = (void **) wxDB_DEFAULT_CURSOR);
273 HSTMT GetCursor(void) { return(hstmt); }
274 HSTMT *GetNewCursor(bool setCursor = FALSE, bool bindColumns = TRUE);
275#if wxODBC_BACKWARD_COMPATABILITY
276// The following member function is deprecated. You should use the GetNewCursor
277 HSTMT *NewCursor(bool setCursor = FALSE, bool bindColumns = TRUE) { return GetNewCursor(setCursor,bindColumns); }
278#endif
279
280 ULONG Count(const char *args="*");
281 int DB_STATUS(void) { return(pDb->DB_STATUS); }
282
283 bool IsColNull(int colNo);
284 bool SetNull(int colNo);
285 bool SetNull(const char *colName);
a2115c88 286
154f22b3 287#ifdef __WXDEBUG__
f6bcfd97 288 ULONG GetTableID() { return tableID; }
a2115c88 289#endif
108106cf 290
f6bcfd97 291}; // wxDbTable
108106cf 292
4a8fc2c8
GT
293
294// Change this to 0 to remove use of all deprecated functions
f6bcfd97 295#if wxODBC_BACKWARD_COMPATABILITY
4a8fc2c8
GT
296//#################################################################################
297//############### DEPRECATED functions for backward compatability #################
298//#################################################################################
299
300// Backward compability. These will eventually go away
f6bcfd97
BP
301typedef wxDbTable wxTable;
302typedef wxDbIdxDef wxIdxDef;
303typedef wxDbIdxDef CidxDef;
304typedef wxDbColDef wxColDef;
305typedef wxDbColDef CcolDef;
306typedef wxDbColDataPtr wxColDataPtr;
307typedef wxDbColDataPtr CcolDataPtr;
308
309const int ROWID = wxDB_ROWID_LEN;
310const int DEFAULT_CURSOR = wxDB_DEFAULT_CURSOR;
311const bool QUERY_ONLY = wxDB_QUERY_ONLY;
312const bool DISABLE_VIEW = wxDB_DISABLE_VIEW;
4a8fc2c8
GT
313#endif
314
108106cf 315#endif