I think you may be assuming that Pgdb is using autocommit. If you visit https://fisheye.springframework.org/...ringpythontest, and then visit both databaseCoreTestCases.py, and databaseTransactionTestCases.py, you should find some samples of working code. If you scroll down a bit in the first file, you will notice a block like this:
Code:
class AbstractDatabaseTemplateTestCase(unittest.TestCase):
def __init__(self, methodName='runTest'):
unittest.TestCase.__init__(self, methodName)
self.factory = None
self.createdTables = False
def setUp(self):
if not self.createdTables:
self.createTables()
self.databaseTemplate = DatabaseTemplate(self.factory)
self.databaseTemplate.execute("DELETE FROM animal")
self.factory.commit()
self.assertEquals(len(self.databaseTemplate.query_for_list("SELECT * FROM animal")), 0)
self.databaseTemplate.execute("INSERT INTO animal (name, category, population) VALUES ('snake', 'reptile', 1)")
self.databaseTemplate.execute("INSERT INTO animal (name, category, population) VALUES ('racoon', 'mammal', 0)")
self.databaseTemplate.execute ("INSERT INTO animal (name, category, population) VALUES ('black mamba', 'kill_bill_viper', 1)")
self.databaseTemplate.execute ("INSERT INTO animal (name, category, population) VALUES ('cottonmouth', 'kill_bill_viper', 1)")
self.factory.commit()
self.assertEquals(len(self.databaseTemplate.query_for_list("SELECT * FROM animal")), 4)
If you embed a factory.commit() operation, does it start working? factory should be handle on your PgdbConnectionFactory. NOTE: Several of the test cases show it inserting rows and then immediately query, to test the results. This works even if commits are required as long as your are using the same connection. If you try to examine the same data from another connection or if this connection factory had been some pooled solution, then you wouldn't see the inserted data, until it is committed.
Why does MySQL work? I believe there are two types of tables supported in MySQL. One of them actually does NOT support transactions, so every insert is an automatic commit, without you having to do it yourself.
- MyISAM — The default MySQL storage engine and the one that is used the most in Web, data warehousing, and other application environments. MyISAM is supported in all MySQL configurations, and is the default storage engine unless you have configured MySQL to use a different one by default.
- InnoDB — Used for transaction processing applications, and sports a number of features including ACID transaction support and foreign keys. InnoDB is included by default in all MySQL 5.1 binary distributions. In source distributions, you can enable or disable either engine by configuring MySQL as you like.
This list was plucked from MySQL's documentation, and shows the MyISAM is the default, which doesn't support transactions. For testing purposes, I have my test code deliberately using innodb, to confirm Spring Python handles transactions for MySQL, Sqlite, and PostGreSQL.