Firebird  [SOLVED]

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

Firebird

Postby RobertHK » Fri Jul 19, 2013 7:46 am

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 [i] 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[i].dodavatel = m_grid20->GetCellValue(i, 0);
wxLogMessage( wxT("%s"), maT[i].dodavatel);
maT[i].kod_vyrobce = m_grid20->GetCellValue(i, 1);
wxLogMessage( wxT("%s"), maT[i].kod_vyrobce);
maT[i].kategorie = m_grid20->GetCellValue(i, 2);
wxLogMessage( wxT("%s"), maT[i].kategorie );
maT[i].typ = m_grid20->GetCellValue(i, 3);
wxLogMessage( wxT("%s"), maT[i].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[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());
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: 12680
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Firebird

Postby doublemax » Fri Jul 19, 2013 7:51 am

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

Postby RobertHK » Fri Jul 19, 2013 8:41 am

Thanks for the quick reply. I thought that I would need another one cycle. Because when I'm in the method Set () changed [i] 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: 12680
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Firebird

Postby doublemax » Fri Jul 19, 2013 9:33 am

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  [SOLVED]

Postby RobertHK » Fri Jul 19, 2013 10:19 am

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[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());
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

Postby extreme001 » Wed Dec 18, 2013 7:40 pm

And don't forget the commit!


Return to “Database Related”

Who is online

Users browsing this forum: No registered users and 2 guests