Ticket #470: 470-2813.patch

File 470-2813.patch, 5.8 KB (added by Jws, 19 years ago)

patch updated for pending release of 0.95

  • django/core/management.py

     
    168168                    # We haven't yet created the table to which this field
    169169                    # is related, so save it for later.
    170170                    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))
    172178    if opts.order_with_respect_to:
    173179        table_output.append(style.SQL_FIELD(backend.quote_name('_order')) + ' ' + \
    174180            style.SQL_COLTYPE(data_types['IntegerField']) + ' ' + \
  • django/db/backends/ado_mssql/base.py

     
    110110        return "Convert(datetime, Convert(varchar, DATEPART(year, %s)) + '/' + Convert(varchar, DATEPART(month, %s)) + '/01')" % (field_name, field_name)
    111111    if lookup_type=='day':
    112112        return "Convert(datetime, Convert(varchar(12), %s))" % field_name
     113
     114def 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
    113122
    114123def get_limit_offset_sql(limit, offset=None):
    115124    # TODO: This is a guess. Make sure this is correct.
     
    137146    'endswith': 'LIKE %s',
    138147    'istartswith': 'LIKE %s',
    139148    'iendswith': 'LIKE %s',
    140 }
     149}
  • django/db/backends/dummy/base.py

     
    2727quote_name = complain
    2828dictfetchone = complain
    2929dictfetchmany = complain
    30 dictfetchall = complain
     30dictfetchall = complain
     31escapechars = complain
    3132get_last_insert_id = complain
    3233get_date_extract_sql = complain
    3334get_date_trunc_sql = complain
    3435get_limit_offset_sql = complain
    3536get_random_function_sql = complain
    3637get_drop_foreignkey_sql = complain
    37 OPERATOR_MAPPING = {}
     38OPERATOR_MAPPING = {}
     39 No newline at end of file
  • django/db/backends/mysql/base.py

     
    139139        sql = "CAST(DATE_FORMAT(%s, '%s') AS DATETIME)" % (field_name, format_str)
    140140    return sql
    141141
     142def 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
    142151def get_limit_offset_sql(limit, offset=None):
    143152    sql = "LIMIT "
    144153    if offset and offset != 0:
     
    164173    'endswith': 'LIKE BINARY %s',
    165174    'istartswith': 'LIKE %s',
    166175    'iendswith': 'LIKE %s',
    167 }
     176}
     177 No newline at end of file
  • django/db/backends/postgresql/base.py

     
    8989    # http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
    9090    return "DATE_TRUNC('%s', %s)" % (lookup_type, field_name)
    9191
     92def 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
    92101def get_limit_offset_sql(limit, offset=None):
    93102    sql = "LIMIT %s" % limit
    94103    if offset and offset != 0:
     
    125134    'endswith': 'LIKE %s',
    126135    'istartswith': 'ILIKE %s',
    127136    'iendswith': 'ILIKE %s',
    128 }
     137}
     138 No newline at end of file
  • django/db/backends/sqlite3/base.py

     
    7676        return query % tuple("?" * num_params)
    7777
    7878supports_constraints = False
    79 
     79
    8080def quote_name(name):
    8181    if name.startswith('"') and name.endswith('"'):
    8282        return name # Quoting once is enough.
     
    119119def get_drop_foreignkey_sql():
    120120    return ""
    121121
     122def 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
    122132def _sqlite_date_trunc(lookup_type, dt):
    123133    try:
    124134        dt = util.typecast_timestamp(dt)
     
    148158    'istartswith': "LIKE %s ESCAPE '\\'",
    149159    'iendswith': "LIKE %s ESCAPE '\\'",
    150160}
     161
Back to Top