]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dbtable.h
Made geometry class link.
[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
3ca6a5f0
BP
6// Bart Jourquin
7// Mark Johnson
108106cf
JS
8// Created: 9.96
9// RCS-ID: $Id$
10// Copyright: (c) 1996 Remstar International, Inc.
11// Licence: wxWindows licence, plus:
95ca6a20 12// Notice: This class library and its intellectual design are free of charge for use,
108106cf
JS
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
a2115c88
GT
28#ifndef DBTABLE_DOT_H
29#define DBTABLE_DOT_H
108106cf 30
a2115c88
GT
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
95ca6a20 37 #ifdef __GNUG__
3ca6a5f0 38 #pragma interface "dbtable.h"
95ca6a20 39 #endif
108106cf
JS
40#endif
41
a2115c88 42#if wxMAJOR_VERSION == 2
95ca6a20 43 #include "wx/db.h"
a2115c88 44#else
95ca6a20 45 #include "db.h"
a2115c88 46#endif
108106cf 47
f6bcfd97
BP
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;
108106cf 52
2b63ff5d
GT
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
108106cf 57// The following class is used to define a column of a table.
f6bcfd97 58// The wxDbTable constructor will dynamically allocate as many of
108106cf 59// these as there are columns in the table. The class derived
f6bcfd97 60// from wxDbTable must initialize these column definitions in it's
108106cf 61// constructor. These column definitions provide inf. to the
f6bcfd97 62// wxDbTable class which allows it to create a table in the data
108106cf
JS
63// source, exchange data between the data source and the C++
64// object, and so on.
f6bcfd97 65class WXDLLEXPORT wxDbColDef
108106cf
JS
66{
67public:
95ca6a20
GT
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
f6bcfd97 79}; // wxDbColDef
30a6d2d2 80
95ca6a20 81
f6bcfd97 82class WXDLLEXPORT wxDbColDataPtr
30a6d2d2
GT
83{
84public:
95ca6a20
GT
85 void *PtrDataObj;
86 int SzDataObj;
87 int SqlCtype;
f6bcfd97 88}; // wxDbColDataPtr
30a6d2d2
GT
89
90
108106cf 91// This structure is used when creating secondary indexes.
f6bcfd97 92class WXDLLEXPORT wxDbIdxDef
108106cf
JS
93{
94public:
95ca6a20
GT
95 char ColName[DB_MAX_COLUMN_NAME_LEN+1];
96 bool Ascending;
f6bcfd97 97}; // wxDbIdxDef
108106cf 98
95ca6a20 99
f6bcfd97 100class WXDLLEXPORT wxDbTable
108106cf
JS
101{
102private:
3ca6a5f0 103 ULONG tableID; // Used for debugging. This can help to match up mismatched constructors/destructors
108106cf 104
95ca6a20 105 // Private member variables
3ca6a5f0
BP
106 UDWORD cursorType;
107 bool insertable;
a2115c88 108
95ca6a20 109 // Private member functions
3ca6a5f0
BP
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);
2b63ff5d 116 bool query(int queryType, bool forUpdate, bool distinct, const char *pSqlStmt = NULL);
108106cf 117
f6bcfd97
BP
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..."
95ca6a20
GT
124
125 // ODBC Handles
f6bcfd97
BP
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)
95ca6a20 135
f6bcfd97
BP
136 // Flags
137 bool selectForUpdate;
95ca6a20 138
f6bcfd97
BP
139 // Pointer to the database object this table belongs to
140 wxDb *pDb;
95ca6a20 141
f6bcfd97
BP
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
95ca6a20 148
f6bcfd97
BP
149 // Column Definitions
150 wxDbColDef *colDefs; // Array of wxDbColDef structures
151#endif
152public:
153#if wxODBC_BACKWARD_COMPATABILITY
95ca6a20 154 // Where, Order By and From clauses
f6bcfd97
BP
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)
95ca6a20
GT
169
170 // Flags
f6bcfd97 171 bool selectForUpdate;
95ca6a20 172
f6bcfd97
BP
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
95ca6a20 186 // Public member functions
f6bcfd97 187 wxDbTable(wxDb *pwxDb, const char *tblName, const int nCols,
2b63ff5d 188 const char *qryTblName = NULL, bool qryOnly = !wxDB_QUERY_ONLY, const char *tblPath="");
f6bcfd97
BP
189 virtual ~wxDbTable();
190
f02d4a64 191 bool Open(bool checkPrivileges=FALSE);
f6bcfd97
BP
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
3ca6a5f0 197 // Accessors
f6bcfd97
BP
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
3ca6a5f0
BP
202 wxDb *GetDb() { return pDb; }
203 const char *GetTableName() { return tableName; }
204 const char *GetQueryTableName() { return queryTableName; }
205 const char *GetTablePath() { return tablePath; }
f6bcfd97 206
3ca6a5f0 207 int GetNumberOfColumns() { return noCols; } // number of "defined" columns for this wxDbTable instance
f6bcfd97
BP
208
209
3ca6a5f0
BP
210 const char *GetFromClause() { return from; }
211 const char *GetOrderByClause() { return orderBy; }
212 const char *GetWhereClause() { return where; }
f6bcfd97 213
3ca6a5f0 214 bool IsQueryOnly() { return queryOnly; }
f6bcfd97
BP
215#if wxODBC_BACKWARD_COMPATABILITY
216 void SetFromClause(const char *From) { from = (char *)From; }
3ca6a5f0
BP
217 void SetOrderByClause(const char *OrderBy) { orderBy = (char *)OrderBy; }
218 void SetWhereClause(const char *Where) { where = (char *)Where; }
f6bcfd97 219#else
3ca6a5f0
BP
220 void SetFromClause(const wxString& From) { from = From; }
221 void SetOrderByClause(const wxString& OrderBy) { orderBy = OrderBy; }
2b63ff5d 222 bool SetOrderByColNums(int first, ...);
3ca6a5f0 223 void SetWhereClause(const wxString& Where) { where = Where; }
baeea290
GT
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(); }
f6bcfd97
BP
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 *****
95ca6a20 247 ***** as not being FwdOnlyCursors *****/
f6bcfd97
BP
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);
2b63ff5d
GT
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);
f6bcfd97
BP
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); }
2b63ff5d 264 void GetDeleteStmt(char *pSqlStmt, int typeOfDel, const char *pWhereClause = NULL)
f6bcfd97 265 { BuildDeleteStmt(pSqlStmt,typeOfDel,pWhereClause); }
2b63ff5d 266 void GetUpdateStmt(char *pSqlStmt, int typeOfUpd, const char *pWhereClause = NULL)
f6bcfd97
BP
267 { BuildUpdateStmt(pSqlStmt,typeOfUpd,pWhereClause); }
268 void GetWhereClause(char *pWhereClause, int typeOfWhere,
2b63ff5d 269 const char *qualTableName = NULL, bool useLikeComparison=FALSE)
f6bcfd97
BP
270 { BuildWhereClause(pWhereClause,typeOfWhere,qualTableName,useLikeComparison); }
271#endif
272 bool CanSelectForUpdate(void);
273 bool CanUpdByROWID(void);
f02d4a64
GT
274 void ClearMemberVar(int colNo, bool setToNull=FALSE);
275 void ClearMemberVars(bool setToNull=FALSE);
f6bcfd97
BP
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);
f02d4a64
GT
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
154f22b3 305#ifdef __WXDEBUG__
f6bcfd97 306 ULONG GetTableID() { return tableID; }
a2115c88 307#endif
108106cf 308
f6bcfd97 309}; // wxDbTable
108106cf 310
4a8fc2c8
GT
311
312// Change this to 0 to remove use of all deprecated functions
f6bcfd97 313#if wxODBC_BACKWARD_COMPATABILITY
4a8fc2c8
GT
314//#################################################################################
315//############### DEPRECATED functions for backward compatability #################
316//#################################################################################
317
318// Backward compability. These will eventually go away
f6bcfd97
BP
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;
4a8fc2c8
GT
331#endif
332
108106cf 333#endif