Ticket #2519: sqlite3.patch
File sqlite3.patch, 4.2 KB (added by , 18 years ago) |
---|
-
django/db/backends/sqlite3/base.py
18 18 Database.register_converter("timestamp", util.typecast_timestamp) 19 19 Database.register_converter("TIMESTAMP", util.typecast_timestamp) 20 20 21 try: 22 # this only exists in 2.4+ 23 from decimal import Decimal 24 Database.register_converter("numeric", util.typecast_numeric) 25 Database.register_adapter(Decimal, util.rev_typecast_decimal) 26 except: 27 pass 28 29 import re 30 31 # We need to trap any queries with empty parenthesis because their invalid in 32 # other database - like Postgresql 33 empty_in_clause = re.compile(".* +in +\( *\).*", re.I) 34 21 35 def utf8rowFactory(cursor, row): 22 36 def utf8(s): 23 37 if type(s) == unicode: … … 66 80 self.connection.close() 67 81 self.connection = None 68 82 69 class SQLiteCursorWrapper( Database.Cursor):83 class SQLiteCursorWrapper(object): 70 84 """ 71 85 Django uses "format" style placeholders, but pysqlite2 uses "qmark" style. 72 86 This fixes it -- but note that if you want to use a literal "%s" in a query, 73 87 you'll need to use "%%s". 74 88 """ 89 def __init__(self, *args, **kwargs): 90 self._cursor = Database.Cursor(*args, **kwargs) 91 75 92 def execute(self, query, params=()): 76 93 query = self.convert_query(query, len(params)) 77 return Database.Cursor.execute(self, query, params) 94 if empty_in_clause.match(query): 95 raise SyntaxError, "Invalid SQL query. Your IN clause is empty. [%s]" % query 96 return self._cursor.execute(query, params) 78 97 79 98 def executemany(self, query, param_list): 80 99 query = self.convert_query(query, len(param_list[0])) 81 return Database.Cursor.executemany(self,query, param_list)100 return self._cursor.executemany(query, param_list) 82 101 83 102 def convert_query(self, query, num_params): 84 103 return query % tuple("?" * num_params) 85 104 105 def __getattr__(self, attr): 106 if self.__dict__.has_key(attr): 107 return self.__dict__[key] 108 else: 109 return getattr(self._cursor, attr) 110 86 111 supports_constraints = False 87 112 88 113 def quote_name(name): -
django/db/backends/sqlite3/creation.py
4 4 DATA_TYPES = { 5 5 'AutoField': 'integer', 6 6 'BooleanField': 'bool', 7 'CharField': 'varchar (%(maxlength)s)',8 'CommaSeparatedIntegerField': 'varchar (%(maxlength)s)',7 'CharField': 'varchar', 8 'CommaSeparatedIntegerField': 'varchar', 9 9 'DateField': 'date', 10 10 'DateTimeField': 'datetime', 11 'FileField': 'varchar (100)',12 'FilePathField': 'varchar (100)',13 'FloatField': 'numeric (%(max_digits)s, %(decimal_places)s)',14 'ImageField': 'varchar (100)',11 'FileField': 'varchar', 12 'FilePathField': 'varchar', 13 'FloatField': 'numeric', 14 'ImageField': 'varchar', 15 15 'IntegerField': 'integer', 16 'IPAddressField': ' char(15)',16 'IPAddressField': 'varchar', 17 17 'ManyToManyField': None, 18 18 'NullBooleanField': 'bool', 19 19 'OneToOneField': 'integer', 20 'PhoneNumberField': 'varchar (20)',20 'PhoneNumberField': 'varchar', 21 21 'PositiveIntegerField': 'integer unsigned', 22 22 'PositiveSmallIntegerField': 'smallint unsigned', 23 'SlugField': 'varchar (%(maxlength)s)',23 'SlugField': 'varchar', 24 24 'SmallIntegerField': 'smallint', 25 25 'TextField': 'text', 26 26 'TimeField': 'time', 27 'URLField': 'varchar (200)',28 'USStateField': 'varchar (2)',27 'URLField': 'varchar', 28 'USStateField': 'varchar', 29 29 }