Ticket #470: 470-2813.patch
File 470-2813.patch, 5.8 KB (added by , 19 years ago) |
---|
-
django/core/management.py
168 168 # We haven't yet created the table to which this field 169 169 # is related, so save it for later. 170 170 pr = pending_references.setdefault(f.rel.to, []).append((klass, f)) 171 table_output.append(' '.join(field_output)) 171 if f.default <> models.fields.NOT_PROVIDED: 172 try: 173 escaped_string = django.db.backend.escapechars(f.default) 174 field_output.append(style.SQL_KEYWORD("DEFAULT '%s'" % (escaped_string,))) 175 except NotImplemented: 176 pass 177 table_output.append(' '.join(field_output)) 172 178 if opts.order_with_respect_to: 173 179 table_output.append(style.SQL_FIELD(backend.quote_name('_order')) + ' ' + \ 174 180 style.SQL_COLTYPE(data_types['IntegerField']) + ' ' + \ -
django/db/backends/ado_mssql/base.py
110 110 return "Convert(datetime, Convert(varchar, DATEPART(year, %s)) + '/' + Convert(varchar, DATEPART(month, %s)) + '/01')" % (field_name, field_name) 111 111 if lookup_type=='day': 112 112 return "Convert(datetime, Convert(varchar(12), %s))" % field_name 113 114 def escapechars(raw_str): 115 "Escapes problematic characters from SQL in a backend-specific way" 116 working_str = str(raw_str) 117 rawchars = ['"',"'"] 118 cookedchars = ['""',"''"] 119 for i in range(0,len(rawchars)): 120 working_str = working_str.replace(rawchars[i],cookedchars[i]) 121 return working_str 113 122 114 123 def get_limit_offset_sql(limit, offset=None): 115 124 # TODO: This is a guess. Make sure this is correct. … … 137 146 'endswith': 'LIKE %s', 138 147 'istartswith': 'LIKE %s', 139 148 'iendswith': 'LIKE %s', 140 } 149 } -
django/db/backends/dummy/base.py
27 27 quote_name = complain 28 28 dictfetchone = complain 29 29 dictfetchmany = complain 30 dictfetchall = complain 30 dictfetchall = complain 31 escapechars = complain 31 32 get_last_insert_id = complain 32 33 get_date_extract_sql = complain 33 34 get_date_trunc_sql = complain 34 35 get_limit_offset_sql = complain 35 36 get_random_function_sql = complain 36 37 get_drop_foreignkey_sql = complain 37 OPERATOR_MAPPING = {} 38 OPERATOR_MAPPING = {} 39 No newline at end of file -
django/db/backends/mysql/base.py
139 139 sql = "CAST(DATE_FORMAT(%s, '%s') AS DATETIME)" % (field_name, format_str) 140 140 return sql 141 141 142 def escapechars(raw_str): 143 "Escapes problematic characters from SQL in a backend-specific way" 144 working_str = str(raw_str) 145 rawchars = ['\\','"',"'"] 146 cookedchars = ['\\\\','\\"',"\\'"] 147 for i in range(0,len(rawchars)): 148 working_str = working_str.replace(rawchars[i],cookedchars[i]) 149 return working_str 150 142 151 def get_limit_offset_sql(limit, offset=None): 143 152 sql = "LIMIT " 144 153 if offset and offset != 0: … … 164 173 'endswith': 'LIKE BINARY %s', 165 174 'istartswith': 'LIKE %s', 166 175 'iendswith': 'LIKE %s', 167 } 176 } 177 No newline at end of file -
django/db/backends/postgresql/base.py
89 89 # http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC 90 90 return "DATE_TRUNC('%s', %s)" % (lookup_type, field_name) 91 91 92 def escapechars(raw_str): 93 "Escapes problematic characters from SQL in a backend-specific way" 94 working_str = str(raw_str) 95 rawchars = ['\\','"',"'"] 96 cookedchars = ['\\\\','\\"',"''"] 97 for i in range(0,len(rawchars)): 98 working_str = working_str.replace(rawchars[i],cookedchars[i]) 99 return working_str 100 92 101 def get_limit_offset_sql(limit, offset=None): 93 102 sql = "LIMIT %s" % limit 94 103 if offset and offset != 0: … … 125 134 'endswith': 'LIKE %s', 126 135 'istartswith': 'ILIKE %s', 127 136 'iendswith': 'ILIKE %s', 128 } 137 } 138 No newline at end of file -
django/db/backends/sqlite3/base.py
76 76 return query % tuple("?" * num_params) 77 77 78 78 supports_constraints = False 79 79 80 80 def quote_name(name): 81 81 if name.startswith('"') and name.endswith('"'): 82 82 return name # Quoting once is enough. … … 119 119 def get_drop_foreignkey_sql(): 120 120 return "" 121 121 122 def escapechars(raw_str): 123 "Escapes problematic characters from SQL in a backend-specific way" 124 # sqlite will happily accept a variety of characters without complaint. Single-quotes, however, must be doubled. 125 working_str = str(raw_str) 126 rawchars = ["'",] 127 cookedchars = ["''",] 128 for i in range(0,len(rawchars)): 129 working_str = working_str.replace(rawchars[i],cookedchars[i]) 130 return working_str 131 122 132 def _sqlite_date_trunc(lookup_type, dt): 123 133 try: 124 134 dt = util.typecast_timestamp(dt) … … 148 158 'istartswith': "LIKE %s ESCAPE '\\'", 149 159 'iendswith': "LIKE %s ESCAPE '\\'", 150 160 } 161