#define _WX_DB_H_
-// BJO 20000503: introduce new GetColumns members which are more database independant and
+// BJO 20000503: introduce new GetColumns members which are more database independent and
// return columns in the order they were created
#define OLD_GETCOLUMNS 1
#define EXPERIMENTAL_WXDB_FUNCTIONS 1
-#include "wx/version.h"
-
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma interface "db.h"
-#endif
-
-#include "wx/setup.h"
-
#include "wx/defs.h"
#include "wx/string.h"
#if wxUSE_MFC
#include <afxwin.h>
#else // !wxUSE_MFC
- #ifndef STRICT
- #define STRICT 1
- #endif
-
- #include <windows.h>
- #include "wx/msw/winundef.h"
+ #include "wx/msw/wrapwin.h"
#endif // wxUSE_MFC/!wxUSE_MFC
// If you use the wxDbCreateDataSource() function with MSW/VC6,
//
#include "sql.h"
#include "sqlext.h"
+ //#if wxUSE_UNICODE
+ // #include <sqlucode.h>
+ //#endif
#include "odbcinst.h"
#else
- #if defined(__WINDOWS__) && ( defined(HAVE_W32API_H) || defined(__BORLANDC__) )
- #include <windows.h>
- #include "wx/msw/winundef.h"
+ #if defined(__WINDOWS__) && ( defined(HAVE_W32API_H) || defined(__BORLANDC__) || defined (__DMC__))
+ #include "wx/msw/wrapwin.h"
#endif
extern "C" {
#if defined(wxUSE_BUILTIN_IODBC) && wxUSE_BUILTIN_IODBC
// Use the ones from the library
#include "wx/isql.h"
#include "wx/isqlext.h"
- #else
+ // Not available in v2.x of iODBC
+ #ifndef __WXMSW__
+ #if wxUSE_UNICODE
+ typedef wxChar SQLTCHAR;
+ #else
+ typedef UCHAR SQLTCHAR;
+ #endif
+ #endif
+ #else // !wxUSE_BUILTIN_IODBC
+ // SQL headers define BOOL if it's not defined yet but BOOL is also
+ // defined in many other places on other systems (Motif, at least on
+ // OpenVMS; Cocoa and X11) so prevent the problem by defining it before
+ // including these headers
+ #define BOOL int
#include <sql.h>
#include <sqlext.h>
- #endif
+ #undef BOOL
+ #endif // wxUSE_BUILTIN_IODBC/!wxUSE_BUILTIN_IODBC
}
#endif
#define SQL_C_WXCHAR SQL_C_CHAR
#endif
+#ifdef __DIGITALMARS__
+#if wxUSE_UNICODE
+typedef wxChar SQLTCHAR;
+#else
+typedef UCHAR SQLTCHAR;
+#endif
+#endif
+
typedef float SFLOAT;
typedef double SDOUBLE;
typedef unsigned int UINT;
#define ULONG UDWORD
-// Not available in iODBC
-#ifndef __WXMSW__
-typedef UCHAR SQLTCHAR;
-#endif
-
#ifndef wxODBC_FWD_ONLY_CURSORS
#define wxODBC_FWD_ONLY_CURSORS 1
#endif
#endif
#endif
+#ifndef _WIN64
+#ifndef SQLLEN
+#define SQLLEN SQLINTEGER
+#endif
+#ifndef SQLULEN
+#define SQLULEN SQLUINTEGER
+#endif
+#endif
+
const int wxDB_PATH_MAX = 254;
-WXDLLIMPEXP_DATA_ODBC(extern wxChar const *) SQL_LOG_FILENAME;
-WXDLLIMPEXP_DATA_ODBC(extern wxChar const *) SQL_CATALOG_FILENAME;
+extern WXDLLIMPEXP_DATA_ODBC(wxChar const *) SQL_LOG_FILENAME;
+extern WXDLLIMPEXP_DATA_ODBC(wxChar const *) SQL_CATALOG_FILENAME;
// Database Globals
const int DB_TYPE_NAME_LEN = 40;
const int DB_DATA_TYPE_FLOAT = 3;
const int DB_DATA_TYPE_DATE = 4;
const int DB_DATA_TYPE_BLOB = 5;
+const int DB_DATA_TYPE_MEMO = 6;
const int DB_SELECT_KEYFIELDS = 1;
const int DB_SELECT_WHERE = 2;
void FreeHenv();
// Accessors
- const HENV &GetHenv() { return Henv; };
+ const HENV &GetHenv() { return Henv; }
- const wxChar *GetDsn() { return Dsn; };
+ const wxChar *GetDsn() { return Dsn; }
- const wxChar *GetUid() { return Uid; };
- const wxChar *GetUserID() { return Uid; };
+ const wxChar *GetUid() { return Uid; }
+ const wxChar *GetUserID() { return Uid; }
- const wxChar *GetAuthStr() { return AuthStr; };
- const wxChar *GetPassword() { return AuthStr; };
+ const wxChar *GetAuthStr() { return AuthStr; }
+ const wxChar *GetPassword() { return AuthStr; }
- const wxChar *GetConnectionStr() { return ConnectionStr; };
- bool UseConnectionStr() { return useConnectionStr; };
+ const wxChar *GetConnectionStr() { return ConnectionStr; }
+ bool UseConnectionStr() { return useConnectionStr; }
- const wxChar *GetDescription() { return Description; };
- const wxChar *GetFileType() { return FileType; };
- const wxChar *GetDefaultDir() { return DefaultDir; };
+ const wxChar *GetDescription() { return Description; }
+ const wxChar *GetFileType() { return FileType; }
+ const wxChar *GetDefaultDir() { return DefaultDir; }
- void SetHenv(const HENV henv) { Henv = henv; };
+ 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 SetUid(const wxString &uid) { SetUserID(uid); }
void SetPassword(const wxString &password);
- void SetAuthStr(const wxString &authstr) { SetPassword(authstr); };
+ void SetAuthStr(const wxString &authstr) { SetPassword(authstr); }
void SetConnectionStr(const wxString &connectStr);
- void SetDescription(const wxString &desc) { Description = desc; };
- void SetFileType(const wxString &fileType) { FileType = fileType; };
- void SetDefaultDir(const wxString &defDir) { DefaultDir = defDir; };
+ void SetDescription(const wxString &desc) { Description = desc; }
+ void SetFileType(const wxString &fileType) { FileType = fileType; }
+ void SetDefaultDir(const wxString &defDir) { DefaultDir = defDir; }
}; // class wxDbConnectInf
class WXDLLIMPEXP_ODBC wxDbColFor
{
public:
- wxString s_Field; // Formated String for Output
- wxString s_Format[7]; // Formated Objects - TIMESTAMP has the biggest (7)
- 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
+ wxString s_Field; // Formatted String for Output
+ wxString s_Format[7]; // Formatted Objects - TIMESTAMP has the biggest (7)
+ wxString s_Amount[7]; // Formatted Objects - amount of things that can be formatted
+ int i_Amount[7]; // Formatted Objects - TT MM YYYY HH MM SS m
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
SWORD i_sqlDataType;
dbmsDB2,
dbmsINTERBASE,
dbmsPERVASIVE_SQL,
- dbmsXBASE_SEQUITER
+ dbmsXBASE_SEQUITER,
+ dbmsFIREBIRD,
+ dbmsMAXDB,
+ dbmsFuture1,
+ dbmsFuture2,
+ dbmsFuture3,
+ dbmsFuture4,
+ dbmsFuture5,
+ dbmsFuture6,
+ dbmsFuture7,
+ dbmsFuture8,
+ dbmsFuture9,
+ dbmsFuture10
};
// will overwrite the errors of the previously destroyed wxDb object in
// this variable.
-WXDLLIMPEXP_DATA_ODBC(extern wxChar)
- DBerrorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN];
+extern WXDLLIMPEXP_DATA_ODBC(wxChar)
+ DBerrorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN+1];
class WXDLLIMPEXP_ODBC wxDb
bool getDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo);
bool setConnectionOptions(void);
void logError(const wxString &errMsg, const wxString &SQLState);
- const wxChar *convertUserID(const wxChar *userID, wxString &UserID);
+ void convertUserID(const wxChar *userID, wxString &UserID);
+ bool determineDataTypes(bool failOnDataTypeUnsupported);
void initialize();
bool open(bool failOnDataTypeUnsupported=true);
wxDbSqlTypeInfo typeInfFloat;
wxDbSqlTypeInfo typeInfDate;
wxDbSqlTypeInfo typeInfBlob;
+ wxDbSqlTypeInfo typeInfMemo;
#endif
public:
- void setCached(bool cached) { dbIsCached = cached; }; // This function must only be called by wxDbGetConnection() and wxDbCloseConnections!!!
- bool IsCached() { return dbIsCached; };
+ void setCached(bool cached) { dbIsCached = cached; } // This function must only be called by wxDbGetConnection() and wxDbCloseConnections!!!
+ bool IsCached() { return dbIsCached; }
bool GetDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo)
{ return getDataTypeInfo(fSqlType, structSQLTypeInfo); }
// ODBC Error Inf.
SWORD cbErrorMsg;
int DB_STATUS;
+#ifdef __VMS
+ // The DECC compiler chokes when in db.cpp the array is accessed outside
+ // its bounds. Maybe this change should also applied for other platforms.
+ wxChar errorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN+1];
+#else
wxChar errorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN];
+#endif
wxChar errorMsg[SQL_MAX_MESSAGE_LENGTH];
- SDWORD nativeError;
+ SQLINTEGER nativeError;
wxChar sqlState[20];
#if wxODBC_BACKWARD_COMPATABILITY
// Data Source Name, User ID, Password and whether open should fail on data type not supported
bool Open(const wxString& inConnectStr, bool failOnDataTypeUnsupported=true);
+ ///This version of Open will open the odbc source selection dialog. Cast a wxWindow::GetHandle() to SQLHWND to use.
+ bool Open(const wxString& inConnectStr, SQLHWND parentWnd, bool failOnDataTypeUnsupported=true);
bool Open(const wxString &Dsn, const wxString &Uid, const wxString &AuthStr, bool failOnDataTypeUnsupported=true);
bool Open(wxDbConnectInf *dbConnectInf, bool failOnDataTypeUnsupported=true);
bool Open(wxDb *copyDb); // pointer to a wxDb whose connection info should be copied rather than re-queried
bool CreateView(const wxString &viewName, const wxString &colList, const wxString &pSqlStmt, bool attemptDrop=true);
bool DropView(const wxString &viewName);
bool ExecSql(const wxString &pSqlStmt);
+ bool ExecSql(const wxString &pSqlStmt, wxDbColInf** columns, short& numcols);
bool GetNext(void);
- bool GetData(UWORD colNo, SWORD cType, PTR pData, SDWORD maxLen, SDWORD FAR *cbReturned);
+ bool GetData(UWORD colNo, SWORD cType, PTR pData, SDWORD maxLen, SQLLEN FAR *cbReturned);
bool Grant(int privileges, const wxString &tableName, const wxString &userList = wxT("PUBLIC"));
int TranslateSqlState(const wxString &SQLState);
wxDbInf *GetCatalog(const wxChar *userID=NULL);
wxDbSqlTypeInfo GetTypeInfFloat() {return typeInfFloat;}
wxDbSqlTypeInfo GetTypeInfDate() {return typeInfDate;}
wxDbSqlTypeInfo GetTypeInfBlob() {return typeInfBlob;}
+ wxDbSqlTypeInfo GetTypeInfMemo() {return typeInfMemo;}
// tableName can refer to a table, view, alias or synonym
bool TableExists(const wxString &tableName, const wxChar *userID=NULL,
bool FwdOnlyCursors(void) {return fwdOnlyCursors;}
+ // return the string with all special SQL characters escaped
+ wxString EscapeSqlChars(const wxString& value);
+
// These two functions are provided strictly for use by wxDbTable.
// DO NOT USE THESE FUNCTIONS, OR MEMORY LEAKS MAY OCCUR
void incrementTableCount() { nTables++; return; }
// Change this to 0 to remove use of all deprecated functions
#if wxODBC_BACKWARD_COMPATABILITY
//#################################################################################
-//############### DEPRECATED functions for backward compatability #################
+//############### DEPRECATED functions for backward compatibility #################
//#################################################################################
// Backward compability structures/classes. This will eventually go away