Changes between Version 9 and Version 10 of DbDumpScript


Ignore:
Timestamp:
08/30/2007 09:37:56 PM (8 years ago)
Author:
limodou
Comment:

keep with svn

Legend:

Unmodified
Added
Removed
Modified
  • DbDumpScript

    v9 v10  
    9191# be saved as python source code, and you can import it.
    9292#
    93 # Version 1.5 2007-02-08
     93# Version 1.8 2007-08-30
     94#    * Fix backend.quote_name to backend.DatabaseOperations().quote_name
     95#      Thanks to richardh
     96#
     97# Version 1.7 2007-05-28
     98#    * keep up with the change of GenericRel, so you can use db_dump.py
     99#      in trunk and version before 0.97
     100#
     101# Version 1.6 2007-04-09
    94102#
    95103# Update 1.0 2007-01-18
     
    112120#    * If the filename is not exists, then skip it
    113121#
     122# Update 1.6 2007-04-09
     123#    * Add float support
    114124
    115125import os, sys
    116126from optparse import OptionParser
    117127import datetime
     128import decimal
    118129
    119130def _get_table_order(app_labels):
     
    197208        m.reverse()
    198209        for model in m:
    199             cursor.execute('DELETE FROM %s WHERE 1=1;' % backend.quote_name(model._meta.db_table))
     210            cursor.execute('DELETE FROM %s WHERE 1=1;' % backend.DatabaseOperations().quote_name(model._meta.db_table))
    200211            for table, fields in get_model_many2many_stru(model):
    201                 cursor.execute('DELETE FROM %s WHERE 1=1;' % backend.quote_name(table))
     212                cursor.execute('DELETE FROM %s WHERE 1=1;' % backend.DatabaseOperations().quote_name(table))
    202213   
    203214    success = True
     
    308319                    sql_fields.append(fd)
    309320                    sql_values.append(v)
    310             e_sql = sql % (backend.quote_name(table),
    311                 ','.join(map(backend.quote_name, sql_fields)), ','.join(['%s'] * len(sql_fields)))
     321            e_sql = sql % (backend.DatabaseOperations().quote_name(table),
     322                ','.join(map(backend.DatabaseOperations().quote_name, sql_fields)), ','.join(['%s'] * len(sql_fields)))
    312323            if stdout:
    313324                print e_sql, sql_values, '\n'
     
    345356
    346357def get_model_many2many_stru(model):
    347     from django.db.models import GenericRel
     358    try:
     359        from django.db.models import GenericRel
     360    except:
     361        from django.contrib.contenttypes.generic import GenericRel
    348362   
    349363    opts = model._meta
     
    399413    fields, default = get_model_stru(model)
    400414    cursor.execute('select %s from %s' %
    401         (','.join(map(backend.quote_name, fields)), backend.quote_name(opts.db_table)))
     415        (','.join(map(backend.DatabaseOperations().quote_name, fields)), backend.DatabaseOperations().quote_name(opts.db_table)))
    402416    return call_cursor(opts.db_table, fields, cursor)
    403417
     
    420434        elif isinstance(fd, datetime.date):
    421435            row[i] = row[i].strftime('%Y-%m-%d')
     436        elif isinstance(fd, decimal.Decimal):
     437            row[i] = row[i].__float__()
     438       
    422439    return row
    423440
     
    429446    for table, fields in get_model_many2many_stru(model):
    430447        cursor.execute('select %s from %s' %
    431             (','.join(map(backend.quote_name, fields)), backend.quote_name(table)))
     448            (','.join(map(backend.DatabaseOperations().quote_name, fields)), backend.DatabaseOperations().quote_name(table)))
    432449        yield call_cursor(table, fields, cursor)
    433450
     
    444461    print >>f, 'table = %r' % table
    445462    print >>f, 'fields = %r' % fields
     463    print >>f, '#default item format: "fieldname":("type", "value")'
     464    print >>f, 'default = {}'
    446465    print >>f, 'records = ['
    447466    i = 0
Back to Top