Page 1 of 1
Cannot apply change in PostgreSQL from C++
Posted: Mon 14 Jan 2013 20:46
by Carmichael_fr
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
Re: Cannot apply change in PostgreSQL from C++
Posted: Tue 15 Jan 2013 09:08
by AlexP
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();
}
Re: Cannot apply change in PostgreSQL from C++
Posted: Tue 15 Jan 2013 20:20
by Carmichael_fr
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
Re: Cannot apply change in PostgreSQL from C++
Posted: Wed 16 Jan 2013 09:17
by AlexP
Hello,
Please send your sample demonstrating the problem to alexp*devart*com, since we still cannot reproduce the problem even using your code.
Re: Cannot apply change in PostgreSQL from C++
Posted: Thu 17 Jan 2013 13:46
by AlexP
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.