0

I am trying to import into Erwin Data Modeler a .sql file created through Python, but when I import the file it creates an empty model. I have tried copying and pasting the sql script into a notepad and then import the new file and it works, so the problem must be with the format of the file I'm creating.

Here's the code I'm using and a sample output.

sql_output = open(sqlFilePath,'wt', encoding="ANSI")
sql_output.write("\nCREATE TABLE {}".format(table) + ' (\n')

if "int" == row[2].value:
  sql_output.write(" INT")
elif "float" == row[2].value:
  sql_output.write(" FLOAT")
elif "char" == row[2].value:
  sql_output.write(" CHAR({})".format(row[3].value))
elif "varchar2" == row[2].value or "CLOB" == row[2].value or "LONG" == row[2].value:
  sql_output.write(" VARCHAR(100)")
elif "date" == row[2].value:
  sql_output.write(" DATETIME")
elif "timestamp" == row[2].value:
  sql_output.write(" TIMESTAMP")

# nullability
if "N" == row[4].value:
  sql_output.write(" NOT NULL")

if PK_found:
  sql_output.write(",\n  PRIMARY KEY ({})".format(PK_string))

if FK_found:
  sql_output.write(",\n  FOREIGN KEY ({}) REFERENCES {}({})".format(foreign_key, table_ref, ref_key))

sql_output.write('\n);\n')

sql_output.flush()
sql_output.close()

Here's what the code writes:

CREATE TABLE TableName (
  AttributeX INT NOT NULL,
  AttributeY VARCHAR(100) NOT NULL,
  AttributeZ FLOAT NOT NULL,
  PRIMARY KEY (AttributeX)
);

Again if I copy and paste this output in a notepad, Erwin reads it, but it doesn't work if I give it as an input the file written directly by Python. Does anybody know what the problem might be? Thank you!

Bebba
  • 27
  • 3

0 Answers0