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 »

Good day. can not someone please advise me where I'm wrong? For sure, I present the complete function code. In the database I have 1 column ID (from the generator + trigger). If you replace for int x (uncommented) and enter index 'x' in the method Set (), the line is transferred to the database as good. Index 'i' does not work.

void BaseFrame::OnCommitGrid20(wxCommandEvent & WXUNUSED(event))
{
try
{

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

db->Connect();
IBPP::Transaction tr3 = IBPP::TransactionFactory(db, IBPP::amWrite,
IBPP::ilConcurrency,IBPP::lrWait);

tr3->Start();

int i = 0;
int rx = m_grid20->GetGridCursorRow();
mater maT[250];
for (; i <= rx; ++i)
{
maT.dodavatel = m_grid20->GetCellValue(i, 0);
wxLogMessage( wxT("%s"), maT.dodavatel);
maT.kod_vyrobce = m_grid20->GetCellValue(i, 1);
wxLogMessage( wxT("%s"), maT.kod_vyrobce);
maT.kategorie = m_grid20->GetCellValue(i, 2);
wxLogMessage( wxT("%s"), maT.kategorie );
maT.typ = m_grid20->GetCellValue(i, 3);
wxLogMessage( wxT("%s"), maT.typ );
}

// int x = 0;

IBPP::Statement st3 = IBPP::StatementFactory(db, tr3);
st3->Prepare("INSERT INTO material (dodavatel, kod_vyrobce, kategorie, typ)"
" VALUES (?,?,?,?)");

st3->Set(1, maT.dodavatel.ToUTF8());
st3->Set(2, maT[i].kod_vyrobce.ToUTF8());
st3->Set(3, maT[i].kategorie.ToUTF8());
st3->Set(4, maT[i].typ.ToUTF8());
try
{
st3->Execute();
}
catch (IBPP::SQLException &rExcept)
{
if (-803 == rExcept.SqlCode())
{
wxString zprava1 = wxT("SQL code: -803");
wxLogMessage( wxT("%s"), zprava1);
}
else
{
throw;
}
}

tr3->CommitRetain();
//st3->Close();
//db->Disconnect();

}
catch(IBPP::Exception& e)
{
wxLogError( wxT("SQL exception: %s"), e.ErrorMessage());
}
wxString zprava2 = wxT("data is write");
wxLogMessage( wxT("%s"), zprava2);
}
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Firebird

Post by doublemax »

The call to update the database must be either inside the for(i) loop, or you must have another loop that writes the data into the database.

With the current code, you're only using the last value of "i" for writing the data into the database.
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 »

Thanks for the quick reply. I thought that I would need another one cycle. Because when I'm in the method Set () changed for [x] and uncomment "int x = 0;" (called as 1 or 2 or 3 or any of the loaded table, so that the server wrote this line [x] . So I'm trying to put the next cycle, al anything does not work on me. 'st->Prepare' method - or methods Set () in a loop I can not give (they are bound to trigger a generator) and throws SQL error ... #-o
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Firebird

Post by doublemax »

I think your code shoud look like this:

Code: Select all

IBPP::Statement st3 = IBPP::StatementFactory(db, tr3);
st3->Prepare("INSERT INTO material (dodavatel, kod_vyrobce, kategorie, typ) VALUES (?,?,?,?)");

for (i=0; i <= rx; ++i)
{
  st3->Set(1, maT[i].dodavatel.ToUTF8());
  st3->Set(2, maT[i].kod_vyrobce.ToUTF8());
  st3->Set(3, maT[i].kategorie.ToUTF8());
  st3->Set(4, maT[i].typ.ToUTF8());
  st3->Execute();
}
I omitted the try/catch stuff to keep it short.
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 »

Thanks so much Doublemax! It's working! Only it was necessary to slightly modify the exceptions:

for (i=0; i <= rx; ++i)
{
st3->Set(1, maT.dodavatel.ToUTF8());
st3->Set(2, maT.kod_vyrobce.ToUTF8());
st3->Set(3, maT.kategorie.ToUTF8());
st3->Set(4, maT.typ.ToUTF8());
try
{
st3->Execute();
}
catch (IBPP::SQLException &rExcept)
{
if (-803 == rExcept.SqlCode())
{
wxString zprava1 = wxT("SQL code: -803");
wxLogMessage( wxT("%s"), zprava1);
}
else
{
throw;
}
}

}
tr3->CommitRetain();

Thanks very much =D> :D
extreme001
I live to help wx-kind
I live to help wx-kind
Posts: 192
Joined: Fri Dec 22, 2006 9:17 am
Location: Germany
Contact:

Re: Firebird

Post by extreme001 »

And don't forget the commit!
Post Reply