wxODBC: problems, and a doc bug

Ben Discoe ben at vterrain.org
Tue Aug 14 15:51:14 PDT 2007


I tried using wxODBC today for the first time (wxMSW 2.8.3), to read an Access .mdb file.  It's working, but not without some problems.

1. The function wxDbGetConnection() has a major flaw.  When it calls wxDB::Open(), on line 4215 of db.cpp, it allows the fourth argument to be default:
	failOnDataTypeUnsupported=true

However, wxODBC will _often_ fail on an unsupported datatype.  The shaky function is wxDb::determineDataTypes().  It fails with the Access driver on the MEMO type which fails to map to SQL_LONGVARCHAR.  This is a bad default behavior, since this failure prevents any connection from opening, even if it will not use the MEMO type.

It's also bad that the details of this error are not reported; it took me an hour of stepping with the debugger to find out _why_ wxDbGetConnection failed.

Possible improvements would be:
  A. Make the default value in wxDB::Open(failOnDataTypeUnsupported=false).
  B. Expose failOnDataTypeUnsupported in wxDbGetConnection so that the user can decide themselves.

2. In the wx documentation, in 'Database classes overview', the following code example is given:

   if (DbConnectInf.AllocHenv())
   {
      wxMessageBox("Unable to allocate an ODBC environment handle",
                   "DB CONNECTION ERROR", wxOK | wxICON_EXCLAMATION);
      return;
   }

This is exactly wrong.  AllocHenv returns true on success.  Correct code would be:

   if (DbConnectInf.AllocHenv() == false)
   {
      wxMessageBox(_T("Unable to allocate an ODBC environment handle"),
                   _T("DB CONNECTION ERROR"), wxOK | wxICON_EXCLAMATION);
      return;
   }

-Ben






More information about the wx-users mailing list