WXDB or DATABASELAYER Help  [SOLVED]

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
JPlaroche
Earned some good credits
Earned some good credits
Posts: 131
Joined: Fri Dec 09, 2005 4:58 pm
Contact:

WXDB or DATABASELAYER Help

Postby JPlaroche » Sat Jun 10, 2006 3:30 pm

bonjour,

Je suis sur un descripteur (comme DSPFFD AS400 display File Field Despcrition) avec sqlite
mon r
apprendre et developper en C++ des sub routine interfac� HIM et BD pour validation acquis
Jean-Pierre

project define DB descripteur idem IBM400
http://www.ombrebleu.com/wxsrc/src/

jb_coder
Super wx Problem Solver
Super wx Problem Solver
Posts: 267
Joined: Mon Oct 18, 2004 10:55 am

  [SOLVED]

Postby jb_coder » Sun Jun 11, 2006 3:04 am

wxDB uses ODBC to talk to the database, so you will need to use the SQLite ODBC driver if you go with wxDB. For SQLite it's most likely easier to go with wxSQLite3 or DatabaseLayer.

wxSQLite3 provides access to most (if not all) of SQLite's API. Here's a snippet from the sample (http://wxcode.cvs.sourceforge.net/wxcode/wxCode/components/wxsqlite3/samples/minimal.cpp?revision=1.4&view=markup):

Code: Select all

try
{
  wxSQLite3Database db;
  db.Open(_T("test.db"));
  wxSQLite3ResultSet q1 = db.ExecuteQuery("select empname from emp order by 1;");
  while (q1.NextRow())
  {
    cout << (const char*)(q1.GetString(0).mb_str()) << endl;
  }
}
catch (wxSQLite3Exception& e)
{
  cerr << e.GetErrorCode() << ":" << e.GetMessage().mb_str() << endl;
}



DatabaseLayer was written to hide the database details so it doesn't provide access to the SQLite3 API. Here's a snippet from the functionality summary page (http://wxcode.sourceforge.net/docs/databaselayer/summary.html):

Code: Select all

DatabaseLayer* pDatabase = NULL;
try
{
  pDatabase = new SqliteDatabaseLayer(_("mydb.db"));
  DatabaseResultSet* pResults = pDatabaseLayer->RunQueryWithResults(_("SELECT * FROM table1"));
  if (pResults)
  {
    while (pResults->Next())
    {
      wxString strOne = pResults->GetResultString(_("column1"));
    }
    pDatabase->CloseResultSet(pResults);
  }
}
 catch (DatabaseLayerException& e)
{
  wxLogError(wxString::Format(_("Error (%d): %s"), e.GetErrorCode(), e.GetErrorMessage().c_str()));
}
if (pDatabase)
  delete pDatabase;

JPlaroche
Earned some good credits
Earned some good credits
Posts: 131
Joined: Fri Dec 09, 2005 4:58 pm
Contact:

je vois that gives me an idea

Postby JPlaroche » Mon Jun 12, 2006 9:36 am

I see I understand that gives me an idea of how I go put to take I think to use wxsqlite3 for the definitions

etr wxDB for accesses to the basis of data AS400


I had already taken the orentation and put some places the definitions with wxSlqite3 and you confirmed me one choices

thank-you for message
apprendre et developper en C++ des sub routine interfac� HIM et BD pour validation acquis

Jean-Pierre



project define DB descripteur idem IBM400

http://www.ombrebleu.com/wxsrc/src/

jb_coder
Super wx Problem Solver
Super wx Problem Solver
Posts: 267
Joined: Mon Oct 18, 2004 10:55 am

Postby jb_coder » Tue Jun 13, 2006 10:44 am

I hadn't thought about it earlier, but you could probably get away with one less pointer to deal with in the DatabaseLayer code using the following code:

Code: Select all

try
{
  SqliteDatabaseLayer db(_("mydb.db"));
  DatabaseResultSet* pResults = db.RunQueryWithResults(_("SELECT * FROM table1"));
  if (pResults)
  {
    while (pResults->Next())
    {
      wxString strOne = pResults->GetResultString(_("column1"));
    }
    db.CloseResultSet(pResults);
  }
}
catch (DatabaseLayerException& e)
{
  wxLogError(wxString::Format(_("Error (%d): %s"), e.GetErrorCode(), e.GetErrorMessage().c_str()));
}

(Sorry if this is a little off topic. I just felt the need to clean up that code sample a little.)


Return to “wxCode”

Who is online

Users browsing this forum: No registered users and 3 guests