Opened 12 years ago

Closed 6 years ago

#2556 closed enhancement (fixed)

Set encoding, start/stop/rollback transaction (PG driver)

Reported by: bishop Owned by: warmerdam
Priority: normal Milestone:
Component: OGR_SF Version: svn-trunk
Severity: normal Keywords: OGR PG
Cc:

Description

  1. Add function SetEncoding?
  2. Make functions (SoftStartTransaction?, SoftCommit?, SoftRollback?) exported from dll

Attachments (4)

ogr_pg.h (10.8 KB) - added by bishop 12 years ago.
pg header
ogrpgdatasource.cpp (48.2 KB) - added by bishop 12 years ago.
ogrpgdatasource
ogrpgtablelayer.cpp (70.6 KB) - added by bishop 12 years ago.
ogrpgtablelayer
export_transaction_functions_from_dll_#2556.patch (2.2 KB) - added by bishop 11 years ago.
SetEncoding? & exoprts some functions

Download all attachments as: .zip

Change History (18)

Changed 12 years ago by bishop

Attachment: ogr_pg.h added

pg header

Changed 12 years ago by bishop

Attachment: ogrpgdatasource.cpp added

ogrpgdatasource

Changed 12 years ago by bishop

Attachment: ogrpgtablelayer.cpp added

ogrpgtablelayer

comment:1 Changed 12 years ago by Even Rouault

Please attach patches to existing files instead of full files.

And please make those patches against GDAL SVN trunk for new features, which resides at http://svn.osgeo.org/gdal/trunk/gdal (http://trac.osgeo.org/gdal/browser)

comment:2 Changed 12 years ago by bishop

Summary: Set encoding, start/stop/rollback transactionSet encoding, start/stop/rollback transaction (PG driver)

comment:3 in reply to:  2 Changed 12 years ago by bishop

Replying to bishop: Sorry, but I'm a newbie, so can you provide some instructions, to do it, or point me of some kind of faq.

comment:4 Changed 12 years ago by Even Rouault

Assuming that you're somehow familiar with subversion, otherwise please read a user manual of it or some tutorial

  1. Checkout the trunk repository with :

svn checkout http://svn.osgeo.org/gdal/trunk/gdal (or with any graphical interface that exists)

  1. Apply your changes; Build; Test
  2. svn diff > name_of_the_patch.patch

As Frank says try to isolate each functionnal change to make a separate patch.

comment:5 Changed 12 years ago by bishop

According to new option "PGCLIENTENCODING" this ticket can be closed.

comment:6 Changed 12 years ago by bishop

Version: 1.5.2svn-trunk

comment:7 Changed 12 years ago by Even Rouault

Why is it necessary to export the transaction functions at the OGRPGDataSource level ? They are already exposed at the OGRLayer level.

comment:8 Changed 12 years ago by bishop

There is necessary to make some changes in several tables (layers) and if some change return error to roll back all operations. This is very important in related tables too

Changed 11 years ago by bishop

SetEncoding? & exoprts some functions

comment:9 Changed 11 years ago by bishop

I updated patch to current svn tranc. I also want to note that using PGCLIENTENCODING environment variable is not a good way. Because SetEncoding? method returns OGRErr and log some info. So developer can manage this situation in program logic.

comment:10 Changed 11 years ago by Even Rouault

Adding new exported method is not a good solution as it implies people to use C++ and depend on the non-installed private headers of the driver.

1) OGRPGDataSource::SetEncoding?(const char* Encoding) is probably unnecessary. You can call poDS->ExecuteSQL("SET client_encoding TO blahblah") and install before an error handler with CPLPushErrorHandler() to track any error issued by the server.

2) Exporting SoftStartTransaction?(), SoftCommit?(), SoftRollback?() and FlushSoftTransaction?() is probably not a good solution either. It would be more interesting if could provide a small Python script or C/C++ code that demonstrates the problems that lead you to call them explicitely. This way perhaps we could perhaps make the driver more clever to call itself those functions when it's needed, without requiring the user to mess with that.

comment:11 Changed 11 years ago by bishop

1) I tested poDS->ExecuteSQL("SET client_encoding TO blahblah") - it's works 2) As I wrote I need make changes in several tables and if it will be some errors to Rollback all changes For example:

void CreateDoubleFeatures()
{
	OGRLayer* pLayer1 = m_pOGRPGDataSource->GetLayerByName("layer1");
	if(pLayer1 == NULL)
		return;
	OGRLayer* pLayer2 = m_pOGRPGDataSource->GetLayerByName("pLayer2");
	if(pLayer2 == NULL)
		return;

	//start transactions
	m_pOGRPGDataSource->SoftStartTransaction();
	
	OGRFeature *pFeature1 = OGRFeature::CreateFeature( pLayer1->GetLayerDefn() );

	pFeature1->SetField("someid", 0);
	pFeature1->SetField("sometext", "some text");

	if( pFeature1->CreateFeature( pFeature1 ) != OGRERR_NONE )
	{
		m_pOGRPGDataSource->SoftRollback();
		return;
	}
	OGRFeature::DestroyFeature( pFeature1 );

	OGRFeature *pFeature2 = OGRFeature::CreateFeature( pLayer2->GetLayerDefn() );

	pFeature2->SetField("somedata", 1.1);
	pFeature1->SetField("sometext", "over some text");

	if( pFeature2->CreateFeature( pFeature2 ) != OGRERR_NONE )
	{
		m_pOGRPGDataSource->SoftRollback();
		return;
	}
	OGRFeature::DestroyFeature( pFeature2 );
	
	//stop transactions
	m_pOGRPGDataSource->SoftCommit();
}

comment:12 Changed 11 years ago by bishop

It's make sense to change PG driver documentation to explain the way to set encoding

CPLPushErrorHandler(); poDS->ExecuteSQL("SET client_encoding TO blahblah"); CPLPopErrorHandler();

comment:13 Changed 11 years ago by Even Rouault

r17603 /trunk/gdal/ogr/ogrsf_frmts/pg/drv_pg.html: PG driver : document how to set client_encoding with a SQL request instead of environmenet variable (#2556)

comment:14 Changed 6 years ago by Jukka Rahkonen

Resolution: fixed
Status: newclosed

Fixed 5 years ago.

Note: See TracTickets for help on using tickets.