Ticket #2284: new-patch.diff

File new-patch.diff, 1.9 KB (added by scottanderson@…, 9 years ago)

Reverts old regex but stil fixes escaped quotes problem from ticket #2119

  • django/core/management.py

     
    337337
    338338    # Some backends can't execute more than one SQL statement at a time,
    339339    # so split into separate statements.
    340     statements = re.compile(r";[ \t]*$", re.M)
     340    statements = re.compile(
     341        r"""(           # each statement ...
     342        [^\r\n;]        # starts with something other than a line ending or ';'
     343        (?:             # then has one or more chunks of ...
     344            (?:[^;'"]+) # not the end of a statement or start of a quote
     345          | (?:'(?:[^']|\\')*') # something in single quotes, but not escaped
     346          | (?:"(?:[^"]|\\")") # something in double quotes, but not escaped
     347        )+)""", re.VERBOSE)
    341348
    342349    # Find custom SQL, if it's available.
    343350    sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), settings.DATABASE_ENGINE)),
     
    345352    for sql_file in sql_files:
    346353        if os.path.exists(sql_file):
    347354            fp = open(sql_file)
    348             for statement in statements.split(fp.read()):
    349                 if statement.strip():
    350                     output.append(statement + ";")
     355            output.extend(statements.findall(fp.read()))
    351356            fp.close()
    352357
    353358    return output
     
    497502                if initial_sql:
    498503                    print "Installing initial data for %s model" % model._meta.object_name
    499504                    try:
    500                         for sql in initial_sql:
     505                        for sql in [sql.strip() for sql in initial_sql]:
     506                            if not sql: continue
     507                            print "Executing '%s'" % sql
    501508                            cursor.execute(sql)
    502509                    except Exception, e:
    503510                        sys.stderr.write("Failed to install initial SQL data for %s model: %s" % \
Back to Top