/// <summary> /// Reads the table data and returns the INSERT statements /// </summary> /// <param name="databaseTable">The database table.</param> /// <param name="connectionString">The connection string.</param> /// <param name="providerName">Name of the provider.</param> /// <returns></returns> public string ReadTable(DatabaseTable databaseTable, string connectionString, string providerName) { var r = new Reader(databaseTable, connectionString, providerName); r.PageSize = PageSize; var dt = r.Read(); var w = new InsertWriter(databaseTable, dt); w.IncludeIdentity = IncludeIdentity; w.IncludeBlobs = IncludeBlobs; return w.Write(FindSqlType(providerName)); }
public void TestInsertIntegration() { //arrange var dbReader = TestHelper.GetNorthwindReader(); var table = dbReader.Table("Orders"); var rdr = new Reader(table, ConnectionString, Providername); var dt = rdr.Read(); var insertWriter = new InsertWriter(table, dt); insertWriter.IncludeIdentity = true; //act string txt = insertWriter.Write(SqlType.SqlServer); //assert Console.WriteLine(txt); //check this manually }
public bool RunData(DirectoryInfo directory, SqlType dialect, DatabaseTable table) { if (table == null) { Message = "No table"; return false; } var path = Path.Combine(directory.FullName, table.Name + "_data.sql"); try { var rdr = new Reader(table, table.DatabaseSchema.ConnectionString, table.DatabaseSchema.Provider); var dt = rdr.Read(); var insertWriter = new InsertWriter(table, dt); //we have special processing for sqlserver if (dialect == SqlType.SqlServer || dialect == SqlType.SqlServerCe //assume db2 uses "generated by default" not "generated always". || dialect == SqlType.SQLite //SQLite is fine with identity inserts and MySQL autoincrement is effectively DEFAULT=MAX(col) anyway || dialect == SqlType.Db2 || dialect == SqlType.MySql) { insertWriter.IncludeIdentity = true; } //act string txt = insertWriter.Write(dialect); File.WriteAllText(path, txt); Message = @"Wrote " + path; return true; } catch (Exception exception) { Message = @"An error occurred while creating the script.\n" + exception.Message; } return false; }
/// <summary> /// Reads the table data and invokes the function for each INSERT statement. The databaseTable must have dataTypes (call DataReader.DataTypes()). /// </summary> /// <param name="databaseTable">The database table.</param> /// <param name="connectionString">The connection string.</param> /// <param name="providerName">Name of the provider.</param> /// <param name="processRecord">The process record.</param> public void ReadTable(DatabaseTable databaseTable, string connectionString, string providerName, Func<string, bool> processRecord) { var r = new Reader(databaseTable, connectionString, providerName); var w = new InsertWriter(databaseTable, FindSqlType(providerName)); r.Read(record => { var s = w.WriteInsert(record); return processRecord(s); }); }