Ticket #8575: update_sequence.patch
| File update_sequence.patch, 2.4 KB (added by bobbysmith007@…, 2 months ago) |
|---|
-
trac/db/sqlite_backend.py
315 315 316 316 def get_last_id(self, cursor, table, column='id'): 317 317 return cursor.lastrowid 318 319 def update_sequence(self, cursor, table, column='id'): 320 # sqlite handles sequence updates automagically 321 # http://www.sqlite.org/autoinc.html 322 pass -
trac/db/tests/api.py
320 320 id2 = self.db.get_last_id(c, 'report') 321 321 self.assertEqual(id1 + 1, id2) 322 322 323 def test_update_sequence(self): 324 c = self.db.cursor() 325 q = "INSERT INTO report (id, author) VALUES (42, 'anonymous')" 326 c.execute(q) 327 self.db.update_sequence(c, "report") 328 id1 = self.db.get_last_id(c, 'report') 329 self.assertEqual(id1, 42) 323 330 331 332 324 333 def suite(): 325 334 suite = unittest.TestSuite() 326 335 suite.addTest(unittest.makeSuite(ParseConnectionStringTestCase, 'test')) -
trac/db/mysql_backend.py
253 253 def get_last_id(self, cursor, table, column='id'): 254 254 return cursor.lastrowid 255 255 256 def update_sequence(self, cursor, table, column='id'): 257 # mysql handles this automagically, verified in 258 # mysql Ver 14.14 Distrib 5.1.41, for debian-linux-gnu (x86_64) 259 # using readline 6.1 260 pass 261 256 262 def rollback(self): 257 263 self.cnx.ping() 258 264 try: -
trac/db/postgres_backend.py
235 235 cursor.execute("SELECT CURRVAL('%s_%s_seq')" % (table, column)) 236 236 return cursor.fetchone()[0] 237 237 238 def update_sequence(self, cursor, table, column='id'): 239 sql = "SELECT setval('%s_%s_seq', (SELECT MAX(id) FROM %s))" % \ 240 (table, column, table) 241 cursor.execute(sql) 242 238 243 def cursor(self): 239 244 return IterableCursor(self.cnx.cursor(), self.log) 240 245
