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