Django

Code

Changeset 3178

Show
Ignore:
Timestamp:
06/20/06 03:00:44 (2 years ago)
Author:
mtredinnick
Message:

Fixed #2119 -- fixed problems with splitting SQL statements into separate
statements. Uses a patch from eaw@woudy.org and some contributions from
jpellerin@gmail.com. Also fixes #2034 and #1935.

Files:

Legend:

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

    r3177 r3178  
    334334    # Some backends can't execute more than one SQL statement at a time, 
    335335    # so split into separate statements. 
    336     sql_expr = re.compile( 
    337         r"""(           # each statement ... 
    338         [^\r\n;]        # starts with something other than a line ending or ';' 
    339         (?:             # then has one or more chunks of ... 
    340             (?:[^;'"]+) # not the end of a statement or start of a quote 
    341           | (?:'[^']*') # something in single quotes 
    342           | (?:"[^"]*") # something in double quotes 
    343         )+)""", re.VERBOSE) 
     336    statements = re.compile(r";[ \t]*$", re.M) 
    344337 
    345338    # Find custom SQL, if it's available. 
     
    349342        if os.path.exists(sql_file): 
    350343            fp = open(sql_file) 
    351             output.extend(sql_expr.findall(fp.read())) 
     344            for statement in statements.split(fp.read()): 
     345                if statement.strip(): 
     346                    output.append(statement + ";") 
    352347            fp.close() 
    353348 
  • django/trunk/tests/regressiontests/initial_sql_regress/sql/simple.sql

    r3177 r3178  
    33INSERT INTO initial_sql_regress_simple (name) VALUES ('Ringo'); 
    44INSERT INTO initial_sql_regress_simple (name) VALUES ('George'); 
     5INSERT INTO initial_sql_regress_simple (name) VALUES ('Miles O''Brien'); 
    56