Package buildbot :: Package monkeypatches :: Module sqlalchemy2189
[frames] | no frames]

Source Code for Module buildbot.monkeypatches.sqlalchemy2189

  1  # This file is part of Buildbot.  Buildbot is free software: you can 
  2  # redistribute it and/or modify it under the terms of the GNU General Public 
  3  # License as published by the Free Software Foundation, version 2. 
  4  # 
  5  # This program is distributed in the hope that it will be useful, but WITHOUT 
  6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  8  # details. 
  9  # 
 10  # You should have received a copy of the GNU General Public License along with 
 11  # this program; if not, write to the Free Software Foundation, Inc., 51 
 12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
 13  # 
 14  # Copyright Buildbot Team Members 
 15   
 16  import re 
 17  from buildbot.util import sautils 
 18  from sqlalchemy.engine import reflection 
 19  from sqlalchemy.dialects.sqlite.base import SQLiteDialect, _pragma_cursor 
 20  from sqlalchemy.dialects.sqlite.base import sqltypes, util 
 21   
 22  @reflection.cache 
23 -def get_columns_06x_fixed(self, connection, table_name, schema=None, **kw):
24 quote = self.identifier_preparer.quote_identifier 25 if schema is not None: 26 pragma = "PRAGMA %s." % quote(schema) 27 else: 28 pragma = "PRAGMA " 29 qtable = quote(table_name) 30 c = _pragma_cursor(connection.execute("%stable_info(%s)" % (pragma, qtable))) 31 #### found_table = False (pyflake) 32 columns = [] 33 while True: 34 row = c.fetchone() 35 if row is None: 36 break 37 (name, type_, nullable, default, has_default, primary_key) = (row[1], row[2].upper(), not row[3], row[4], row[4] is not None, row[5]) 38 name = re.sub(r'^\"|\"$', '', name) 39 #### if default: 40 #### default = re.sub(r"^\'|\'$", '', default) 41 match = re.match(r'(\w+)(\(.*?\))?', type_) 42 if match: 43 coltype = match.group(1) 44 args = match.group(2) 45 else: 46 coltype = "VARCHAR" 47 args = '' 48 try: 49 coltype = self.ischema_names[coltype] 50 except KeyError: 51 util.warn("Did not recognize type '%s' of column '%s'" % 52 (coltype, name)) 53 coltype = sqltypes.NullType 54 if args is not None: 55 args = re.findall(r'(\d+)', args) 56 coltype = coltype(*[int(a) for a in args]) 57 58 columns.append({ 59 'name' : name, 60 'type' : coltype, 61 'nullable' : nullable, 62 'default' : default, 63 'primary_key': primary_key 64 }) 65 return columns
66 67 68 @reflection.cache
69 -def get_columns_07x_fixed(self, connection, table_name, schema=None, **kw):
70 quote = self.identifier_preparer.quote_identifier 71 if schema is not None: 72 pragma = "PRAGMA %s." % quote(schema) 73 else: 74 pragma = "PRAGMA " 75 qtable = quote(table_name) 76 c = _pragma_cursor(connection.execute("%stable_info(%s)" % (pragma, qtable))) 77 #### found_table = False (pyflake) 78 columns = [] 79 while True: 80 row = c.fetchone() 81 if row is None: 82 break 83 (name, type_, nullable, default, has_default, primary_key) = (row[1], row[2].upper(), not row[3], row[4], row[4] is not None, row[5]) 84 name = re.sub(r'^\"|\"$', '', name) 85 #### if default: 86 #### default = re.sub(r"^\'|\'$", '', default) 87 match = re.match(r'(\w+)(\(.*?\))?', type_) 88 if match: 89 coltype = match.group(1) 90 args = match.group(2) 91 else: 92 coltype = "VARCHAR" 93 args = '' 94 try: 95 coltype = self.ischema_names[coltype] 96 if args is not None: 97 args = re.findall(r'(\d+)', args) 98 coltype = coltype(*[int(a) for a in args]) 99 except KeyError: 100 util.warn("Did not recognize type '%s' of column '%s'" % 101 (coltype, name)) 102 coltype = sqltypes.NullType() 103 104 columns.append({ 105 'name' : name, 106 'type' : coltype, 107 'nullable' : nullable, 108 'default' : default, 109 'autoincrement':default is None, 110 'primary_key': primary_key 111 }) 112 return columns
113
114 -def patch():
115 # fix for http://www.sqlalchemy.org/trac/ticket/2189, backported to 0.6.0 116 if sautils.sa_version()[:2] == (0, 6): 117 get_columns_fixed = get_columns_06x_fixed 118 else: 119 get_columns_fixed = get_columns_07x_fixed 120 SQLiteDialect.get_columns = get_columns_fixed
121