]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dbtable.h
*** empty log message ***
[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);
98 bool execDelete(char *pSqlStmt);
99 bool execUpdate(char *pSqlStmt);
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
GT
138 wxTable(wxDB *pwxDB, const char *tblName, const int nCols,
139 const char *qryTblName = 0, bool qryOnly = !QUERY_ONLY, char *tblPath=NULL);
7e616b10 140 virtual ~wxTable();
1fc5dd6f 141 bool Open(void);
a2115c88
GT
142 bool CreateTable(bool attemptDrop=TRUE);
143 bool DropTable(void);
144 bool CreateIndex(char * idxName, bool unique, int noIdxCols, CidxDef *pIdxDefs, bool attemptDrop=TRUE);
145 bool DropIndex(char * idxName);
1fc5dd6f
JS
146 bool CloseCursor(HSTMT cursor);
147 int Insert(void);
148 bool Update(void);
149 bool Update(char *pSqlStmt);
150 bool UpdateWhere(char *pWhereClause);
151 bool Delete(void);
152 bool DeleteWhere(char *pWhereClause);
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)); }
108106cf 160#ifndef FWD_ONLY_CURSORS
1fc5dd6f
JS
161 bool GetPrev(void) { return(getRec(SQL_FETCH_PRIOR)); }
162 bool operator--(int) { return(getRec(SQL_FETCH_PRIOR)); }
163 bool GetFirst(void) { return(getRec(SQL_FETCH_FIRST)); }
164 bool GetLast(void) { return(getRec(SQL_FETCH_LAST)); }
108106cf 165#endif
1fc5dd6f
JS
166 bool IsCursorClosedOnCommit(void);
167 bool IsColNull(int colNo);
168 UWORD GetRowNum(void);
169 void GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct);
170 void GetDeleteStmt(char *pSqlStmt, int typeOfDel, char *pWhereClause = 0);
171 void GetUpdateStmt(char *pSqlStmt, int typeOfUpd, char *pWhereClause = 0);
172 void GetWhereClause(char *pWhereClause, int typeOfWhere, char *qualTableName = 0);
173 bool CanSelectForUpdate(void);
174 bool CanUpdByROWID(void);
175 void ClearMemberVars(void);
176 bool SetQueryTimeout(UDWORD nSeconds);
177 void SetColDefs (int index, char *fieldName, int dataType, void *pData, int cType,
178 int size, bool keyField = FALSE, bool upd = TRUE,
179 bool insAllow = TRUE, bool derivedCol = FALSE);
a2115c88
GT
180 HSTMT *NewCursor(bool setCursor = FALSE, bool bindColumns = TRUE);
181 bool DeleteCursor(HSTMT *hstmtDel);
182 void SetCursor(HSTMT *hstmtActivate = (void **) DEFAULT_CURSOR);
183 HSTMT GetCursor(void) { return(hstmt); }
1fc5dd6f
JS
184 ULONG Count(void);
185 int DB_STATUS(void) { return(pDb->DB_STATUS); }
186 bool Refresh(void);
a2115c88
GT
187 bool SetNull(int colNo);
188 bool SetNull(char *colName);
189
190#if __WXDEBUG__ > 0
191 ULONG GetTableID() { return tableID; };
192#endif
108106cf
JS
193
194}; // wxTable
195
196#endif