void LoadData() { MyConn conn = new MyConn(); conn.OnRead += Conn_OnRead; conn.ExecQuery(MySchm.querySchema); }
public void GenerateScript() { LoadData(); var tables = data.Select(x => x.table_name).Distinct().ToList(); MyConn conn; foreach (string table in tables) { query += "\nTable " + table + " {"; var columns = data.Where(x => x.table_name == table).ToList(); foreach (var column in columns) { query += "\n" + column.column_name; switch (column.type_name) { case "nvarchar": query += " varchar"; break; case "datetime2": query += " datetime"; break; default: query += " " + column.type_name; break; } if (column.is_key) { query += " [pk]"; } } query += "\n}"; conn = new MyConn(); conn.OnRead += Conn_OnRead1; conn.ExecQuery(MySchm.getForeignKeys(table)); } System.IO.File.WriteAllText("script.txt", query + foreignKeys); Console.ReadLine(); }
public void GenerateScript() { LoadData(); var tables = data.Select(x => x.table_name).Distinct().ToList(); MyConn conn; foreach (string table in tables) { query += "\ncreate table " + table + " ("; var columns = data.Where(x => x.table_name == table).ToList(); int counter = 0; foreach (var column in columns) { query += "\n" + column.column_name; counter += 1; switch (column.type_name) { case "nvarchar": query += " varchar(50)"; break; case "datetime2": query += " datetime"; break; case "int": query += " number(10)"; break; case "bit": query += " boolean"; break; default: query += " " + column.type_name; break; } if (column.is_key) { query += " primary key"; } if (!column.is_nullable) { query += " not null"; } if (counter != columns.Count) { query += ","; } } query += "\n);"; conn = new MyConn(); conn.OnRead += Conn_OnRead1; conn.ExecQuery(MySchm.getForeignKeys(table)); } System.IO.File.WriteAllText("script.txt", query + foreignKeys); Console.ReadLine(); }