Firebird Topic is solved

In this forum you can discuss database related issues which can be wxWidgets related, but also generic in nature.
Post Reply
RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Firebird

Post by RobertHK »

Hi, I need help please. In wxWidgets I have a copy of the client file. Administration's original (for example DBA.FDB), ie creating tables, triggers and generators created in FlameRobin. A copy is of the employment application (file). The data in each field in the base frame with the wxTextCtrl I put. These later exported to my file. Data are entered OK (Validation Report). But the data on the server (verified FlameRobin) show all fields symbols T. Does anyone know please where I'm wrong? Here is the complete function in question:

void BaseFrame::OnCommit(wxCommandEvent& WXUNUSED(event))
{
if(false == IBPP::CheckVersion(IBPP::Version))
{
wxString verze = wxT("Tento program nemá dobrou verzi knihovny");
wxLogMessage( wxT("Aha!: %s"), verze);
}

///
wxString investor = m_textCtrl1->GetValue();
wxString objednatel = m_textCtrl2->GetValue();
wxString stavba = m_textCtrl3->GetValue();
wxString akce = m_textCtrl4->GetValue();
wxString vypracoval = m_textCtrl5->GetValue();
wxString obj_cislo = m_textCtrl6->GetValue();
wxString zak_cislo = m_textCtrl7->GetValue();
wxString datum = m_textCtrl8->GetValue();
wxString mena = m_textCtrl9->GetValue();

///
try
{

wxString dbName1 = targetFilename; // copy from Newfile -- working OK
IBPP::Database db = DatabaseFactory(wx2std(ServerName), wx2std(dbName1), wx2std(UserName),
wx2std(Password), "", "UTF8", "Page_size 4096 DEFAULT CHARACTER SET UTF8");

db->Connect();
IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite,
IBPP::ilConcurrency,IBPP::lrWait);
tr->Start();
IBPP::Statement st = IBPP::StatementFactory(db, tr);

st->Prepare("INSERT INTO ZAKAZKA (zak_cislo, investor, objednatel, stavba, akce, vypracoval, obj_cislo, datum, mena)"
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");

st->Set(1, zak_cislo.wchar_str());
st->Set(2, investor.wchar_str());
st->Set(3, objednatel.wchar_str());
st->Set(4, stavba.wchar_str());
st->Set(5, akce.wchar_str());
st->Set(6, vypracoval.wchar_str());
st->Set(7, obj_cislo.wchar_str());
st->Set(8, datum.wchar_str());
st->Set(9, mena.wchar_str());
tr->CommitRetain();

try
{
st->Execute();
}
catch (IBPP::SQLException &rExcept)
{
if (-803 == rExcept.SqlCode())
{
wxString zprava1 = wxT("OK!");
wxLogMessage( wxT("Zpráva: %s"), zprava1);
}
else
{
throw;
}
}
tr->CommitRetain();
st->Close();
db->Disconnect();

wxLogMessage( wxT("Investor : %s"), investor);
wxLogMessage( wxT("Objednatel : %s"), objednatel);
wxLogMessage( wxT("Stavba : %s"), stavba);
wxLogMessage( wxT("Akce : %s"), akce);
wxLogMessage( wxT("Vypracoval : %s"), vypracoval);
wxLogMessage( wxT("Obj. číslo : %s"), obj_cislo);
wxLogMessage( wxT("Číslo zakázky: %s"), zak_cislo);
wxLogMessage( wxT("Datum: %s"), datum);
wxLogMessage( wxT("Mena: %s"), mena);
//------------------------------------
}
catch(IBPP::Exception& e)
{
wxString zprava2 = wxT("bad!");
wxLogMessage( wxT("Oj: %s"), zprava2);
}
wxLogMessage( wxT("Complette: %s"), targetFilename); // targetFilename is copy from fc NewFile, working OK
}
User avatar
doublemax
Moderator
Moderator
Posts: 19102
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Firebird

Post by doublemax »

I don't know IBPP, but as a saw a ""UTF8" in the DatabaseFactory ctor, i assume that it expects string data as uft8.

Try to replace this:

Code: Select all

st->Set(1, zak_cislo.wchar_str());
with this:

Code: Select all

st->Set(1, zak_cislo.ToUTF8());
(And the same for the other variables).
Use the source, Luke!
RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: Firebird

Post by RobertHK »

