Django

Code

Changeset 737

Show
Ignore:
Timestamp:
09/29/05 18:43:03 (3 years ago)
Author:
adrian
Message:

Changed [735] so that database-agnostic SQL always gets executed, even if database-specific SQL doesn't exist.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management.py

    r735 r737  
    157157def get_sql_initial_data(mod): 
    158158    "Returns a list of the initial INSERT SQL statements for the given module." 
     159    from django.core import db 
    159160    output = [] 
    160161    app_label = mod._MODELS[0]._meta.app_label 
     
    163164    for klass in mod._MODELS: 
    164165        opts = klass._meta 
     166 
    165167        # Add custom SQL, if it's available. 
    166         from django.core import db 
    167          
    168         # Get the sql file name for the init data for the current database engine 
    169         db_engine_sql_file_name = os.path.join(app_dir, opts.module_name + '.' + db.DATABASE_ENGINE.lower() +  '.sql') 
    170  
    171         # Check if the data specific file exists 
    172         if os.path.exists(db_engine_sql_file_name): 
    173             sql_file_name = db_engine_sql_file_name 
    174         # if the database specific file doesn't exist, use the database agnostic version 
    175         else: 
    176             sql_file_name = os.path.join(app_dir, opts.module_name + '.sql') 
    177  
    178         if os.path.exists(sql_file_name): 
    179             fp = open(sql_file_name, 'r') 
    180             output.append(fp.read()) 
    181             fp.close() 
     168        sql_files = [os.path.join(app_dir, opts.module_name + '.' + db.DATABASE_ENGINE +  '.sql'), 
     169                     os.path.join(app_dir, opts.module_name + '.sql')] 
     170        for sql_file in sql_files: 
     171            if os.path.exists(sql_file): 
     172                fp = open(sql_file) 
     173                output.append(fp.read()) 
     174                fp.close() 
     175 
    182176        # Content types. 
    183177        output.append(_get_contenttype_insert(opts))