comparison roundup/backends/back_sqlite.py @ 5248:198b6e810c67

Use Python-3-compatible 'as' syntax for except statements Many raise statements near these are also fixed. So are two ivorrect file encoding marks ('utf8'->'utf-8').
author Eric S. Raymond <esr@thyrsus.com>
date Thu, 24 Aug 2017 22:21:37 -0400
parents e1e40674a0bc
children 506c7ee9a385
comparison
equal deleted inserted replaced
5247:7f00a47b3559 5248:198b6e810c67
145 145
146 (self.conn, self.cursor) = self.sql_open_connection() 146 (self.conn, self.cursor) = self.sql_open_connection()
147 147
148 try: 148 try:
149 self.load_dbschema() 149 self.load_dbschema()
150 except sqlite.DatabaseError, error: 150 except sqlite.DatabaseError as error:
151 if str(error) != 'no such table: schema': 151 if str(error) != 'no such table: schema':
152 raise 152 raise
153 self.init_dbschema() 153 self.init_dbschema()
154 self.sql('create table schema (schema varchar)') 154 self.sql('create table schema (schema varchar)')
155 self.sql('create table ids (name varchar, num integer)') 155 self.sql('create table ids (name varchar, num integer)')
330 """ Squash any error caused by us already having closed the 330 """ Squash any error caused by us already having closed the
331 connection. 331 connection.
332 """ 332 """
333 try: 333 try:
334 self.conn.close() 334 self.conn.close()
335 except sqlite.ProgrammingError, value: 335 except sqlite.ProgrammingError as value:
336 if str(value) != 'close failed - Connection is closed.': 336 if str(value) != 'close failed - Connection is closed.':
337 raise 337 raise
338 338
339 def sql_rollback(self): 339 def sql_rollback(self):
340 """ Squash any error caused by us having closed the connection (and 340 """ Squash any error caused by us having closed the connection (and
341 therefore not having anything to roll back) 341 therefore not having anything to roll back)
342 """ 342 """
343 try: 343 try:
344 self.conn.rollback() 344 self.conn.rollback()
345 except sqlite.ProgrammingError, value: 345 except sqlite.ProgrammingError as value:
346 if str(value) != 'rollback failed - Connection is closed.': 346 if str(value) != 'rollback failed - Connection is closed.':
347 raise 347 raise
348 348
349 def __repr__(self): 349 def __repr__(self):
350 return '<roundlite 0x%x>'%id(self) 350 return '<roundlite 0x%x>'%id(self)
354 354
355 Ignore errors if there's nothing to commit. 355 Ignore errors if there's nothing to commit.
356 """ 356 """
357 try: 357 try:
358 self.conn.commit() 358 self.conn.commit()
359 except sqlite.DatabaseError, error: 359 except sqlite.DatabaseError as error:
360 if str(error) != 'cannot commit - no transaction is active': 360 if str(error) != 'cannot commit - no transaction is active':
361 raise 361 raise
362 # open a new cursor for subsequent work 362 # open a new cursor for subsequent work
363 self.cursor = self.conn.cursor() 363 self.cursor = self.conn.cursor()
364 364

Roundup Issue Tracker: http://roundup-tracker.org/