Yes, yes, yes! That was exactly it. It works perfectly (on the 1st attempt), thanks very much.
RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: Firebird

Post by RobertHK »

Hi, I need help again please. When loading from the server to wxTextCtr boxes are displayed garbage characters (not displayed correctly national characters in Czech / Slovak). I've tried everything. Me used functions wx2std / std2wx the conversion function std :: string / wxString and vice versa. Poorly also shows the (nonsense) in wxLogMessage. Does anyone know how to do it please? Here is my code:

void BaseFrame::OnOpenFile(wxCommandEvent& WXUNUSED(event))
{

wxString caption = wxT("Vyberte rozpočet");
wxString wildcard = wxT("Rozpočet FDB (*.fdb)|*.fdb");

wxString defaultDir = wxT("c:\\temp");
wxString openFilename = wxEmptyString;

wxFileDialog * openFileDialog = new wxFileDialog(this, caption, defaultDir, openFilename,
wildcard, wxFD_OPEN);
if (openFileDialog->ShowModal() == wxID_OK)
{
openFilename = openFileDialog->GetPath();

if(false == IBPP::CheckVersion(IBPP::Version))
{
wxString verze = wxT("Tento program nemá dobrou verzi knihovny");
wxLogMessage( wxT("Aha!: %s"), verze);
}
}

try
{

wxString dbName2 = openFilename;
IBPP::Database db = DatabaseFactory(wx2std(ServerName), wx2std(dbName2), wx2std(UserName),
wx2std(Password), "", "UTF8", "Page_size 4096 DEFAULT CHARACTER SET UTF8");

db->Connect();
IBPP::Transaction tr10 = IBPP::TransactionFactory(db); //, IBPP::amWrite,
//IBPP::ilConcurrency,IBPP::lrWait);
tr10->Start();
IBPP::Statement st10 = IBPP::StatementFactory(db, tr10);

st10->Prepare("SELECT zak_cislo, investor, objednatel, stavba, akce, vypracoval, obj_cislo, datum, mena FROM ZAKAZKA");
st10->Execute();

std::string investor;
std::string objednatel;
std::string stavba;
std::string akce;
std::string vypracoval;
std::string obj_cislo;
std::string zak_cislo;
std::string datum;
std::string mena;

while(true == st10->Fetch())
{
st10->Get(1, zak_cislo);
st10->Get(2, investor);
st10->Get(3, objednatel);
st10->Get(4, stavba);
st10->Get(5, akce);
st10->Get(6, vypracoval);
st10->Get(7, obj_cislo);
st10->Get(8, datum);
st10->Get(9, mena);

wxString inv = std2wx(investor);
wxString obj = std2wx(objednatel);
wxString stav = std2wx(stavba);
wxString acce = std2wx(akce);
wxString vypr = std2wx(vypracoval);
wxString c_obj = std2wx(obj_cislo);
wxString c_zak = std2wx(zak_cislo);
wxString dtm = std2wx(datum);
wxString many = std2wx(mena);

this->m_textCtrl1->SetValue(inv);
this->m_textCtrl2->SetValue(obj);
this->m_textCtrl3->SetValue(stav);
this->m_textCtrl4->SetValue(acce);
this->m_textCtrl5->SetValue(vypr);
this->m_textCtrl6->SetValue(c_obj);
this->m_textCtrl7->SetValue(c_zak);
this->m_textCtrl8->SetValue(dtm);
this->m_textCtrl9->SetValue(many);

}
st10->Close();
db->Disconnect();

wxLogMessage( wxT("Investor : %s"), investor);
wxLogMessage( wxT("Objednatel : %s"), objednatel);
wxLogMessage( wxT("Stavba : %s"), stavba);
wxLogMessage( wxT("Akce : %s"), akce);
wxLogMessage( wxT("Vypracoval : %s"), vypracoval);
wxLogMessage( wxT("Obj. číslo : %s"), obj_cislo);
wxLogMessage( wxT("Číslo zakázky: %s"), zak_cislo);
wxLogMessage( wxT("Datum: %s"), datum);
wxLogMessage( wxT("Mena: %s"), mena);

}
catch(IBPP::Exception& e)
{
wxString zprava = wxT("špatný výstup!");
wxLogMessage( wxT("Ach jaj: %s"), zprava);
}
wxLogMessage( wxT("Výstup: %s"), openFilename);
}
User avatar
doublemax
Moderator
Moderator
Posts: 19102
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Firebird

