public bool RunSprocs(DirectoryInfo directory, SqlType dialect, DatabaseTable table) { if (table == null) { Message = "No table"; return false; } var gen = new DdlGeneratorFactory(dialect).ProcedureGenerator(table); if (gen == null) { //there is no sproc provider (SQLite) Message = @"There is no sproc generator"; return false; } var path = Path.Combine(directory.FullName, table.Name + "_sprocs.sql"); try { gen.WriteToScript(path); Message = @"Wrote " + path; return true; } catch (Exception exception) { Message = @"An error occurred while creating the script.\n" + exception.Message; } return false; }
public void TestWritingCrudSprocs() { var table = LoadCategoriesFromNorthwind(); //let's create the SQLServer crud procedures var gen = new DdlGeneratorFactory(SqlType.SqlServer).ProcedureGenerator(table); gen.ManualPrefix = table.Name + "__"; var destination = TestHelper.CreateDirectory("sql").FullName; var path = Path.Combine(destination, "sqlserver_sprocs.sql"); gen.WriteToScript(path); var txt = File.ReadAllText(path); Assert.IsFalse(string.IsNullOrEmpty(txt), "Should have written some text"); //manually check the script is ok }
public void TestWritingCrudSprocsWithOracleConversion() { var table = LoadCategoriesFromNorthwind(); //let's pretend it's an oracle table and create an oracle package var oracleGen = new DdlGeneratorFactory(SqlType.Oracle).ProcedureGenerator(table); oracleGen.ManualPrefix = table.Name + "__"; //here i want all my parameters prefixed by a p oracleGen.FormatParameter = name => "p_" + name; //also define the cursor parameter oracleGen.CursorParameterName = "p_cursor"; var destination = TestHelper.CreateDirectory("sql").FullName; var oraclePath = Path.Combine(destination, "oracle_sprocs.sql"); oracleGen.WriteToScript(oraclePath); var txt = File.ReadAllText(oraclePath); Assert.IsFalse(string.IsNullOrEmpty(txt), "Should have written some text"); //manually check the script is ok }