I have a Sqlite3 database with 3 rows. The [select * from contacts] Query with Results seems to return nothing - steps through the while() only once not finding the data I seek.
Code: Select all
void DbConfigDialog::OnbtnTestOnlyClick(wxCommandEvent& event)
{
DatabaseLayer* pMyDatabase = new SqliteDatabaseLayer(_("/home/jim/test.db"));
int nRows = -1;
DatabaseResultSet* pResultSet = pMyDatabase->RunQueryWithResults(_("SELECT COUNT(*) FROM contacts"));
if ( pResultSet )
{
if ( pResultSet->Next() )
{
nRows = pResultSet->GetResultInt(1);
}
pMyDatabase->CloseResultSet(pResultSet);
}
wxString strfname = (_("DUMMY"));
DatabaseResultSet* pResults = pMyDatabase->RunQueryWithResults(_("SELECT * FROM contacts"));
if (pResults)
{
while (pResults->Next());
{
strfname = pResults->GetResultString(2);
wxLogMessage(wxString::Format(_T("firstname is: %s"), strfname.c_str()));
}
pMyDatabase->CloseResultSet(pResults);
}
else
{
wxMessageBox(_("Results Error"));
}
pMyDatabase->Close();
}
I tried GetResultString(_("fname")) and changed it to the field number (base 1) because I see no method to accept the field name in the DatabaseLayer documentation. This change had no affect.
Can I access fields via name? Using the field name compiled Ok, implying there is a method that accepts strings, vice integer field number. But that does not explain why I don't step through the result set three times - so there I have a bigger problem not filling the result set.
I am using Code::Blocks SVN-5489 (wx2.8.8) on Linux, if that matters. DatabaseLayer is as of March 2009.
The library in use is the Sqlite-2.8.so file and The header files in use are:
Code: Select all
#include "wx_pch.h"
#include "DbConfigDialog.h"
#include <wx/log.h>
//(* DatabaseLayer related header files
#include "/usr/include/wx-2.8/wx/databaselayer/DatabaseLayer.h"
#include "/usr/include/wx-2.8/wx/databaselayer/SqliteDatabaseLayer.h"
#include "/usr/include/wx-2.8/wx/databaselayer/DatabaseErrorCodes.h"
#include "/usr/include/wx-2.8/wx/databaselayer/DatabaseLayerException.h"
#include "/usr/include/wx-2.8/wx/databaselayer/ResultSetMetaData.h"
//*)
#ifndef WX_PRECOMP
//(*InternalHeadersPCH(DbConfigDialog)
//*)
#endif
//(*InternalHeaders(DbConfigDialog)
#include <wx/xrc/xmlres.h>
//*)
One other question I have is how to view string value in a debug watch. I set a watch on "strfname" but I get wxString and what I presume is a memory address, not the value of the string - is there a way to see the value of the string in the Code::Blocks debug watch window?