Post by doublemax »

Code: Select all

wxString inv = std2wx(investor);
Try this:

Code: Select all

wxString inv(investor, wxConvUTF8)
Use the source, Luke!
RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: Firebird

Post by RobertHK »

So unfortunately, it reports errors:

error: no matching function for call to 'wxString::wxString(std::string&, wxMBConvStrictUTF8&)'|

note: candidates are:
D:\wxWidgets-2.9.4\include\wx\string.h|2494|note: wxString::wxString(const wxCStrData&, const wxCStrData&)|
D:\wxWidgets-2.9.4\include\wx\string.h|2494|note: no known conversion for argument 1 from 'std::string {aka std::basic_string<char>}' to 'const wxCStrData&'|
D:\wxWidgets-2.9.4\include\wx\string.h|2488|note: wxString::wxString(const wchar_t*, const wchar_t*)|
RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: Firebird

Post by RobertHK »

Here, the debugger C::B stops (wx/string.h):
2494 wxString(const wxCStrData& first, const wxCStrData& last)
2495 : m_impl(CreateConstIterator(first).impl(),
2496 CreateConstIterator(last).impl())
User avatar
doublemax
Moderator
Moderator
Posts: 19102
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Firebird

Post by doublemax »

Try:

Code: Select all

wxString inv( (const char *)investor, wxConvUTF8);
or
wxString inv( investor.c_str(), wxConvUTF8);
Use the source, Luke!
RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: Firebird

Post by RobertHK »

So, unfortunately, does not work either. First variant (wxString inv ((const char *) investor, wxConvUTF8) gives an error when compiling. 2nd option (wxString inv( investor.c_str(), wxConvUTF8);) compiles without errors, but the resulting wxTextCtrl (and logs) are empty - no effect. #-o
User avatar
doublemax
Moderator
Moderator
Posts: 19102
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Firebird

Post by doublemax »

Very strange. Does the initial variable "investor" (or the others) really contain something? Try to find out if it really contains UTF8 encoded text. Maybe they're using a different encoding there.
Use the source, Luke!
RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: Firebird

Post by RobertHK »

But no. In the build and release (build options) I have set (C :: B - Compiler Flags/ Other options/ -> here: # define tab)
__GNUWIN32__
__WXMSW__
wxUSE_UNICODE
User avatar
doublemax
Moderator
Moderator
Posts: 19102
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Firebird

Post by doublemax »

That's not important. The question is which encoding IBPP uses when filling the strings in the st10->Get() call.
Use the source, Luke!
RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: Firebird

Post by RobertHK »

I understand. IBPP provides the following (among others) virtual constructors. I mention only those which are listed with std :: string:

655 virtual bool Get (int, std :: string &) = 0;
671 virtual bool Get (const std :: string &, std :: string &) = 0;

I know that. that someone (from France) wrote ibpp.h code for use TCHAR...
User avatar
doublemax
Moderator
Moderator
Posts: 19102
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Firebird

Post by doublemax »

I know that std::string is a 8bit container. But they are "stupid" in the sense that they don't care what kind of data you put into them. E.g. they could contain UTF8 or ISO8859-1 encoded 8bit data.

As UTF8 worked to fill the database, it should be very likely that it also returns string data in that encoding.

You have to:
a) confirm that the returned std::string contains anything at all
b) if they are not empty, read out their content byte-by-byte to find out what encoding they contain
Use the source, Luke!
RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: Firebird

Post by RobertHK »

Hi, good day. Yes, it works. Method ST10-> Get (2,investor) retrieves from the server to std :: string data, but as gibberish. This gibberish is displayed as in wxLogMessage and in wxTextCtrl (which I understand are raw data std :: string). Now just to determine the appropriate method for transfer to wxString. Method, which I took from FlameRobin (std2wx) also shows gibberish.
******
Now I did it! It is interesting that when i you formulate questions for this forum, sometimes I think of a solution. That's why I love this forum!! So, it is correct as follows:
...
std::string investor;
...
st10->Get(2, investor);
....
wxString inv(investor.c_str(), wxConvUTF8);
...
this->m_textCtrl1->ChangeValue(inv);
...
wxLogMessage( wxT("Investor : %s"), inv);

And everything works very OK. Once again Doublemax, thanks very much. :D =D>
Post Reply