Centralize cursors to PDB.sql_execute.
This gives me a nice common place to do logging if I want.
This commit is contained in:
		
							parent
							
								
									cca8837863
								
							
						
					
					
						commit
						2edb9a1d57
					
				
					 1 changed files with 13 additions and 16 deletions
				
			
		|  | @ -736,31 +736,32 @@ class PDBSQLMixin: | ||||||
|         return savepoint_id |         return savepoint_id | ||||||
| 
 | 
 | ||||||
|     def sql_delete(self, table, pairs, *, commit=False): |     def sql_delete(self, table, pairs, *, commit=False): | ||||||
|         cur = self.sql.cursor() |  | ||||||
| 
 |  | ||||||
|         (qmarks, bindings) = sqlhelpers.delete_filler(pairs) |         (qmarks, bindings) = sqlhelpers.delete_filler(pairs) | ||||||
|         query = 'DELETE FROM %s %s' % (table, qmarks) |         query = 'DELETE FROM %s %s' % (table, qmarks) | ||||||
|         #self.log.debug(query) |         self.sql_execute(query, bindings) | ||||||
|         cur.execute(query, bindings) |  | ||||||
| 
 | 
 | ||||||
|         if commit: |         if commit: | ||||||
|             self.commit() |             self.commit() | ||||||
| 
 | 
 | ||||||
|  |     def sql_execute(self, query, bindings=[]): | ||||||
|  |         if bindings is None: | ||||||
|  |             bindings = [] | ||||||
|  |         cur = self.sql.cursor() | ||||||
|  |         cur.execute(query, bindings) | ||||||
|  |         return cur | ||||||
|  | 
 | ||||||
|     def sql_insert(self, table, data, *, commit=False): |     def sql_insert(self, table, data, *, commit=False): | ||||||
|         column_names = constants.SQL_COLUMNS[table] |         column_names = constants.SQL_COLUMNS[table] | ||||||
|         cur = self.sql.cursor() |  | ||||||
| 
 |  | ||||||
|         (qmarks, bindings) = sqlhelpers.insert_filler(column_names, data) |         (qmarks, bindings) = sqlhelpers.insert_filler(column_names, data) | ||||||
|  | 
 | ||||||
|         query = 'INSERT INTO %s VALUES(%s)' % (table, qmarks) |         query = 'INSERT INTO %s VALUES(%s)' % (table, qmarks) | ||||||
|         #self.log.debug(query) |         self.sql_execute(query, bindings) | ||||||
|         cur.execute(query, bindings) |  | ||||||
| 
 | 
 | ||||||
|         if commit: |         if commit: | ||||||
|             self.commit() |             self.commit() | ||||||
| 
 | 
 | ||||||
|     def sql_select(self, query, bindings=None): |     def sql_select(self, query, bindings=None): | ||||||
|         cur = self.sql.cursor() |         cur = self.sql_execute(query, bindings) | ||||||
|         cur.execute(query, bindings) |  | ||||||
|         while True: |         while True: | ||||||
|             fetch = cur.fetchone() |             fetch = cur.fetchone() | ||||||
|             if fetch is None: |             if fetch is None: | ||||||
|  | @ -768,17 +769,13 @@ class PDBSQLMixin: | ||||||
|             yield fetch |             yield fetch | ||||||
| 
 | 
 | ||||||
|     def sql_select_one(self, query, bindings=None): |     def sql_select_one(self, query, bindings=None): | ||||||
|         cur = self.sql.cursor() |         cur = self.sql_execute(query, bindings) | ||||||
|         cur.execute(query, bindings) |  | ||||||
|         return cur.fetchone() |         return cur.fetchone() | ||||||
| 
 | 
 | ||||||
|     def sql_update(self, table, pairs, where_key, *, commit=False): |     def sql_update(self, table, pairs, where_key, *, commit=False): | ||||||
|         cur = self.sql.cursor() |  | ||||||
| 
 |  | ||||||
|         (qmarks, bindings) = sqlhelpers.update_filler(pairs, where_key=where_key) |         (qmarks, bindings) = sqlhelpers.update_filler(pairs, where_key=where_key) | ||||||
|         query = 'UPDATE %s %s' % (table, qmarks) |         query = 'UPDATE %s %s' % (table, qmarks) | ||||||
|         #self.log.debug(query) |         self.sql_execute(query, bindings) | ||||||
|         cur.execute(query, bindings) |  | ||||||
| 
 | 
 | ||||||
|         if commit: |         if commit: | ||||||
|             self.commit() |             self.commit() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue