Ticket #2284: new-patch.diff
File new-patch.diff, 1.9 KB (added by , 18 years ago) |
---|
-
django/core/management.py
337 337 338 338 # Some backends can't execute more than one SQL statement at a time, 339 339 # 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) 341 348 342 349 # Find custom SQL, if it's available. 343 350 sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), settings.DATABASE_ENGINE)), … … 345 352 for sql_file in sql_files: 346 353 if os.path.exists(sql_file): 347 354 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())) 351 356 fp.close() 352 357 353 358 return output … … 497 502 if initial_sql: 498 503 print "Installing initial data for %s model" % model._meta.object_name 499 504 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 501 508 cursor.execute(sql) 502 509 except Exception, e: 503 510 sys.stderr.write("Failed to install initial SQL data for %s model: %s" % \