Cannot apply change in PostgreSQL from C++

Cannot apply change in PostgreSQL from C++

Postby Carmichael_fr » Mon 14 Jan 2013 20:46

Bonjour,

My configuration :
- Windows 7 SP1
- Embarcadero C++ XE3
- Devart dbExpress for PostgreSQL 3.1.2.0


My projet :
Before buy your product (and pay it!), i would like to test your "dbExpress for Postgres" drivers.

I make a small application in C++ 32 bits.
I would like to show, in a TBDGrid, a table. I want to modify the values in the Grid, and the values must be modified in the Postgresql database.
No warning in the compilation, but when i modify a value in the Grid, the modification is not set in the Database.

Some Details : the projet use some simple componants :
- TSQLConnection1 with the propertie : Driver = DevartPostgreSQL
- TSimpledataSet1 with the propertie : Connection = TSQLConnection1, ReadOnly = false
- TDataSource1 with the propertie : DataSet = TSimpleDataSet1
- TDbGrid1 with the propertie : DataSource = TDataSource1

After any update of in the Grid, i click on a TButton with the code :
SimpleDataSet1->ApplyUpdates(0);

I made the same projet with Oracle, it works well.
Do you have any idea ?
Is ti possible to activate logs in Devart dbExpress for Postgres ?

Best Regards

Carmichael_fr
Carmichael_fr
 
Posts: 4
Joined: Sun 13 Jan 2013 14:19

Re: Cannot apply change in PostgreSQL from C++

Postby AlexP » Tue 15 Jan 2013 09:08

Hello,

The following sample demonstrates updating data using SimpleDataSet in C++Builder. Paste the needed parameters and run this code. After the execution, data must change in the table.

Code: Select all
   TSQLConnection *SQLConnection = new TSQLConnection(NULL);
   try
   {
      SQLConnection->ConnectionName = "Devart PostgreSQL";
      SQLConnection->DriverName = "DevartPostgreSQL";
      SQLConnection->Params->Values["HostName"] = "host:port";
      SQLConnection->Params->Values["DataBase"] = "database";
      SQLConnection->Params->Values["User_Name"] = "login";
      SQLConnection->Params->Values["Password"] = "password";
      SQLConnection->LoginPrompt = False;
      SQLConnection->Connected = True;
      TSimpleDataSet *SimpleDataSet = new TSimpleDataSet(NULL);
      try
      {
         SimpleDataSet->Connection = SQLConnection;
         SimpleDataSet->DataSet->CommandType = ctTable;
         SimpleDataSet->DataSet->CommandText = "table";
         SimpleDataSet->Active = True;
         SimpleDataSet->Edit();
         SimpleDataSet->FieldByName("field")->AsInteger = 1;
         SimpleDataSet->Post();
         SimpleDataSet->ApplyUpdates(0);
      }
      __finally
      {
         SimpleDataSet->Free();
      }
   }
   __finally
   {
      SQLConnection->Free();
   }
AlexP
Devart Team
 
Posts: 5528
Joined: Tue 10 Aug 2010 11:35

Re: Cannot apply change in PostgreSQL from C++

Postby Carmichael_fr » Tue 15 Jan 2013 20:20

Bonjour,

Thanks for your response, your exemple is working.
But my question was a little different.

I would like to use a TBDGrid. I would like to modify my data into the Grid.
In this case, when i modify something in the grid, the modification is not send to the database Postgres.

Today, i add a connection to Oracle in my program.
the structure of the code is :
SQLConnectionPostgres -> SimpleDataSetPostgres -> DataSourcePostgres -> TDBGridPostgres and
SQLConnectionOracle -> SimpleDataSetOracle -> DataSourceOracle -> TDBGridOracle

Surprise ! It's working with Oracle, but not with Postgres.

The full text of the code is :
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "FenPrincipale.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "DbxDevartPostgreSQL"
#pragma link "DBXDevartOracle"
#pragma resource "*.dfm"
TFenetrePrincipale *FenetrePrincipale;
//---------------------------------------------------------------------------
__fastcall TFenetrePrincipale::TFenetrePrincipale(TComponent* Owner): TForm(Owner)
{

}

void __fastcall TFenetrePrincipale::QuitterClick(TObject *Sender)
{ // Just before exit to windows.
SimpleDataSetPostgres->Free();
SimpleDataSetOracle->Free();
ConnexionPostgres->Free();
ConnexionOracle->Free();
Close();

}
//---------------------------------------------------------------------------

void __fastcall TFenetrePrincipale::CommitPostgresClick(TObject *Sender)
{ // When i click on the Commit Postgres Button.
SimpleDataSetPostgres->Post();
SimpleDataSetPostgres->ApplyUpdates(0);
}
//---------------------------------------------------------------------------

void __fastcall TFenetrePrincipale::CommitOracleClick(TObject *Sender)
{// When i click on the Commit Oracle Button.
SimpleDataSetOracle->Post();
SimpleDataSetOracle->ApplyUpdates(0);
}
//---------------------------------------------------------------------------

May i suggest a little bug in the driver ?

Best regards
Carmichael_fr
Carmichael_fr
 
Posts: 4
Joined: Sun 13 Jan 2013 14:19

Re: Cannot apply change in PostgreSQL from C++

Postby AlexP » Wed 16 Jan 2013 09:17

Hello,

Please send your sample demonstrating the problem to alexp*devart*com, since we still cannot reproduce the problem even using your code.
AlexP
Devart Team
 
Posts: 5528
Joined: Tue 10 Aug 2010 11:35

Re: Cannot apply change in PostgreSQL from C++

Postby AlexP » Thu 17 Jan 2013 13:46

Hello,

I received your project, but the problem still cannot be reproduced even on it on the similar configuration (Win 7, PG 9.1 x64, XE 3, dbExpress Driver For PostgreSQL 3.1.2). Perhaps, a trigger is created for the edited table and doesn't allow data editing, or there is a limitation, etc.
AlexP
Devart Team
 
Posts: 5528
Joined: Tue 10 Aug 2010 11:35


Return to dbExpress driver for PostgreSQL