]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dbtable.h
2nd attempt at MDI in wxMotif, using wxNotebook this time (still some probs).
[wxWidgets.git] / include / wx / dbtable.h
CommitLineData
108106cf
JS
1///////////////////////////////////////////////////////////////////////////////
2// Name: table.h
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
26#ifndef TABLE_DOT_H
27#define TABLE_DOT_H
28
29#ifdef __GNUG__
30#pragma interface "dbtable.h"
31#endif
32
33#include "wx/db.h"
34
35const ROWID_LEN = 24; // 18 is the max, 24 is in case it gets larger
36
37// The following class is used to define a column of a table.
38// The wxTable constructor will dynamically allocate as many of
39// these as there are columns in the table. The class derived
40// from wxTable must initialize these column definitions in it's
41// constructor. These column definitions provide inf. to the
42// wxTable class which allows it to create a table in the data
43// source, exchange data between the data source and the C++
44// object, and so on.
45
46class CcolDef
47{
48public:
49 char ColName[DB_MAX_COLUMN_NAME_LEN+1]; // Column Name glt 4/19/97 added one for the null terminator
50 int DbDataType; // Logical Data Type; e.g. DB_DATA_TYPE_INTEGER
51 int SqlCtype; // C data type; e.g. SQL_C_LONG
52 void *PtrDataObj; // Address of the data object
53 int SzDataObj; // Size, in bytes, of the data object
54 bool KeyField; // TRUE if this column is part of the PRIMARY KEY to the table; Date fields should NOT be KeyFields.
55 bool Updateable; // Specifies whether this column is updateable
56 bool InsertAllowed; // Specifies whether this column should be included in an INSERT statement
57 bool DerivedCol; // Specifies whether this column is a derived value
58 SDWORD CbValue; // Internal use only!!!
59}; // CcolDef
60
61// This structure is used when creating secondary indexes.
62class CidxDef
63{
64public:
65 char ColName[DB_MAX_COLUMN_NAME_LEN+1]; // Column Name glt 4/19/97 added one for the null terminator
66 bool Ascending;
67}; // CidxDef
68
69class wxTable
70{
71private:
72
73 // Private member variables
74 int currCursorNo;
75
76 // Private member functions
77 bool bindInsertParams(void);
78 bool bindUpdateParams(void);
79 bool bindCols(HSTMT cursor);
80 bool getRec(UWORD fetchType);
81 bool execDelete(char *pSqlStmt);
82 bool execUpdate(char *pSqlStmt);
83 bool query(int queryType, bool forUpdate, bool distinct, char *pSqlStmt = 0);
84
85public:
86
87 // Pointer to the database object this table belongs to
88 wxDB *pDb;
89
90 // ODBC Handles
91 HENV henv; // ODBC Environment handle
92 HDBC hdbc; // ODBC DB Connection handle
93 HSTMT hstmt; // ODBC Statement handle
94// HSTMT c0, c1, c2, c3, c4, c5; // Cursors 0 through 5
95 HSTMT c0, c1, c2; // Limited to Cursors 0 through 2 for now
96 HSTMT hstmtInsert; // ODBC Statement handle used specifically for inserts
97 HSTMT hstmtDelete; // ODBC Statement handle used specifically for deletes
98 HSTMT hstmtUpdate; // ODBC Statement handle used specifically for updates
99 HSTMT hstmtCount; // ODBC Statement handle used specifically for COUNT(*)
100
101 // Table Inf.
102 char tableName[DB_MAX_TABLE_NAME_LEN+1]; // Table name
103 char queryTableName[DB_MAX_TABLE_NAME_LEN+1]; // Query Table Name
104 int noCols; // # of columns in the table
105
106 // Column Definitions
107 CcolDef *colDefs; // Array of CcolDef structures
108
109 // Where and Order By clauses
110 char *where; // Standard SQL where clause, minus the word WHERE
111 char *orderBy; // Standard SQL order by clause, minus the ORDER BY
112
113 // Flags
114 bool selectForUpdate;
115
116 // Public member functions
117 wxTable(wxDB *pwxDB, const char *tblName, const int nCols, const char *qryTblName = 0);
118 ~wxTable();
119 bool Open(void);
120 bool CreateTable(void);
121 bool CreateIndex(char * idxName, bool unique, int noIdxCols, CidxDef *pIdxDefs);
122 bool CloseCursor(HSTMT cursor);
123 int Insert(void);
124 bool Update(void);
125 bool Update(char *pSqlStmt);
126 bool UpdateWhere(char *pWhereClause);
127 bool Delete(void);
128 bool DeleteWhere(char *pWhereClause);
129 bool DeleteMatching(void);
130 bool Query(bool forUpdate = FALSE, bool distinct = FALSE);
131 bool QueryBySqlStmt(char *pSqlStmt);
132 bool QueryMatching(bool forUpdate = FALSE, bool distinct = FALSE);
133 bool QueryOnKeyFields(bool forUpdate = FALSE, bool distinct = FALSE);
134 bool GetNext(void) { return(getRec(SQL_FETCH_NEXT)); }
135 bool operator++(int) { return(getRec(SQL_FETCH_NEXT)); }
136#ifndef FWD_ONLY_CURSORS
137 bool GetPrev(void) { return(getRec(SQL_FETCH_PRIOR)); }
138 bool operator--(int) { return(getRec(SQL_FETCH_PRIOR)); }
139 bool GetFirst(void) { return(getRec(SQL_FETCH_FIRST)); }
140 bool GetLast(void) { return(getRec(SQL_FETCH_LAST)); }
141#endif
142 bool IsCursorClosedOnCommit(void);
143 bool IsColNull(int colNo);
144 UWORD GetRowNum(void);
145 void GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct);
146 void GetDeleteStmt(char *pSqlStmt, int typeOfDel, char *pWhereClause = 0);
147 void GetUpdateStmt(char *pSqlStmt, int typeOfUpd, char *pWhereClause = 0);
148 void GetWhereClause(char *pWhereClause, int typeOfWhere);
149 bool CanSelectForUpdate(void);
150 bool CanUpdByROWID(void);
151 void ClearMemberVars(void);
152 bool SetQueryTimeout(UDWORD nSeconds);
153 void SetColDefs (int index, char *fieldName, int dataType, void *pData, int cType,
154 int size, bool keyField = FALSE, bool upd = TRUE,
155 bool insAllow = TRUE, bool derivedCol = FALSE);
156 bool SetCursor(int cursorNo = DB_CURSOR0);
157 int GetCursor(void) { return(currCursorNo); }
158 ULONG Count(void);
159 int DB_STATUS(void) { return(pDb->DB_STATUS); }
160 bool Refresh(void);
161
162}; // wxTable
163
164#endif
165