Opened 16 years ago

Closed 9 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 16 years ago.
pg header
ogrpgdatasource.cpp (48.2 KB ) - added by bishop 16 years ago.
ogrpgdatasource
ogrpgtablelayer.cpp (70.6 KB ) - added by bishop 16 years ago.
ogrpgtablelayer
export_transaction_functions_from_dll_#2556.patch (2.2 KB ) - added by bishop 15 years ago.
SetEncoding & exoprts some functions

Download all attachments as: .zip

Change History (18)

by bishop, 16 years ago

Attachment: ogr_pg.h added

pg header

by bishop, 16 years ago

Attachment: ogrpgdatasource.cpp added

ogrpgdatasource

by bishop, 16 years ago

Attachment: ogrpgtablelayer.cpp added

ogrpgtablelayer

comment:1 by Even Rouault, 16 years ago

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 by bishop, 16 years ago

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

in reply to:  2 comment:3 by bishop, 16 years ago

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 by Even Rouault, 16 years ago

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 by bishop, 16 years ago

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

comment:6 by bishop, 16 years ago

Version: 1.5.2svn-trunk

comment:7 by Even Rouault, 16 years ago

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

comment:8 by bishop, 16 years ago

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

by bishop, 15 years ago

SetEncoding & exoprts some functions

comment:9 by bishop, 15 years ago

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 by Even Rouault, 15 years ago

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 by bishop, 15 years ago

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 by bishop, 15 years ago

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 by Even Rouault, 15 years ago

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 by Jukka Rahkonen, 9 years ago

Resolution: fixed
Status: newclosed

Fixed 5 years ago.

Note: See TracTickets for help on using tickets.