]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dbtable.h
SN: Don't include (non-existing) pmstddlg.h for EMX
[wxWidgets.git] / include / wx / dbtable.h
CommitLineData
108106cf 1///////////////////////////////////////////////////////////////////////////////
a2115c88 2// Name: dbtable.h
108106cf
JS
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
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
35 #ifdef __GNUG__
36 #pragma interface "dbtable.h"
37 #endif
108106cf
JS
38#endif
39
a2115c88
GT
40#if wxMAJOR_VERSION == 2
41 #include "wx/db.h"
42#else
43 #include "db.h"
44#endif
108106cf 45
a2115c88
GT
46const int ROWID_LEN = 24; // 18 is the max, 24 is in case it gets larger
47const int DEFAULT_CURSOR = 0;
48const bool QUERY_ONLY = TRUE;
49const bool DISABLE_VIEW = TRUE;
108106cf
JS
50
51// The following class is used to define a column of a table.
52// The wxTable constructor will dynamically allocate as many of
53// these as there are columns in the table. The class derived
54// from wxTable must initialize these column definitions in it's
55// constructor. These column definitions provide inf. to the
56// wxTable class which allows it to create a table in the data
57// source, exchange data between the data source and the C++
58// object, and so on.
59
9f8de18f 60class WXDLLEXPORT CcolDef
108106cf
JS
61{
62public:
a2115c88 63 char ColName[DB_MAX_COLUMN_NAME_LEN+1]; // Column Name
1fc5dd6f
JS
64 int DbDataType; // Logical Data Type; e.g. DB_DATA_TYPE_INTEGER
65 int SqlCtype; // C data type; e.g. SQL_C_LONG
66 void *PtrDataObj; // Address of the data object
67 int SzDataObj; // Size, in bytes, of the data object
68 bool KeyField; // TRUE if this column is part of the PRIMARY KEY to the table; Date fields should NOT be KeyFields.
69 bool Updateable; // Specifies whether this column is updateable
70 bool InsertAllowed; // Specifies whether this column should be included in an INSERT statement
71 bool DerivedCol; // Specifies whether this column is a derived value
72 SDWORD CbValue; // Internal use only!!!
a2115c88 73 bool Null; // NOT FULLY IMPLEMENTED - Allows NULL values in Inserts and Updates
108106cf
JS
74}; // CcolDef
75
76// This structure is used when creating secondary indexes.
9f8de18f 77class WXDLLEXPORT CidxDef
108106cf
JS
78{
79public:
a2115c88 80 char ColName[DB_MAX_COLUMN_NAME_LEN+1];
1fc5dd6f 81 bool Ascending;
108106cf
JS
82}; // CidxDef
83
9f8de18f 84class WXDLLEXPORT wxTable
108106cf
JS
85{
86private:
87
a2115c88
GT
88 ULONG tableID; // Used for debugging. This can help to match up mismatched constructors/destructors
89
108106cf 90 // Private member variables
a2115c88 91 UDWORD cursorType;
108106cf
JS
92
93 // Private member functions
94 bool bindInsertParams(void);
95 bool bindUpdateParams(void);
96 bool bindCols(HSTMT cursor);
97 bool getRec(UWORD fetchType);
0b0ca94c
GT
98 bool execDelete(const char *pSqlStmt);
99 bool execUpdate(const char *pSqlStmt);
108106cf
JS
100 bool query(int queryType, bool forUpdate, bool distinct, char *pSqlStmt = 0);
101
102public:
103
104 // Pointer to the database object this table belongs to
105 wxDB *pDb;
106
107 // ODBC Handles
108 HENV henv; // ODBC Environment handle
109 HDBC hdbc; // ODBC DB Connection handle
110 HSTMT hstmt; // ODBC Statement handle
a2115c88 111 HSTMT *hstmtDefault; // Default cursor
108106cf
JS
112 HSTMT hstmtInsert; // ODBC Statement handle used specifically for inserts
113 HSTMT hstmtDelete; // ODBC Statement handle used specifically for deletes
114 HSTMT hstmtUpdate; // ODBC Statement handle used specifically for updates
a2115c88
GT
115 HSTMT hstmtInternal; // ODBC Statement handle used internally only
116 HSTMT *hstmtCount; // ODBC Statement handle used by Count() function (No binding of columns)
108106cf
JS
117
118 // Table Inf.
119 char tableName[DB_MAX_TABLE_NAME_LEN+1]; // Table name
120 char queryTableName[DB_MAX_TABLE_NAME_LEN+1]; // Query Table Name
121 int noCols; // # of columns in the table
a2115c88
GT
122 bool queryOnly; // Query Only, no inserts, updates or deletes
123
124 char tablePath[DB_PATH_MAX]; // needed for dBase tables
108106cf
JS
125
126 // Column Definitions
127 CcolDef *colDefs; // Array of CcolDef structures
128
1fc5dd6f 129 // Where, Order By and From clauses
108106cf
JS
130 char *where; // Standard SQL where clause, minus the word WHERE
131 char *orderBy; // Standard SQL order by clause, minus the ORDER BY
a2115c88 132 char *from; // Allows for joins in a wxTable::Query(). Format: ",tbl,tbl..."
108106cf
JS
133
134 // Flags
135 bool selectForUpdate;
136
137 // Public member functions
a2115c88 138 wxTable(wxDB *pwxDB, const char *tblName, const int nCols,
0b0ca94c 139 const char *qryTblName = 0, bool qryOnly = !QUERY_ONLY, const char *tblPath=NULL);
7e616b10 140 virtual ~wxTable();
1fc5dd6f 141 bool Open(void);
a2115c88
GT
142 bool CreateTable(bool attemptDrop=TRUE);
143 bool DropTable(void);
0b0ca94c
GT
144 bool CreateIndex(const char * idxName, bool unique, int noIdxCols, CidxDef *pIdxDefs, bool attemptDrop=TRUE);
145 bool DropIndex(const char * idxName);
1fc5dd6f
JS
146 bool CloseCursor(HSTMT cursor);
147 int Insert(void);
148 bool Update(void);
0b0ca94c
GT
149 bool Update(const char *pSqlStmt);
150 bool UpdateWhere(const char *pWhereClause);
1fc5dd6f 151 bool Delete(void);
0b0ca94c 152 bool DeleteWhere(const char *pWhereClause);
1fc5dd6f
JS
153 bool DeleteMatching(void);
154 virtual bool Query(bool forUpdate = FALSE, bool distinct = FALSE);
155 bool QueryBySqlStmt(char *pSqlStmt);
156 bool QueryMatching(bool forUpdate = FALSE, bool distinct = FALSE);
157 bool QueryOnKeyFields(bool forUpdate = FALSE, bool distinct = FALSE);
158 bool GetNext(void) { return(getRec(SQL_FETCH_NEXT)); }
159 bool operator++(int) { return(getRec(SQL_FETCH_NEXT)); }
a3439c7d
GT
160
161 /***** These four functions only work with wxDB instances that are defined *****
162 ***** as not being FwdOnlyCursors *****/
163 bool GetPrev(void);
164 bool operator--(int);
165 bool GetFirst(void);
166 bool GetLast(void);
167
1fc5dd6f
JS
168 bool IsCursorClosedOnCommit(void);
169 bool IsColNull(int colNo);
170 UWORD GetRowNum(void);
171 void GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct);
0b0ca94c
GT
172 void GetDeleteStmt(char *pSqlStmt, int typeOfDel, const char *pWhereClause = 0);
173 void GetUpdateStmt(char *pSqlStmt, int typeOfUpd, const char *pWhereClause = 0);
174 void GetWhereClause(char *pWhereClause, int typeOfWhere, const char *qualTableName = 0);
1fc5dd6f
JS
175 bool CanSelectForUpdate(void);
176 bool CanUpdByROWID(void);
177 void ClearMemberVars(void);
178 bool SetQueryTimeout(UDWORD nSeconds);
0b0ca94c 179 void SetColDefs (int index, const char *fieldName, int dataType, void *pData, int cType,
1fc5dd6f
JS
180 int size, bool keyField = FALSE, bool upd = TRUE,
181 bool insAllow = TRUE, bool derivedCol = FALSE);
a2115c88
GT
182 HSTMT *NewCursor(bool setCursor = FALSE, bool bindColumns = TRUE);
183 bool DeleteCursor(HSTMT *hstmtDel);
184 void SetCursor(HSTMT *hstmtActivate = (void **) DEFAULT_CURSOR);
185 HSTMT GetCursor(void) { return(hstmt); }
e9a145df 186 ULONG Count(const char *args="*");
1fc5dd6f
JS
187 int DB_STATUS(void) { return(pDb->DB_STATUS); }
188 bool Refresh(void);
a2115c88 189 bool SetNull(int colNo);
0b0ca94c 190 bool SetNull(const char *colName);
a2115c88 191
154f22b3 192#ifdef __WXDEBUG__
a2115c88
GT
193 ULONG GetTableID() { return tableID; };
194#endif
108106cf
JS
195
196}; // wxTable
197
198#endif