I don't think the last person to edit splitter.cpp did
[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
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
95ca6a20
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.
30a6d2d2 59class WXDLLEXPORT wxColDef
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
30a6d2d2
GT
73}; // wxColDef
74
95ca6a20 75
30a6d2d2
GT
76class WXDLLEXPORT wxColDataPtr
77{
78public:
95ca6a20
GT
79 void *PtrDataObj;
80 int SzDataObj;
81 int SqlCtype;
30a6d2d2
GT
82}; // wxColDataPtr
83
84
108106cf 85// This structure is used when creating secondary indexes.
4a8fc2c8 86class WXDLLEXPORT wxIdxDef
108106cf
JS
87{
88public:
95ca6a20
GT
89 char ColName[DB_MAX_COLUMN_NAME_LEN+1];
90 bool Ascending;
4a8fc2c8 91}; // wxIdxDef
108106cf 92
95ca6a20 93
9f8de18f 94class WXDLLEXPORT wxTable
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;
a2115c88 101
95ca6a20
GT
102 // Private member functions
103 bool bindInsertParams(void);
104 bool bindUpdateParams(void);
105 bool bindCols(HSTMT cursor);
106 bool getRec(UWORD fetchType);
107 bool execDelete(const char *pSqlStmt);
108 bool execUpdate(const char *pSqlStmt);
109 bool query(int queryType, bool forUpdate, bool distinct, char *pSqlStmt = 0);
108106cf
JS
110
111public:
95ca6a20
GT
112 // Pointer to the database object this table belongs to
113 wxDB *pDb;
114
115 // ODBC Handles
116 HENV henv; // ODBC Environment handle
117 HDBC hdbc; // ODBC DB Connection handle
118 HSTMT hstmt; // ODBC Statement handle
119 HSTMT *hstmtDefault; // Default cursor
120 HSTMT hstmtInsert; // ODBC Statement handle used specifically for inserts
121 HSTMT hstmtDelete; // ODBC Statement handle used specifically for deletes
122 HSTMT hstmtUpdate; // ODBC Statement handle used specifically for updates
123 HSTMT hstmtInternal; // ODBC Statement handle used internally only
124 HSTMT *hstmtCount; // ODBC Statement handle used by Count() function (No binding of columns)
125
126 // Table Inf.
127 char tableName[DB_MAX_TABLE_NAME_LEN+1]; // Table name
128 char queryTableName[DB_MAX_TABLE_NAME_LEN+1]; // Query Table Name
129 int noCols; // # of columns in the table
130 bool queryOnly; // Query Only, no inserts, updates or deletes
131
132 char tablePath[DB_PATH_MAX]; // needed for dBase tables
133
134 // Column Definitions
135 wxColDef *colDefs; // Array of wxColDef structures
136
137 // Where, Order By and From clauses
138 char *where; // Standard SQL where clause, minus the word WHERE
139 char *orderBy; // Standard SQL order by clause, minus the ORDER BY
140 char *from; // Allows for joins in a wxTable::Query(). Format: ",tbl,tbl..."
141
142 // Flags
143 bool selectForUpdate;
144
145 // Public member functions
146 wxTable(wxDB *pwxDB, const char *tblName, const int nCols,
147 const char *qryTblName = 0, bool qryOnly = !QUERY_ONLY, const char *tblPath=NULL);
148 virtual ~wxTable();
149 bool Open(void);
150 bool CreateTable(bool attemptDrop=TRUE);
151 bool DropTable(void);
4a8fc2c8 152 bool CreateIndex(const char * idxName, bool unique, int noIdxCols, wxIdxDef *pIdxDefs, bool attemptDrop=TRUE);
95ca6a20
GT
153 bool DropIndex(const char * idxName);
154 bool CloseCursor(HSTMT cursor);
155 int Insert(void);
156 bool Update(void);
157 bool Update(const char *pSqlStmt);
158 bool UpdateWhere(const char *pWhereClause);
159 bool Delete(void);
160 bool DeleteWhere(const char *pWhereClause);
161 bool DeleteMatching(void);
162 virtual bool Query(bool forUpdate = FALSE, bool distinct = FALSE);
163 bool QueryBySqlStmt(char *pSqlStmt);
164 bool QueryMatching(bool forUpdate = FALSE, bool distinct = FALSE);
165 bool QueryOnKeyFields(bool forUpdate = FALSE, bool distinct = FALSE);
166 bool GetNext(void) { return(getRec(SQL_FETCH_NEXT)); }
167 bool operator++(int) { return(getRec(SQL_FETCH_NEXT)); }
168
169 /***** These four functions only work with wxDB instances that are defined *****
170 ***** as not being FwdOnlyCursors *****/
171 bool GetPrev(void);
172 bool operator--(int);
173 bool GetFirst(void);
174 bool GetLast(void);
175
176 bool IsCursorClosedOnCommit(void);
177 bool IsColNull(int colNo);
178 UWORD GetRowNum(void);
179 void GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct);
180 void GetDeleteStmt(char *pSqlStmt, int typeOfDel, const char *pWhereClause = 0);
181 void GetUpdateStmt(char *pSqlStmt, int typeOfUpd, const char *pWhereClause = 0);
4a8fc2c8 182 void GetWhereClause(char *pWhereClause, int typeOfWhere, const char *qualTableName = 0, bool useLikeComparison=FALSE);
95ca6a20
GT
183 bool CanSelectForUpdate(void);
184 bool CanUpdByROWID(void);
185 void ClearMemberVars(void);
186 bool SetQueryTimeout(UDWORD nSeconds);
187 void SetColDefs (int index, const char *fieldName, int dataType, void *pData, int cType,
188 int size, bool keyField = FALSE, bool upd = TRUE,
189 bool insAllow = TRUE, bool derivedCol = FALSE);
190 wxColDataPtr* SetColDefs (wxColInf *colInfs, ULONG numCols);
191
192 HSTMT *NewCursor(bool setCursor = FALSE, bool bindColumns = TRUE);
193 bool DeleteCursor(HSTMT *hstmtDel);
194 void SetCursor(HSTMT *hstmtActivate = (void **) DEFAULT_CURSOR);
195 HSTMT GetCursor(void) { return(hstmt); }
196 ULONG Count(const char *args="*");
197 int DB_STATUS(void) { return(pDb->DB_STATUS); }
198 bool Refresh(void);
199 bool SetNull(int colNo);
200 bool SetNull(const char *colName);
a2115c88 201
154f22b3 202#ifdef __WXDEBUG__
95ca6a20 203 ULONG GetTableID() { return tableID; };
a2115c88 204#endif
108106cf
JS
205
206}; // wxTable
207
4a8fc2c8
GT
208
209// Change this to 0 to remove use of all deprecated functions
210#if 1
211//#################################################################################
212//############### DEPRECATED functions for backward compatability #################
213//#################################################################################
214
215// Backward compability. These will eventually go away
216typedef wxColDef CcolDef;
217typedef wxColDataPtr CcolDataPtr;
218typedef wxIdxDef CidxDef;
219
220#endif
221
108106cf 222#endif