// A wrapper function around GetDatabaseStructure(DataTable) to override in a derived class public virtual string[] GetDatabaseStructure(SwapQLConnection tConnection) { var createStatements = new List <string>(); var tables = Connection.GetSchema("Tables", new[] { AccessConfig.Source.Databasename }); foreach (DataRow table in tables.Rows) { var tableName = table[2] as string; var dt = Connection.GetSchema("Columns", new[] { AccessConfig.Source.Databasename, tableName }); string statement = $"CREATE TABLE {tableName} ({GetDatabaseStructure(dt, tConnection)});"; } return(createStatements.ToArray()); }
// Construct an SQL statement for each column protected string GetDatabaseStructure(DataTable columns, SwapQLConnection tConnection) { var columnDefinition = ""; string columnName, columnType; for (var i = 0; i < columns.Rows.Count - 1; i++) { var column = columns.Rows[i]; columnName = column.Field <string>("column_name"); columnType = tConnection.GetTDataTypeName(column.Field <string>("column_type")); columnDefinition += $"{columnName} {columnType}, "; } columnName = columns.Rows[columns.Rows.Count - 1].Field <string>("column_name"); columnType = tConnection.GetTDataTypeName(columns.Rows[columns.Rows.Count - 1].Field <string>("column_type")); columnDefinition += $"{columnName} {columnType}"; return(columnDefinition); }