Ticket #470: 470-2900.diff

File 470-2900.diff, 4.8 KB (added by jws, 19 years ago)

update for 2900

  • 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

     
    111111    if lookup_type=='day':
    112112        return "Convert(datetime, Convert(varchar(12), %s))" % field_name
    113113
     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
     122
    114123def get_limit_offset_sql(limit, offset=None):
    115124    # TODO: This is a guess. Make sure this is correct.
    116125    sql = "LIMIT %s" % limit
  • django/db/backends/dummy/base.py

     
    2828dictfetchone = complain
    2929dictfetchmany = complain
    3030dictfetchall = complain
     31escapechars = complain
    3132get_last_insert_id = complain
    3233get_date_extract_sql = complain
    3334get_date_trunc_sql = complain
  • 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:
  • 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:
  • django/db/backends/sqlite3/base.py

     
    123123def get_drop_foreignkey_sql():
    124124    return ""
    125125
     126def escapechars(raw_str):
     127    "Escapes problematic characters from SQL in a backend-specific way"
     128    # sqlite will happily accept a variety of characters without complaint. Single-quotes, however, must be doubled.
     129    working_str = str(raw_str)
     130    rawchars = ["'",]
     131    cookedchars = ["''",]
     132    for i in range(0,len(rawchars)):
     133        working_str = working_str.replace(rawchars[i],cookedchars[i])
     134    return working_str
     135
    126136def _sqlite_date_trunc(lookup_type, dt):
    127137    try:
    128138        dt = util.typecast_timestamp(dt)
     
    152162    'istartswith': "LIKE %s ESCAPE '\\'",
    153163    'iendswith': "LIKE %s ESCAPE '\\'",
    154164}
     165
Back to Top