1998-07-28 09:43:44 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2002-12-04 14:11:26 +00:00
|
|
|
// Name: wx/db.h
|
2000-07-15 19:51:35 +00:00
|
|
|
// Purpose: Header file wxDb class. The wxDb class represents a connection
|
|
|
|
// to an ODBC data source. The wxDb class allows operations on the data
|
1998-07-28 09:43:44 +00:00
|
|
|
// source such as opening and closing the data source.
|
|
|
|
// Author: Doug Card
|
2000-01-20 14:15:44 +00:00
|
|
|
// Modified by: George Tasker
|
2000-08-08 06:11:51 +00:00
|
|
|
// Bart Jourquin
|
2000-08-12 11:15:24 +00:00
|
|
|
// Mark Johnson, wxWindows@mj10777.de
|
2000-02-08 11:06:53 +00:00
|
|
|
// Mods: Dec, 1998:
|
1999-10-07 14:19:57 +00:00
|
|
|
// -Added support for SQL statement logging and database cataloging
|
2000-01-31 15:41:28 +00:00
|
|
|
// April, 1999
|
|
|
|
// -Added QUERY_ONLY mode support to reduce default number of cursors
|
|
|
|
// -Added additional SQL logging code
|
1999-10-07 14:19:57 +00:00
|
|
|
// -Added DEBUG-ONLY tracking of Ctable objects to detect orphaned DB connections
|
2000-01-31 15:41:28 +00:00
|
|
|
// -Set ODBC option to only read committed writes to the DB so all
|
|
|
|
// databases operate the same in that respect
|
1999-10-07 14:19:57 +00:00
|
|
|
//
|
1998-07-28 09:43:44 +00:00
|
|
|
// Created: 9.96
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1996 Remstar International, Inc.
|
2004-08-21 11:49:18 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-07-28 09:43:44 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
#ifndef _WX_DB_H_
|
|
|
|
#define _WX_DB_H_
|
1999-10-07 14:19:57 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
|
2004-09-10 12:56:07 +00:00
|
|
|
// BJO 20000503: introduce new GetColumns members which are more database independant and
|
2000-07-15 19:51:35 +00:00
|
|
|
// return columns in the order they were created
|
|
|
|
#define OLD_GETCOLUMNS 1
|
2000-11-20 17:17:09 +00:00
|
|
|
#define EXPERIMENTAL_WXDB_FUNCTIONS 1
|
2000-07-15 19:51:35 +00:00
|
|
|
|
1999-10-07 14:19:57 +00:00
|
|
|
#include "wx/version.h"
|
|
|
|
|
2003-08-09 12:38:21 +00:00
|
|
|
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
|
2001-06-10 17:05:25 +00:00
|
|
|
#pragma interface "db.h"
|
1998-07-28 09:43:44 +00:00
|
|
|
#endif
|
|
|
|
|
2000-01-29 17:52:53 +00:00
|
|
|
#include "wx/setup.h"
|
|
|
|
|
2001-07-04 11:01:52 +00:00
|
|
|
#include "wx/defs.h"
|
|
|
|
#include "wx/string.h"
|
|
|
|
|
2004-09-10 12:56:07 +00:00
|
|
|
#if defined(__VISUALC__)
|
2002-12-04 14:11:26 +00:00
|
|
|
// we need to include standard Windows headers but we can't include
|
|
|
|
// <windows.h> directly when using MFC because it includes it itself in a
|
|
|
|
// different manner
|
|
|
|
#if wxUSE_MFC
|
|
|
|
#include <afxwin.h>
|
|
|
|
#else // !wxUSE_MFC
|
|
|
|
#ifndef STRICT
|
|
|
|
#define STRICT 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include "wx/msw/winundef.h"
|
|
|
|
#endif // wxUSE_MFC/!wxUSE_MFC
|
|
|
|
|
|
|
|
// If you use the wxDbCreateDataSource() function with MSW/VC6,
|
|
|
|
// you cannot use the iODBC headers, you must use the VC headers,
|
|
|
|
// plus the odbcinst.h header - gt Nov 2 2000
|
|
|
|
//
|
2004-05-23 14:56:36 +00:00
|
|
|
// Must add "odbccp32.lib" in \wx2\wxWidgets\src\makevc.env to the WINLIBS= line
|
2002-12-04 14:11:26 +00:00
|
|
|
//
|
2000-11-20 17:17:09 +00:00
|
|
|
#include "sql.h"
|
|
|
|
#include "sqlext.h"
|
|
|
|
#include "odbcinst.h"
|
2003-03-24 18:50:10 +00:00
|
|
|
#else
|
2004-01-11 20:52:43 +00:00
|
|
|
#if defined(__WINDOWS__) && ( defined(HAVE_W32API_H) || defined(__BORLANDC__) )
|
2003-08-02 16:27:21 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include "wx/msw/winundef.h"
|
|
|
|
#endif
|
2002-12-04 14:11:26 +00:00
|
|
|
extern "C" {
|
2003-08-23 12:45:34 +00:00
|
|
|
#if defined(wxUSE_BUILTIN_IODBC) && wxUSE_BUILTIN_IODBC
|
|
|
|
// Use the ones from the library
|
|
|
|
#include "wx/isql.h"
|
|
|
|
#include "wx/isqlext.h"
|
|
|
|
#else
|
2003-03-24 18:50:10 +00:00
|
|
|
#include <sql.h>
|
|
|
|
#include <sqlext.h>
|
2003-08-23 12:45:34 +00:00
|
|
|
#endif
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
2002-01-29 21:30:03 +00:00
|
|
|
#endif
|
|
|
|
|
2004-11-04 21:31:12 +00:00
|
|
|
#if wxUSE_UNICODE
|
|
|
|
#define SQL_C_WXCHAR SQL_C_WCHAR
|
|
|
|
#else
|
|
|
|
#define SQL_C_WXCHAR SQL_C_CHAR
|
|
|
|
#endif
|
2000-01-20 14:15:44 +00:00
|
|
|
|
2000-03-17 08:44:44 +00:00
|
|
|
typedef float SFLOAT;
|
|
|
|
typedef double SDOUBLE;
|
2000-01-31 15:41:28 +00:00
|
|
|
typedef unsigned int UINT;
|
|
|
|
#define ULONG UDWORD
|
2000-01-20 14:15:44 +00:00
|
|
|
|
2003-09-19 10:59:14 +00:00
|
|
|
// Not available in iODBC
|
|
|
|
#ifndef __WXMSW__
|
|
|
|
typedef UCHAR SQLTCHAR;
|
|
|
|
#endif
|
|
|
|
|
2000-01-20 14:15:44 +00:00
|
|
|
#ifndef wxODBC_FWD_ONLY_CURSORS
|
|
|
|
#define wxODBC_FWD_ONLY_CURSORS 1
|
|
|
|
#endif
|
|
|
|
|
2000-01-31 15:41:28 +00:00
|
|
|
enum enumDummy {enumDum1};
|
1998-12-30 23:30:49 +00:00
|
|
|
|
2001-02-13 11:42:35 +00:00
|
|
|
#ifndef SQL_C_BOOLEAN
|
2004-05-12 14:07:37 +00:00
|
|
|
#define SQL_C_BOOLEAN(datatype) (sizeof(datatype) == 1 ? SQL_C_UTINYINT : (sizeof(datatype) == 2 ? SQL_C_USHORT : SQL_C_ULONG))
|
2001-02-13 11:42:35 +00:00
|
|
|
#endif
|
2001-06-10 17:05:25 +00:00
|
|
|
|
2001-02-13 11:42:35 +00:00
|
|
|
#ifndef SQL_C_ENUM
|
2004-05-12 14:07:37 +00:00
|
|
|
#define SQL_C_ENUM (sizeof(enumDummy) == 2 ? SQL_C_USHORT : SQL_C_ULONG)
|
2001-02-13 11:42:35 +00:00
|
|
|
#endif
|
2001-06-10 17:05:25 +00:00
|
|
|
|
2004-05-12 14:07:37 +00:00
|
|
|
// NOTE: If SQL_C_BLOB is defined, and it is not SQL_C_BINARY, iODBC 2.x
|
|
|
|
// may not function correctly. Likely best to use SQL_C_BINARY direct
|
2001-02-13 11:42:35 +00:00
|
|
|
#ifndef SQL_C_BLOB
|
2004-05-12 14:07:37 +00:00
|
|
|
#ifdef SQL_C_BINARY
|
|
|
|
#define SQL_C_BLOB SQL_C_BINARY
|
2001-02-13 11:42:35 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
1998-12-30 23:30:49 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
const int wxDB_PATH_MAX = 254;
|
2000-01-31 15:41:28 +00:00
|
|
|
|
2003-08-02 19:14:54 +00:00
|
|
|
WXDLLIMPEXP_DATA_ODBC(extern wxChar const *) SQL_LOG_FILENAME;
|
|
|
|
WXDLLIMPEXP_DATA_ODBC(extern wxChar const *) SQL_CATALOG_FILENAME;
|
1998-07-28 09:43:44 +00:00
|
|
|
|
|
|
|
// Database Globals
|
2000-01-31 15:41:28 +00:00
|
|
|
const int DB_TYPE_NAME_LEN = 40;
|
2000-11-24 16:46:11 +00:00
|
|
|
const int DB_MAX_STATEMENT_LEN = 4096;
|
|
|
|
const int DB_MAX_WHERE_CLAUSE_LEN = 2048;
|
2000-01-31 15:41:28 +00:00
|
|
|
const int DB_MAX_ERROR_MSG_LEN = 512;
|
|
|
|
const int DB_MAX_ERROR_HISTORY = 5;
|
|
|
|
const int DB_MAX_TABLE_NAME_LEN = 128;
|
|
|
|
const int DB_MAX_COLUMN_NAME_LEN = 128;
|
|
|
|
|
|
|
|
const int DB_DATA_TYPE_VARCHAR = 1;
|
|
|
|
const int DB_DATA_TYPE_INTEGER = 2;
|
|
|
|
const int DB_DATA_TYPE_FLOAT = 3;
|
|
|
|
const int DB_DATA_TYPE_DATE = 4;
|
2001-02-13 11:42:35 +00:00
|
|
|
const int DB_DATA_TYPE_BLOB = 5;
|
2000-01-31 15:41:28 +00:00
|
|
|
|
|
|
|
const int DB_SELECT_KEYFIELDS = 1;
|
|
|
|
const int DB_SELECT_WHERE = 2;
|
|
|
|
const int DB_SELECT_MATCHING = 3;
|
|
|
|
const int DB_SELECT_STATEMENT = 4;
|
|
|
|
|
|
|
|
const int DB_UPD_KEYFIELDS = 1;
|
|
|
|
const int DB_UPD_WHERE = 2;
|
|
|
|
|
|
|
|
const int DB_DEL_KEYFIELDS = 1;
|
|
|
|
const int DB_DEL_WHERE = 2;
|
|
|
|
const int DB_DEL_MATCHING = 3;
|
|
|
|
|
|
|
|
const int DB_WHERE_KEYFIELDS = 1;
|
|
|
|
const int DB_WHERE_MATCHING = 2;
|
|
|
|
|
|
|
|
const int DB_GRANT_SELECT = 1;
|
|
|
|
const int DB_GRANT_INSERT = 2;
|
|
|
|
const int DB_GRANT_UPDATE = 4;
|
|
|
|
const int DB_GRANT_DELETE = 8;
|
|
|
|
const int DB_GRANT_ALL = DB_GRANT_SELECT | DB_GRANT_INSERT | DB_GRANT_UPDATE | DB_GRANT_DELETE;
|
1998-07-28 09:43:44 +00:00
|
|
|
|
|
|
|
// ODBC Error codes (derived from ODBC SqlState codes)
|
2000-03-16 19:00:24 +00:00
|
|
|
enum wxODBC_ERRORS
|
1998-07-28 09:43:44 +00:00
|
|
|
{
|
2000-01-31 15:41:28 +00:00
|
|
|
DB_FAILURE = 0,
|
|
|
|
DB_SUCCESS = 1,
|
|
|
|
DB_ERR_NOT_IN_USE,
|
|
|
|
DB_ERR_GENERAL_WARNING, // SqlState = '01000'
|
|
|
|
DB_ERR_DISCONNECT_ERROR, // SqlState = '01002'
|
|
|
|
DB_ERR_DATA_TRUNCATED, // SqlState = '01004'
|
|
|
|
DB_ERR_PRIV_NOT_REVOKED, // SqlState = '01006'
|
|
|
|
DB_ERR_INVALID_CONN_STR_ATTR, // SqlState = '01S00'
|
|
|
|
DB_ERR_ERROR_IN_ROW, // SqlState = '01S01'
|
|
|
|
DB_ERR_OPTION_VALUE_CHANGED, // SqlState = '01S02'
|
|
|
|
DB_ERR_NO_ROWS_UPD_OR_DEL, // SqlState = '01S03'
|
|
|
|
DB_ERR_MULTI_ROWS_UPD_OR_DEL, // SqlState = '01S04'
|
|
|
|
DB_ERR_WRONG_NO_OF_PARAMS, // SqlState = '07001'
|
|
|
|
DB_ERR_DATA_TYPE_ATTR_VIOL, // SqlState = '07006'
|
|
|
|
DB_ERR_UNABLE_TO_CONNECT, // SqlState = '08001'
|
|
|
|
DB_ERR_CONNECTION_IN_USE, // SqlState = '08002'
|
|
|
|
DB_ERR_CONNECTION_NOT_OPEN, // SqlState = '08003'
|
|
|
|
DB_ERR_REJECTED_CONNECTION, // SqlState = '08004'
|
|
|
|
DB_ERR_CONN_FAIL_IN_TRANS, // SqlState = '08007'
|
|
|
|
DB_ERR_COMM_LINK_FAILURE, // SqlState = '08S01'
|
|
|
|
DB_ERR_INSERT_VALUE_LIST_MISMATCH, // SqlState = '21S01'
|
|
|
|
DB_ERR_DERIVED_TABLE_MISMATCH, // SqlState = '21S02'
|
|
|
|
DB_ERR_STRING_RIGHT_TRUNC, // SqlState = '22001'
|
|
|
|
DB_ERR_NUMERIC_VALUE_OUT_OF_RNG, // SqlState = '22003'
|
|
|
|
DB_ERR_ERROR_IN_ASSIGNMENT, // SqlState = '22005'
|
|
|
|
DB_ERR_DATETIME_FLD_OVERFLOW, // SqlState = '22008'
|
|
|
|
DB_ERR_DIVIDE_BY_ZERO, // SqlState = '22012'
|
|
|
|
DB_ERR_STR_DATA_LENGTH_MISMATCH, // SqlState = '22026'
|
|
|
|
DB_ERR_INTEGRITY_CONSTRAINT_VIOL, // SqlState = '23000'
|
|
|
|
DB_ERR_INVALID_CURSOR_STATE, // SqlState = '24000'
|
|
|
|
DB_ERR_INVALID_TRANS_STATE, // SqlState = '25000'
|
|
|
|
DB_ERR_INVALID_AUTH_SPEC, // SqlState = '28000'
|
|
|
|
DB_ERR_INVALID_CURSOR_NAME, // SqlState = '34000'
|
|
|
|
DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL, // SqlState = '37000'
|
|
|
|
DB_ERR_DUPLICATE_CURSOR_NAME, // SqlState = '3C000'
|
|
|
|
DB_ERR_SERIALIZATION_FAILURE, // SqlState = '40001'
|
|
|
|
DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL2, // SqlState = '42000'
|
|
|
|
DB_ERR_OPERATION_ABORTED, // SqlState = '70100'
|
|
|
|
DB_ERR_UNSUPPORTED_FUNCTION, // SqlState = 'IM001'
|
|
|
|
DB_ERR_NO_DATA_SOURCE, // SqlState = 'IM002'
|
|
|
|
DB_ERR_DRIVER_LOAD_ERROR, // SqlState = 'IM003'
|
|
|
|
DB_ERR_SQLALLOCENV_FAILED, // SqlState = 'IM004'
|
|
|
|
DB_ERR_SQLALLOCCONNECT_FAILED, // SqlState = 'IM005'
|
|
|
|
DB_ERR_SQLSETCONNECTOPTION_FAILED, // SqlState = 'IM006'
|
|
|
|
DB_ERR_NO_DATA_SOURCE_DLG_PROHIB, // SqlState = 'IM007'
|
|
|
|
DB_ERR_DIALOG_FAILED, // SqlState = 'IM008'
|
|
|
|
DB_ERR_UNABLE_TO_LOAD_TRANSLATION_DLL, // SqlState = 'IM009'
|
|
|
|
DB_ERR_DATA_SOURCE_NAME_TOO_LONG, // SqlState = 'IM010'
|
|
|
|
DB_ERR_DRIVER_NAME_TOO_LONG, // SqlState = 'IM011'
|
|
|
|
DB_ERR_DRIVER_KEYWORD_SYNTAX_ERROR, // SqlState = 'IM012'
|
|
|
|
DB_ERR_TRACE_FILE_ERROR, // SqlState = 'IM013'
|
|
|
|
DB_ERR_TABLE_OR_VIEW_ALREADY_EXISTS, // SqlState = 'S0001'
|
|
|
|
DB_ERR_TABLE_NOT_FOUND, // SqlState = 'S0002'
|
|
|
|
DB_ERR_INDEX_ALREADY_EXISTS, // SqlState = 'S0011'
|
|
|
|
DB_ERR_INDEX_NOT_FOUND, // SqlState = 'S0012'
|
|
|
|
DB_ERR_COLUMN_ALREADY_EXISTS, // SqlState = 'S0021'
|
|
|
|
DB_ERR_COLUMN_NOT_FOUND, // SqlState = 'S0022'
|
|
|
|
DB_ERR_NO_DEFAULT_FOR_COLUMN, // SqlState = 'S0023'
|
|
|
|
DB_ERR_GENERAL_ERROR, // SqlState = 'S1000'
|
|
|
|
DB_ERR_MEMORY_ALLOCATION_FAILURE, // SqlState = 'S1001'
|
|
|
|
DB_ERR_INVALID_COLUMN_NUMBER, // SqlState = 'S1002'
|
|
|
|
DB_ERR_PROGRAM_TYPE_OUT_OF_RANGE, // SqlState = 'S1003'
|
|
|
|
DB_ERR_SQL_DATA_TYPE_OUT_OF_RANGE, // SqlState = 'S1004'
|
|
|
|
DB_ERR_OPERATION_CANCELLED, // SqlState = 'S1008'
|
|
|
|
DB_ERR_INVALID_ARGUMENT_VALUE, // SqlState = 'S1009'
|
|
|
|
DB_ERR_FUNCTION_SEQUENCE_ERROR, // SqlState = 'S1010'
|
|
|
|
DB_ERR_OPERATION_INVALID_AT_THIS_TIME, // SqlState = 'S1011'
|
|
|
|
DB_ERR_INVALID_TRANS_OPERATION_CODE, // SqlState = 'S1012'
|
|
|
|
DB_ERR_NO_CURSOR_NAME_AVAIL, // SqlState = 'S1015'
|
|
|
|
DB_ERR_INVALID_STR_OR_BUF_LEN, // SqlState = 'S1090'
|
|
|
|
DB_ERR_DESCRIPTOR_TYPE_OUT_OF_RANGE, // SqlState = 'S1091'
|
|
|
|
DB_ERR_OPTION_TYPE_OUT_OF_RANGE, // SqlState = 'S1092'
|
|
|
|
DB_ERR_INVALID_PARAM_NO, // SqlState = 'S1093'
|
|
|
|
DB_ERR_INVALID_SCALE_VALUE, // SqlState = 'S1094'
|
|
|
|
DB_ERR_FUNCTION_TYPE_OUT_OF_RANGE, // SqlState = 'S1095'
|
|
|
|
DB_ERR_INF_TYPE_OUT_OF_RANGE, // SqlState = 'S1096'
|
|
|
|
DB_ERR_COLUMN_TYPE_OUT_OF_RANGE, // SqlState = 'S1097'
|
|
|
|
DB_ERR_SCOPE_TYPE_OUT_OF_RANGE, // SqlState = 'S1098'
|
|
|
|
DB_ERR_NULLABLE_TYPE_OUT_OF_RANGE, // SqlState = 'S1099'
|
|
|
|
DB_ERR_UNIQUENESS_OPTION_TYPE_OUT_OF_RANGE, // SqlState = 'S1100'
|
|
|
|
DB_ERR_ACCURACY_OPTION_TYPE_OUT_OF_RANGE, // SqlState = 'S1101'
|
|
|
|
DB_ERR_DIRECTION_OPTION_OUT_OF_RANGE, // SqlState = 'S1103'
|
|
|
|
DB_ERR_INVALID_PRECISION_VALUE, // SqlState = 'S1104'
|
|
|
|
DB_ERR_INVALID_PARAM_TYPE, // SqlState = 'S1105'
|
|
|
|
DB_ERR_FETCH_TYPE_OUT_OF_RANGE, // SqlState = 'S1106'
|
|
|
|
DB_ERR_ROW_VALUE_OUT_OF_RANGE, // SqlState = 'S1107'
|
|
|
|
DB_ERR_CONCURRENCY_OPTION_OUT_OF_RANGE, // SqlState = 'S1108'
|
|
|
|
DB_ERR_INVALID_CURSOR_POSITION, // SqlState = 'S1109'
|
|
|
|
DB_ERR_INVALID_DRIVER_COMPLETION, // SqlState = 'S1110'
|
|
|
|
DB_ERR_INVALID_BOOKMARK_VALUE, // SqlState = 'S1111'
|
|
|
|
DB_ERR_DRIVER_NOT_CAPABLE, // SqlState = 'S1C00'
|
|
|
|
DB_ERR_TIMEOUT_EXPIRED // SqlState = 'S1T00'
|
1998-07-28 09:43:44 +00:00
|
|
|
};
|
|
|
|
|
2001-02-03 17:50:45 +00:00
|
|
|
#ifndef MAXNAME
|
2004-05-12 14:07:37 +00:00
|
|
|
#define MAXNAME 31
|
2001-02-03 17:50:45 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SQL_MAX_AUTHSTR_LEN
|
2004-05-12 14:07:37 +00:00
|
|
|
// There does not seem to be a standard for this, so I am
|
|
|
|
// defaulting to the value that MS uses
|
|
|
|
#define SQL_MAX_AUTHSTR_LEN MAXNAME
|
2001-02-03 17:50:45 +00:00
|
|
|
#endif
|
2000-01-31 15:41:28 +00:00
|
|
|
|
2004-05-12 19:41:03 +00:00
|
|
|
#ifndef SQL_MAX_CONNECTSTR_LEN
|
|
|
|
// There does not seem to be a standard for this, so I am
|
|
|
|
// defaulting to the value that MS recommends
|
|
|
|
#define SQL_MAX_CONNECTSTR_LEN 1024
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-08-02 19:14:54 +00:00
|
|
|
class WXDLLIMPEXP_ODBC wxDbConnectInf
|
1998-07-28 09:43:44 +00:00
|
|
|
{
|
2001-02-03 17:50:45 +00:00
|
|
|
private:
|
|
|
|
bool freeHenvOnDestroy;
|
2004-05-12 19:41:03 +00:00
|
|
|
bool useConnectionStr;
|
1999-10-07 14:19:57 +00:00
|
|
|
|
2001-02-03 17:50:45 +00:00
|
|
|
public:
|
2001-05-23 13:39:40 +00:00
|
|
|
HENV Henv;
|
|
|
|
wxChar Dsn[SQL_MAX_DSN_LENGTH+1]; // Data Source Name
|
|
|
|
wxChar Uid[SQL_MAX_USER_NAME_LEN+1]; // User ID
|
|
|
|
wxChar AuthStr[SQL_MAX_AUTHSTR_LEN+1]; // Authorization string (password)
|
2004-05-12 19:41:03 +00:00
|
|
|
wxChar ConnectionStr[SQL_MAX_CONNECTSTR_LEN+1]; // Connection string (password)
|
2001-02-03 17:50:45 +00:00
|
|
|
|
|
|
|
wxString Description; // Not sure what the max length is
|
|
|
|
wxString FileType; // Not sure what the max length is
|
|
|
|
|
|
|
|
// Optionals needed for some databases like dBase
|
|
|
|
wxString DefaultDir; // Directory that db file resides in
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
wxDbConnectInf();
|
2004-09-10 12:56:07 +00:00
|
|
|
wxDbConnectInf(HENV henv, const wxString &dsn, const wxString &userID=wxEmptyString,
|
|
|
|
const wxString &password=wxEmptyString, const wxString &defaultDir=wxEmptyString,
|
2001-02-05 13:36:33 +00:00
|
|
|
const wxString &description=wxEmptyString, const wxString &fileType=wxEmptyString);
|
2001-02-03 17:50:45 +00:00
|
|
|
|
|
|
|
~wxDbConnectInf();
|
|
|
|
|
|
|
|
bool Initialize();
|
|
|
|
|
|
|
|
bool AllocHenv();
|
|
|
|
void FreeHenv();
|
|
|
|
|
|
|
|
// Accessors
|
2001-02-04 15:56:59 +00:00
|
|
|
const HENV &GetHenv() { return Henv; };
|
2001-02-03 17:50:45 +00:00
|
|
|
|
|
|
|
const wxChar *GetDsn() { return Dsn; };
|
|
|
|
|
|
|
|
const wxChar *GetUid() { return Uid; };
|
|
|
|
const wxChar *GetUserID() { return Uid; };
|
|
|
|
|
|
|
|
const wxChar *GetAuthStr() { return AuthStr; };
|
|
|
|
const wxChar *GetPassword() { return AuthStr; };
|
|
|
|
|
2004-05-12 19:41:03 +00:00
|
|
|
const wxChar *GetConnectionStr() { return ConnectionStr; };
|
|
|
|
bool UseConnectionStr() { return useConnectionStr; };
|
|
|
|
|
2001-02-03 17:50:45 +00:00
|
|
|
const wxChar *GetDescription() { return Description; };
|
|
|
|
const wxChar *GetFileType() { return FileType; };
|
|
|
|
const wxChar *GetDefaultDir() { return DefaultDir; };
|
|
|
|
|
|
|
|
void SetHenv(const HENV henv) { Henv = henv; };
|
|
|
|
|
|
|
|
void SetDsn(const wxString &dsn);
|
|
|
|
|
|
|
|
void SetUserID(const wxString &userID);
|
|
|
|
void SetUid(const wxString &uid) { SetUserID(uid); };
|
|
|
|
|
|
|
|
void SetPassword(const wxString &password);
|
|
|
|
void SetAuthStr(const wxString &authstr) { SetPassword(authstr); };
|
|
|
|
|
2004-05-12 19:41:03 +00:00
|
|
|
void SetConnectionStr(const wxString &connectStr);
|
|
|
|
|
2001-02-03 17:50:45 +00:00
|
|
|
void SetDescription(const wxString &desc) { Description = desc; };
|
|
|
|
void SetFileType(const wxString &fileType) { FileType = fileType; };
|
|
|
|
void SetDefaultDir(const wxString &defDir) { DefaultDir = defDir; };
|
|
|
|
}; // class wxDbConnectInf
|
1999-10-07 14:19:57 +00:00
|
|
|
|
1998-07-28 09:43:44 +00:00
|
|
|
|
2003-08-02 19:14:54 +00:00
|
|
|
struct WXDLLIMPEXP_ODBC wxDbSqlTypeInfo
|
1998-07-28 09:43:44 +00:00
|
|
|
{
|
2001-02-01 20:21:52 +00:00
|
|
|
wxString TypeName;
|
2001-04-11 14:11:02 +00:00
|
|
|
SWORD FsqlType;
|
2001-02-01 20:21:52 +00:00
|
|
|
long Precision;
|
|
|
|
short CaseSensitive;
|
|
|
|
short MaximumScale;
|
2000-03-16 19:00:24 +00:00
|
|
|
};
|
1998-07-28 09:43:44 +00:00
|
|
|
|
2000-01-31 15:41:28 +00:00
|
|
|
|
2003-08-02 19:14:54 +00:00
|
|
|
class WXDLLIMPEXP_ODBC wxDbColFor
|
2000-01-20 14:15:44 +00:00
|
|
|
{
|
2000-01-31 15:41:28 +00:00
|
|
|
public:
|
2001-02-03 17:50:45 +00:00
|
|
|
wxString s_Field; // Formated String for Output
|
|
|
|
wxString s_Format[7]; // Formated Objects - TIMESTAMP has the biggest (7)
|
2000-08-08 06:11:51 +00:00
|
|
|
wxString s_Amount[7]; // Formated Objects - amount of things that can be formatted
|
|
|
|
int i_Amount[7]; // Formated Objects - TT MM YYYY HH MM SS m
|
2001-02-03 17:50:45 +00:00
|
|
|
int i_Nation; // 0 = timestamp , 1=EU, 2=UK, 3=International, 4=US
|
|
|
|
int i_dbDataType; // conversion of the 'sqlDataType' to the generic data type used by these classes
|
2000-01-31 15:41:28 +00:00
|
|
|
SWORD i_sqlDataType;
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
wxDbColFor();
|
2004-10-18 05:56:07 +00:00
|
|
|
~wxDbColFor(){}
|
2000-03-17 08:44:44 +00:00
|
|
|
|
2001-02-04 15:56:59 +00:00
|
|
|
void Initialize();
|
2004-11-04 21:31:12 +00:00
|
|
|
int Format(int Nation, int dbDataType, SWORD sqlDataType, short columnLength, short decimalDigits);
|
2000-01-20 14:15:44 +00:00
|
|
|
};
|
|
|
|
|
2000-01-31 15:41:28 +00:00
|
|
|
|
2003-08-02 19:14:54 +00:00
|
|
|
class WXDLLIMPEXP_ODBC wxDbColInf
|
1998-07-28 09:43:44 +00:00
|
|
|
{
|
|
|
|
public:
|
2001-02-01 20:21:52 +00:00
|
|
|
wxChar catalog[128+1];
|
|
|
|
wxChar schema[128+1];
|
|
|
|
wxChar tableName[DB_MAX_TABLE_NAME_LEN+1];
|
|
|
|
wxChar colName[DB_MAX_COLUMN_NAME_LEN+1];
|
2000-01-31 15:41:28 +00:00
|
|
|
SWORD sqlDataType;
|
2001-02-01 20:21:52 +00:00
|
|
|
wxChar typeName[128+1];
|
2004-11-04 21:31:12 +00:00
|
|
|
SWORD columnLength;
|
|
|
|
SWORD bufferSize;
|
2000-01-31 15:41:28 +00:00
|
|
|
short decimalDigits;
|
|
|
|
short numPrecRadix;
|
|
|
|
short nullable;
|
2001-02-01 20:21:52 +00:00
|
|
|
wxChar remarks[254+1];
|
2000-01-31 15:41:28 +00:00
|
|
|
int dbDataType; // conversion of the 'sqlDataType' to the generic data type used by these classes
|
2000-01-20 14:15:44 +00:00
|
|
|
// mj10777.19991224 : new
|
|
|
|
int PkCol; // Primary key column 0=No; 1= First Key, 2 = Second Key etc.
|
2001-02-01 20:21:52 +00:00
|
|
|
wxChar PkTableName[DB_MAX_TABLE_NAME_LEN+1]; // Tables that use this PKey as a FKey
|
2000-01-20 14:15:44 +00:00
|
|
|
int FkCol; // Foreign key column 0=No; 1= First Key, 2 = Second Key etc.
|
2001-02-01 20:21:52 +00:00
|
|
|
wxChar FkTableName[DB_MAX_TABLE_NAME_LEN+1]; // Foreign key table name
|
2000-07-15 19:51:35 +00:00
|
|
|
wxDbColFor *pColFor; // How should this columns be formatted
|
2000-08-08 06:11:51 +00:00
|
|
|
|
|
|
|
wxDbColInf();
|
|
|
|
~wxDbColInf();
|
2001-02-05 13:36:33 +00:00
|
|
|
|
|
|
|
bool Initialize();
|
2000-01-20 14:15:44 +00:00
|
|
|
};
|
|
|
|
|
2000-01-31 15:41:28 +00:00
|
|
|
|
2003-08-02 19:14:54 +00:00
|
|
|
class WXDLLIMPEXP_ODBC wxDbTableInf // Description of a Table
|
2000-01-31 15:41:28 +00:00
|
|
|
{
|
2000-01-20 14:15:44 +00:00
|
|
|
public:
|
2001-02-01 20:21:52 +00:00
|
|
|
wxChar tableName[DB_MAX_TABLE_NAME_LEN+1];
|
|
|
|
wxChar tableType[254+1]; // "TABLE" or "SYSTEM TABLE" etc.
|
|
|
|
wxChar tableRemarks[254+1];
|
2001-04-11 14:11:02 +00:00
|
|
|
UWORD numCols; // How many Columns does this Table have: GetColumnCount(..);
|
2000-07-15 19:51:35 +00:00
|
|
|
wxDbColInf *pColInf; // pColInf = NULL ; User can later call GetColumns(..);
|
2001-02-05 13:36:33 +00:00
|
|
|
|
2000-08-08 06:11:51 +00:00
|
|
|
wxDbTableInf();
|
|
|
|
~wxDbTableInf();
|
2001-02-05 13:36:33 +00:00
|
|
|
|
|
|
|
bool Initialize();
|
2000-01-20 14:15:44 +00:00
|
|
|
};
|
|
|
|
|
2000-01-31 15:41:28 +00:00
|
|
|
|
2003-08-02 19:14:54 +00:00
|
|
|
class WXDLLIMPEXP_ODBC wxDbInf // Description of a Database
|
2000-01-31 15:41:28 +00:00
|
|
|
{
|
2000-01-20 14:15:44 +00:00
|
|
|
public:
|
2001-02-01 20:21:52 +00:00
|
|
|
wxChar catalog[128+1];
|
|
|
|
wxChar schema[128+1];
|
2000-07-15 19:51:35 +00:00
|
|
|
int numTables; // How many tables does this database have
|
|
|
|
wxDbTableInf *pTableInf; // pTableInf = new wxDbTableInf[numTables];
|
2000-08-08 06:11:51 +00:00
|
|
|
|
|
|
|
wxDbInf();
|
|
|
|
~wxDbInf();
|
2001-02-04 15:56:59 +00:00
|
|
|
|
2001-02-05 13:36:33 +00:00
|
|
|
bool Initialize();
|
1998-07-28 09:43:44 +00:00
|
|
|
};
|
|
|
|
|
2000-01-31 15:41:28 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
enum wxDbSqlLogState
|
1998-12-30 17:40:53 +00:00
|
|
|
{
|
2000-01-31 15:41:28 +00:00
|
|
|
sqlLogOFF,
|
|
|
|
sqlLogON
|
1998-12-30 17:40:53 +00:00
|
|
|
};
|
|
|
|
|
2000-01-31 15:41:28 +00:00
|
|
|
// These are the databases currently tested and working with these classes
|
2000-07-15 19:51:35 +00:00
|
|
|
// See the comments in wxDb::Dbms() for exceptions/issues with
|
2000-01-31 15:41:28 +00:00
|
|
|
// each of these database engines
|
2000-03-16 19:00:24 +00:00
|
|
|
enum wxDBMS
|
1999-10-07 14:19:57 +00:00
|
|
|
{
|
2000-01-31 15:41:28 +00:00
|
|
|
dbmsUNIDENTIFIED,
|
|
|
|
dbmsORACLE,
|
|
|
|
dbmsSYBASE_ASA, // Adaptive Server Anywhere
|
|
|
|
dbmsSYBASE_ASE, // Adaptive Server Enterprise
|
|
|
|
dbmsMS_SQL_SERVER,
|
|
|
|
dbmsMY_SQL,
|
|
|
|
dbmsPOSTGRES,
|
|
|
|
dbmsACCESS,
|
|
|
|
dbmsDBASE,
|
2000-07-15 19:51:35 +00:00
|
|
|
dbmsINFORMIX,
|
2000-11-20 17:17:09 +00:00
|
|
|
dbmsVIRTUOSO,
|
2000-11-22 00:19:25 +00:00
|
|
|
dbmsDB2,
|
2001-05-11 20:24:53 +00:00
|
|
|
dbmsINTERBASE,
|
2002-08-16 12:43:07 +00:00
|
|
|
dbmsPERVASIVE_SQL,
|
2004-12-28 00:33:09 +00:00
|
|
|
dbmsXBASE_SEQUITER,
|
|
|
|
dbmsFIREBIRD
|
1999-10-07 14:19:57 +00:00
|
|
|
};
|
|
|
|
|
2000-01-31 15:41:28 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
// The wxDb::errorList is copied to this variable when the wxDb object
|
1999-10-07 14:19:57 +00:00
|
|
|
// is closed. This way, the error list is still available after the
|
2000-03-17 08:44:44 +00:00
|
|
|
// database object is closed. This is necessary if the database
|
1999-10-07 14:19:57 +00:00
|
|
|
// connection fails so the calling application can show the operator
|
2000-07-15 19:51:35 +00:00
|
|
|
// why the connection failed. Note: as each wxDb object is closed, it
|
|
|
|
// will overwrite the errors of the previously destroyed wxDb object in
|
1999-10-07 14:19:57 +00:00
|
|
|
// this variable.
|
2002-02-05 19:07:20 +00:00
|
|
|
|
2004-06-13 21:52:14 +00:00
|
|
|
WXDLLIMPEXP_DATA_ODBC(extern wxChar)
|
2003-07-02 01:41:23 +00:00
|
|
|
DBerrorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN];
|
1999-10-07 14:19:57 +00:00
|
|
|
|
2000-01-31 15:41:28 +00:00
|
|
|
|
2003-08-02 19:14:54 +00:00
|
|
|
class WXDLLIMPEXP_ODBC wxDb
|
1998-07-28 09:43:44 +00:00
|
|
|
{
|
|
|
|
private:
|
2000-01-31 15:41:28 +00:00
|
|
|
bool dbIsOpen;
|
2001-06-10 17:05:25 +00:00
|
|
|
bool dbIsCached; // Was connection created by caching functions
|
2004-05-12 19:41:03 +00:00
|
|
|
bool dbOpenedWithConnectionString; // Was the database connection opened with a connection string
|
2001-02-01 20:21:52 +00:00
|
|
|
wxString dsn; // Data source name
|
|
|
|
wxString uid; // User ID
|
|
|
|
wxString authStr; // Authorization string (password)
|
2004-05-12 19:41:03 +00:00
|
|
|
wxString inConnectionStr; // Connection string used to connect to the database
|
|
|
|
wxString outConnectionStr;// Connection string returned by the database when a connection is successfully opened
|
2000-01-31 15:41:28 +00:00
|
|
|
FILE *fpSqlLog; // Sql Log file pointer
|
2000-07-15 19:51:35 +00:00
|
|
|
wxDbSqlLogState sqlLogState; // On or Off
|
2000-01-31 15:41:28 +00:00
|
|
|
bool fwdOnlyCursors;
|
2000-11-20 17:17:09 +00:00
|
|
|
wxDBMS dbmsType; // Type of datasource - i.e. Oracle, dBase, SQLServer, etc
|
2000-01-31 15:41:28 +00:00
|
|
|
|
|
|
|
// Private member functions
|
2004-09-10 12:56:07 +00:00
|
|
|
bool getDbInfo(bool failOnDataTypeUnsupported=true);
|
2000-07-15 19:51:35 +00:00
|
|
|
bool getDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo);
|
2000-01-31 15:41:28 +00:00
|
|
|
bool setConnectionOptions(void);
|
2001-02-01 20:21:52 +00:00
|
|
|
void logError(const wxString &errMsg, const wxString &SQLState);
|
|
|
|
const wxChar *convertUserID(const wxChar *userID, wxString &UserID);
|
2004-12-28 19:22:37 +00:00
|
|
|
bool determineDataTypes(bool failOnDataTypeUnsupported);
|
2001-02-05 13:36:33 +00:00
|
|
|
void initialize();
|
2004-09-10 12:56:07 +00:00
|
|
|
bool open(bool failOnDataTypeUnsupported=true);
|
2001-02-01 20:21:52 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
#if !wxODBC_BACKWARD_COMPATABILITY
|
|
|
|
// ODBC handles
|
|
|
|
HENV henv; // ODBC Environment handle
|
|
|
|
HDBC hdbc; // ODBC DB Connection handle
|
|
|
|
HSTMT hstmt; // ODBC Statement handle
|
|
|
|
|
|
|
|
//Error reporting mode
|
|
|
|
bool silent;
|
|
|
|
|
|
|
|
// Number of Ctable objects connected to this db object. FOR INTERNAL USE ONLY!!!
|
|
|
|
unsigned int nTables;
|
|
|
|
|
|
|
|
// Information about logical data types VARCHAR, INTEGER, FLOAT and DATE.
|
2000-08-08 06:11:51 +00:00
|
|
|
//
|
2000-07-15 19:51:35 +00:00
|
|
|
// This information is obtained from the ODBC driver by use of the
|
|
|
|
// SQLGetTypeInfo() function. The key piece of information is the
|
|
|
|
// type name the data source uses for each logical data type.
|
|
|
|
// e.g. VARCHAR; Oracle calls it VARCHAR2.
|
|
|
|
wxDbSqlTypeInfo typeInfVarchar;
|
|
|
|
wxDbSqlTypeInfo typeInfInteger;
|
|
|
|
wxDbSqlTypeInfo typeInfFloat;
|
|
|
|
wxDbSqlTypeInfo typeInfDate;
|
2001-02-13 11:42:35 +00:00
|
|
|
wxDbSqlTypeInfo typeInfBlob;
|
2000-07-15 19:51:35 +00:00
|
|
|
#endif
|
1999-11-29 19:20:53 +00:00
|
|
|
|
1998-07-28 09:43:44 +00:00
|
|
|
public:
|
2001-02-13 11:42:35 +00:00
|
|
|
|
2001-06-10 17:05:25 +00:00
|
|
|
void setCached(bool cached) { dbIsCached = cached; }; // This function must only be called by wxDbGetConnection() and wxDbCloseConnections!!!
|
|
|
|
bool IsCached() { return dbIsCached; };
|
|
|
|
|
2001-02-13 11:42:35 +00:00
|
|
|
bool GetDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo)
|
|
|
|
{ return getDataTypeInfo(fSqlType, structSQLTypeInfo); }
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
#if wxODBC_BACKWARD_COMPATABILITY
|
|
|
|
// ODBC handles
|
|
|
|
HENV henv; // ODBC Environment handle
|
|
|
|
HDBC hdbc; // ODBC DB Connection handle
|
|
|
|
HSTMT hstmt; // ODBC Statement handle
|
|
|
|
|
|
|
|
//Error reporting mode
|
|
|
|
bool silent;
|
|
|
|
|
|
|
|
// Number of Ctable objects connected to this db object. FOR INTERNAL USE ONLY!!!
|
|
|
|
unsigned int nTables;
|
|
|
|
#endif
|
|
|
|
|
2000-01-31 15:41:28 +00:00
|
|
|
// The following structure contains database information gathered from the
|
|
|
|
// datasource when the datasource is first opened.
|
|
|
|
struct
|
|
|
|
{
|
2001-02-01 20:21:52 +00:00
|
|
|
wxChar dbmsName[40]; // Name of the dbms product
|
|
|
|
wxChar dbmsVer[64]; // Version # of the dbms product
|
|
|
|
wxChar driverName[40]; // Driver name
|
|
|
|
wxChar odbcVer[60]; // ODBC version of the driver
|
|
|
|
wxChar drvMgrOdbcVer[60]; // ODBC version of the driver manager
|
|
|
|
wxChar driverVer[60]; // Driver version
|
|
|
|
wxChar serverName[80]; // Server Name, typically a connect string
|
|
|
|
wxChar databaseName[128]; // Database filename
|
|
|
|
wxChar outerJoins[2]; // Indicates whether the data source supports outer joins
|
|
|
|
wxChar procedureSupport[2]; // Indicates whether the data source supports stored procedures
|
|
|
|
wxChar accessibleTables[2]; // Indicates whether the data source only reports accessible tables in SQLTables.
|
2000-01-31 15:41:28 +00:00
|
|
|
UWORD maxConnections; // Maximum # of connections the data source supports
|
|
|
|
UWORD maxStmts; // Maximum # of HSTMTs per HDBC
|
|
|
|
UWORD apiConfLvl; // ODBC API conformance level
|
|
|
|
UWORD cliConfLvl; // Indicates whether the data source is SAG compliant
|
|
|
|
UWORD sqlConfLvl; // SQL conformance level
|
|
|
|
UWORD cursorCommitBehavior; // Indicates how cursors are affected by a db commit
|
|
|
|
UWORD cursorRollbackBehavior; // Indicates how cursors are affected by a db rollback
|
|
|
|
UWORD supportNotNullClause; // Indicates if data source supports NOT NULL clause
|
2001-02-01 20:21:52 +00:00
|
|
|
wxChar supportIEF[2]; // Integrity Enhancement Facility (Referential Integrity)
|
2000-01-31 15:41:28 +00:00
|
|
|
UDWORD txnIsolation; // Default transaction isolation level supported by the driver
|
|
|
|
UDWORD txnIsolationOptions; // Transaction isolation level options available
|
|
|
|
UDWORD fetchDirections; // Fetch directions supported
|
|
|
|
UDWORD lockTypes; // Lock types supported in SQLSetPos
|
|
|
|
UDWORD posOperations; // Position operations supported in SQLSetPos
|
|
|
|
UDWORD posStmts; // Position statements supported
|
|
|
|
UDWORD scrollConcurrency; // Concurrency control options supported for scrollable cursors
|
|
|
|
UDWORD scrollOptions; // Scroll Options supported for scrollable cursors
|
|
|
|
UDWORD staticSensitivity; // Indicates if additions, deletions and updates can be detected
|
|
|
|
UWORD txnCapable; // Indicates if the data source supports transactions
|
|
|
|
UDWORD loginTimeout; // Number seconds to wait for a login request
|
|
|
|
} dbInf;
|
|
|
|
|
|
|
|
// ODBC Error Inf.
|
|
|
|
SWORD cbErrorMsg;
|
|
|
|
int DB_STATUS;
|
2000-07-15 19:51:35 +00:00
|
|
|
wxChar errorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN];
|
|
|
|
wxChar errorMsg[SQL_MAX_MESSAGE_LENGTH];
|
|
|
|
SDWORD nativeError;
|
|
|
|
wxChar sqlState[20];
|
2000-01-31 15:41:28 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
#if wxODBC_BACKWARD_COMPATABILITY
|
|
|
|
// Information about logical data types VARCHAR, INTEGER, FLOAT and DATE.
|
2000-08-08 06:11:51 +00:00
|
|
|
//
|
2000-07-15 19:51:35 +00:00
|
|
|
// This information is obtained from the ODBC driver by use of the
|
|
|
|
// SQLGetTypeInfo() function. The key piece of information is the
|
2000-01-31 15:41:28 +00:00
|
|
|
// type name the data source uses for each logical data type.
|
|
|
|
// e.g. VARCHAR; Oracle calls it VARCHAR2.
|
2000-07-15 19:51:35 +00:00
|
|
|
wxDbSqlTypeInfo typeInfVarchar;
|
|
|
|
wxDbSqlTypeInfo typeInfInteger;
|
|
|
|
wxDbSqlTypeInfo typeInfFloat;
|
|
|
|
wxDbSqlTypeInfo typeInfDate;
|
2001-02-13 11:42:35 +00:00
|
|
|
wxDbSqlTypeInfo typeInfBlob;
|
2000-07-15 19:51:35 +00:00
|
|
|
#endif
|
2000-03-17 08:44:44 +00:00
|
|
|
|
2000-01-31 15:41:28 +00:00
|
|
|
// Public member functions
|
2001-02-04 15:56:59 +00:00
|
|
|
wxDb(const HENV &aHenv, bool FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS);
|
2001-06-10 17:05:25 +00:00
|
|
|
~wxDb();
|
2001-02-03 17:50:45 +00:00
|
|
|
|
2002-03-22 13:43:15 +00:00
|
|
|
// Data Source Name, User ID, Password and whether open should fail on data type not supported
|
2004-09-10 12:56:07 +00:00
|
|
|
bool Open(const wxString& inConnectStr, bool failOnDataTypeUnsupported=true);
|
|
|
|
bool Open(const wxString &Dsn, const wxString &Uid, const wxString &AuthStr, bool failOnDataTypeUnsupported=true);
|
|
|
|
bool Open(wxDbConnectInf *dbConnectInf, bool failOnDataTypeUnsupported=true);
|
2000-11-20 17:17:09 +00:00
|
|
|
bool Open(wxDb *copyDb); // pointer to a wxDb whose connection info should be copied rather than re-queried
|
2000-01-31 15:41:28 +00:00
|
|
|
void Close(void);
|
|
|
|
bool CommitTrans(void);
|
|
|
|
bool RollbackTrans(void);
|
|
|
|
bool DispAllErrors(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT);
|
|
|
|
bool GetNextError(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT);
|
|
|
|
void DispNextError(void);
|
2004-09-10 12:56:07 +00:00
|
|
|
bool CreateView(const wxString &viewName, const wxString &colList, const wxString &pSqlStmt, bool attemptDrop=true);
|
2001-02-01 20:21:52 +00:00
|
|
|
bool DropView(const wxString &viewName);
|
|
|
|
bool ExecSql(const wxString &pSqlStmt);
|
2004-11-06 20:32:34 +00:00
|
|
|
bool ExecSql(const wxString &pSqlStmt, wxDbColInf** columns, short& numcols);
|
2000-01-31 15:41:28 +00:00
|
|
|
bool GetNext(void);
|
|
|
|
bool GetData(UWORD colNo, SWORD cType, PTR pData, SDWORD maxLen, SDWORD FAR *cbReturned);
|
2001-02-01 20:21:52 +00:00
|
|
|
bool Grant(int privileges, const wxString &tableName, const wxString &userList = wxT("PUBLIC"));
|
|
|
|
int TranslateSqlState(const wxString &SQLState);
|
|
|
|
wxDbInf *GetCatalog(const wxChar *userID=NULL);
|
|
|
|
bool Catalog(const wxChar *userID=NULL, const wxString &fileName=SQL_CATALOG_FILENAME);
|
2001-04-11 14:11:02 +00:00
|
|
|
int GetKeyFields(const wxString &tableName, wxDbColInf* colInf, UWORD noCols);
|
2001-02-01 20:21:52 +00:00
|
|
|
|
|
|
|
wxDbColInf *GetColumns(wxChar *tableName[], const wxChar *userID=NULL);
|
2004-09-10 12:56:07 +00:00
|
|
|
wxDbColInf *GetColumns(const wxString &tableName, UWORD *numCols, const wxChar *userID=NULL);
|
2001-02-01 20:21:52 +00:00
|
|
|
|
2001-06-12 17:20:10 +00:00
|
|
|
int GetColumnCount(const wxString &tableName, const wxChar *userID=NULL);
|
2001-02-13 11:42:35 +00:00
|
|
|
const wxChar *GetDatabaseName(void) {return dbInf.dbmsName;}
|
2001-02-01 20:21:52 +00:00
|
|
|
const wxString &GetDataSource(void) {return dsn;}
|
|
|
|
const wxString &GetDatasourceName(void){return dsn;}
|
|
|
|
const wxString &GetUsername(void) {return uid;}
|
|
|
|
const wxString &GetPassword(void) {return authStr;}
|
2004-05-12 19:41:03 +00:00
|
|
|
const wxString &GetConnectionInStr(void) {return inConnectionStr;}
|
|
|
|
const wxString &GetConnectionOutStr(void) {return outConnectionStr;}
|
2001-02-13 11:42:35 +00:00
|
|
|
bool IsOpen(void) {return dbIsOpen;}
|
2004-05-12 19:41:03 +00:00
|
|
|
bool OpenedWithConnectionString(void) {return dbOpenedWithConnectionString;}
|
2001-02-13 11:42:35 +00:00
|
|
|
HENV GetHENV(void) {return henv;}
|
|
|
|
HDBC GetHDBC(void) {return hdbc;}
|
|
|
|
HSTMT GetHSTMT(void) {return hstmt;}
|
|
|
|
int GetTableCount() {return nTables;} // number of tables using this connection
|
|
|
|
wxDbSqlTypeInfo GetTypeInfVarchar() {return typeInfVarchar;}
|
|
|
|
wxDbSqlTypeInfo GetTypeInfInteger() {return typeInfInteger;}
|
|
|
|
wxDbSqlTypeInfo GetTypeInfFloat() {return typeInfFloat;}
|
|
|
|
wxDbSqlTypeInfo GetTypeInfDate() {return typeInfDate;}
|
|
|
|
wxDbSqlTypeInfo GetTypeInfBlob() {return typeInfBlob;}
|
|
|
|
|
|
|
|
// tableName can refer to a table, view, alias or synonym
|
2004-09-10 12:56:07 +00:00
|
|
|
bool TableExists(const wxString &tableName, const wxChar *userID=NULL,
|
2001-02-13 11:42:35 +00:00
|
|
|
const wxString &tablePath=wxEmptyString);
|
2004-09-10 12:56:07 +00:00
|
|
|
bool TablePrivileges(const wxString &tableName, const wxString &priv,
|
|
|
|
const wxChar *userID=NULL, const wxChar *schema=NULL,
|
2001-02-13 11:42:35 +00:00
|
|
|
const wxString &path=wxEmptyString);
|
|
|
|
|
2001-10-04 16:44:08 +00:00
|
|
|
// These two functions return the table name or column name in a form ready
|
|
|
|
// for use in SQL statements. For example, if the datasource allows spaces
|
|
|
|
// in the table name or column name, the returned string will have the
|
2004-09-10 12:56:07 +00:00
|
|
|
// correct enclosing marks around the name to allow it to be properly
|
2001-10-04 16:44:08 +00:00
|
|
|
// included in a SQL statement
|
2001-11-23 00:42:10 +00:00
|
|
|
const wxString SQLTableName(const wxChar *tableName);
|
|
|
|
const wxString SQLColumnName(const wxChar *colName);
|
2001-10-04 16:44:08 +00:00
|
|
|
|
2004-09-10 12:56:07 +00:00
|
|
|
void LogError(const wxString &errMsg, const wxString &SQLState = wxEmptyString)
|
2001-02-13 11:42:35 +00:00
|
|
|
{ logError(errMsg, SQLState); }
|
2000-07-15 19:51:35 +00:00
|
|
|
void SetDebugErrorMessages(bool state) { silent = !state; }
|
2004-09-10 12:56:07 +00:00
|
|
|
bool SetSqlLogging(wxDbSqlLogState state, const wxString &filename = SQL_LOG_FILENAME,
|
|
|
|
bool append = false);
|
2001-02-01 20:21:52 +00:00
|
|
|
bool WriteSqlLog(const wxString &logMsg);
|
2001-02-13 11:42:35 +00:00
|
|
|
|
2000-03-16 19:00:24 +00:00
|
|
|
wxDBMS Dbms(void);
|
2001-02-01 20:21:52 +00:00
|
|
|
bool ModifyColumn(const wxString &tableName, const wxString &columnName,
|
|
|
|
int dataType, ULONG columnLength=0,
|
2001-02-05 13:36:33 +00:00
|
|
|
const wxString &optionalParam=wxEmptyString);
|
2001-02-01 20:21:52 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
bool FwdOnlyCursors(void) {return fwdOnlyCursors;}
|
|
|
|
|
|
|
|
// These two functions are provided strictly for use by wxDbTable.
|
|
|
|
// DO NOT USE THESE FUNCTIONS, OR MEMORY LEAKS MAY OCCUR
|
|
|
|
void incrementTableCount() { nTables++; return; }
|
|
|
|
void decrementTableCount() { nTables--; return; }
|
|
|
|
|
|
|
|
}; // wxDb
|
1998-07-28 09:43:44 +00:00
|
|
|
|
2000-03-16 19:00:24 +00:00
|
|
|
|
1998-07-28 09:43:44 +00:00
|
|
|
// This structure forms a node in a linked list. The linked list of "DbList" objects
|
|
|
|
// keeps track of allocated database connections. This allows the application to
|
|
|
|
// open more than one database connection through ODBC for multiple transaction support
|
|
|
|
// or for multiple database support.
|
2000-03-16 19:00:24 +00:00
|
|
|
struct wxDbList
|
1998-07-28 09:43:44 +00:00
|
|
|
{
|
2001-02-01 20:21:52 +00:00
|
|
|
wxDbList *PtrPrev; // Pointer to previous item in the list
|
|
|
|
wxString Dsn; // Data Source Name
|
|
|
|
wxString Uid; // User ID
|
|
|
|
wxString AuthStr; // Authorization string (password)
|
2004-05-12 19:41:03 +00:00
|
|
|
wxString ConnectionStr; // Connection string used instead of DSN
|
2001-02-01 20:21:52 +00:00
|
|
|
wxDb *PtrDb; // Pointer to the wxDb object
|
|
|
|
bool Free; // Is item free or in use?
|
|
|
|
wxDbList *PtrNext; // Pointer to next item in the list
|
1998-07-28 09:43:44 +00:00
|
|
|
};
|
|
|
|
|
2001-02-03 17:50:45 +00:00
|
|
|
|
1999-11-08 21:14:50 +00:00
|
|
|
#ifdef __WXDEBUG__
|
1999-10-09 13:32:40 +00:00
|
|
|
#include "wx/object.h"
|
2000-03-16 19:00:24 +00:00
|
|
|
class wxTablesInUse : public wxObject
|
1999-10-07 14:19:57 +00:00
|
|
|
{
|
2000-01-31 15:41:28 +00:00
|
|
|
public:
|
2001-02-01 20:21:52 +00:00
|
|
|
const wxChar *tableName;
|
2000-01-31 15:41:28 +00:00
|
|
|
ULONG tableID;
|
2000-07-15 19:51:35 +00:00
|
|
|
class wxDb *pDb;
|
2000-03-16 19:00:24 +00:00
|
|
|
}; // wxTablesInUse
|
1999-10-07 14:19:57 +00:00
|
|
|
#endif
|
|
|
|
|
2000-03-16 19:00:24 +00:00
|
|
|
|
1998-07-28 09:43:44 +00:00
|
|
|
// The following routines allow a user to get new database connections, free them
|
|
|
|
// for other code segments to use, or close all of them when the application has
|
|
|
|
// completed.
|
2003-08-02 19:14:54 +00:00
|
|
|
wxDb WXDLLIMPEXP_ODBC *wxDbGetConnection(wxDbConnectInf *pDbConfig, bool FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS);
|
|
|
|
bool WXDLLIMPEXP_ODBC wxDbFreeConnection(wxDb *pDb);
|
|
|
|
void WXDLLIMPEXP_ODBC wxDbCloseConnections(void);
|
|
|
|
int WXDLLIMPEXP_ODBC wxDbConnectionsInUse(void);
|
2000-01-31 15:41:28 +00:00
|
|
|
|
1998-07-28 09:43:44 +00:00
|
|
|
|
2001-06-10 17:05:25 +00:00
|
|
|
// Writes a message to the wxLog window (stdout usually) when an internal error
|
|
|
|
// situation occurs. This function only works in DEBUG builds
|
2003-08-04 18:56:58 +00:00
|
|
|
const wxChar WXDLLIMPEXP_ODBC *
|
2003-07-02 01:41:23 +00:00
|
|
|
wxDbLogExtendedErrorMsg(const wxChar *userText,
|
|
|
|
wxDb *pDb,
|
|
|
|
const wxChar *ErrFile,
|
|
|
|
int ErrLine);
|
2001-11-23 00:42:10 +00:00
|
|
|
|
2001-06-10 17:05:25 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
// This function sets the sql log state for all open wxDb objects
|
2003-08-02 19:14:54 +00:00
|
|
|
bool WXDLLIMPEXP_ODBC
|
2003-07-02 01:41:23 +00:00
|
|
|
wxDbSqlLog(wxDbSqlLogState state, const wxString &filename = SQL_LOG_FILENAME);
|
2000-03-16 19:00:24 +00:00
|
|
|
|
2000-01-31 15:41:28 +00:00
|
|
|
|
2000-03-16 19:00:24 +00:00
|
|
|
#if 0
|
|
|
|
// MSW/VC6 ONLY!!! Experimental
|
2001-02-05 13:36:33 +00:00
|
|
|
int WXDLLEXPORT wxDbCreateDataSource(const wxString &driverName, const wxString &dsn, const wxString &description=wxEmptyString,
|
2004-09-10 12:56:07 +00:00
|
|
|
bool sysDSN=false, const wxString &defDir=wxEmptyString, wxWindow *parent=NULL);
|
2000-03-16 19:00:24 +00:00
|
|
|
#endif
|
1999-10-07 14:19:57 +00:00
|
|
|
|
1998-07-28 09:43:44 +00:00
|
|
|
// This routine allows you to query a driver manager
|
|
|
|
// for a list of available datasources. Call this routine
|
|
|
|
// the first time using SQL_FETCH_FIRST. Continue to call it
|
|
|
|
// using SQL_FETCH_NEXT until you've exhausted the list.
|
2003-08-02 19:14:54 +00:00
|
|
|
bool WXDLLIMPEXP_ODBC
|
2004-11-04 21:31:12 +00:00
|
|
|
wxDbGetDataSource(HENV henv, wxChar *Dsn, SWORD DsnMaxLength, wxChar *DsDesc,
|
|
|
|
SWORD DsDescMaxLength, UWORD direction = SQL_FETCH_NEXT);
|
2000-03-16 19:00:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Change this to 0 to remove use of all deprecated functions
|
2000-07-15 19:51:35 +00:00
|
|
|
#if wxODBC_BACKWARD_COMPATABILITY
|
2000-03-16 19:00:24 +00:00
|
|
|
//#################################################################################
|
|
|
|
//############### DEPRECATED functions for backward compatability #################
|
|
|
|
//#################################################################################
|
|
|
|
|
|
|
|
// Backward compability structures/classes. This will eventually go away
|
2000-07-15 19:51:35 +00:00
|
|
|
const int DB_PATH_MAX = wxDB_PATH_MAX;
|
|
|
|
|
|
|
|
typedef wxDb wxDB;
|
|
|
|
typedef wxDbTableInf wxTableInf;
|
|
|
|
typedef wxDbColInf wxColInf;
|
|
|
|
typedef wxDbColInf CcolInf;
|
|
|
|
typedef wxDbColFor wxColFor;
|
|
|
|
typedef wxDbSqlTypeInfo SqlTypeInfo;
|
|
|
|
typedef wxDbSqlTypeInfo wxSqlTypeInfo;
|
|
|
|
typedef enum wxDbSqlLogState sqlLog;
|
|
|
|
typedef enum wxDbSqlLogState wxSqlLogState;
|
|
|
|
typedef enum wxDBMS dbms;
|
|
|
|
typedef enum wxDBMS DBMS;
|
|
|
|
typedef wxODBC_ERRORS ODBC_ERRORS;
|
|
|
|
typedef wxDbConnectInf DbStuff;
|
|
|
|
typedef wxDbList DbList;
|
2000-03-17 11:15:57 +00:00
|
|
|
#ifdef __WXDEBUG__
|
2000-07-15 19:51:35 +00:00
|
|
|
typedef wxTablesInUse CstructTablesInUse;
|
2000-03-17 11:15:57 +00:00
|
|
|
#endif
|
2000-03-16 19:00:24 +00:00
|
|
|
|
|
|
|
// Deprecated function names that are replaced by the function names listed above
|
2003-08-02 19:14:54 +00:00
|
|
|
wxDB WXDLLIMPEXP_ODBC
|
2003-07-02 01:41:23 +00:00
|
|
|
*GetDbConnection(DbStuff *pDbStuff, bool FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS);
|
2003-08-02 19:14:54 +00:00
|
|
|
bool WXDLLIMPEXP_ODBC FreeDbConnection(wxDB *pDb);
|
|
|
|
void WXDLLIMPEXP_ODBC CloseDbConnections(void);
|
|
|
|
int WXDLLIMPEXP_ODBC NumberDbConnectionsInUse(void);
|
2000-03-16 19:00:24 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
bool SqlLog(sqlLog state, const wxChar *filename = SQL_LOG_FILENAME);
|
2000-03-16 19:00:24 +00:00
|
|
|
|
2003-08-02 19:14:54 +00:00
|
|
|
bool WXDLLIMPEXP_ODBC
|
2004-11-04 21:31:12 +00:00
|
|
|
GetDataSource(HENV henv, char *Dsn, SWORD DsnMaxLength, char *DsDesc, SWORD DsDescMaxLength,
|
2003-07-02 01:41:23 +00:00
|
|
|
UWORD direction = SQL_FETCH_NEXT);
|
|
|
|
|
2000-03-16 19:00:24 +00:00
|
|
|
#endif // Deprecated structures/classes/functions
|
1998-07-28 09:43:44 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
#endif // _WX_DB_H_
|
|
|
|
|