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);
}
Firebird Topic is solved
Re: Firebird
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.
With the current code, you're only using the last value of "i" for writing the data into the database.
Use the source, Luke!
Re: Firebird
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 ...
Re: Firebird
I think your code shoud look like this:
I omitted the try/catch stuff to keep it short.
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();
}
Use the source, Luke!
Re: Firebird
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
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
-
- I live to help wx-kind
- Posts: 192
- Joined: Fri Dec 22, 2006 9:17 am
- Location: Germany
- Contact:
Re: Firebird
And don't forget the commit!