Page 1 of 1

Firebird

Posted: Fri Jul 19, 2013 7:46 am
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);
}

Re: Firebird

Posted: Fri Jul 19, 2013 7:51 am
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.

Re: Firebird

Posted: Fri Jul 19, 2013 8:41 am
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

Re: Firebird

Posted: Fri Jul 19, 2013 9:33 am
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.

Re: Firebird

Posted: Fri Jul 19, 2013 10:19 am
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

Re: Firebird

Posted: Wed Dec 18, 2013 7:40 pm
by extreme001
And don't forget the commit!