public void Add(DbConnector dbConn) { if (ChangeID == Guid.Empty) { ChangeID = Guid.NewGuid(); } string q = string.Format("insert into A_SCHEMA_CHANGES_LOG (ChangeID, ChangeNo, ScriptName, DateInstall) values ('{0}', {1}, '{2}', '{3}')", ChangeID, ChangeNo, ScriptName, DateInstall.ToString(CultureInfo.InvariantCulture)); dbConn.SetQueryText(q); dbConn.Execute(); }
public static DbTable GetByName(DbConnector dbConn, string name) { dbConn.SetQueryText(string.Format("{0} where type = 'U' and name = '{1}'", _selectQuery, name)); dbConn.Execute(); if (!dbConn.NextRow()) { return null; } var t = new DbTable(); t.FromDb(dbConn); return t; }
public static DbSchemaChange GetByNo(DbConnector dbConn, uint changeNo) { dbConn.SetQueryText(string.Format("select ChangeID, ChangeNo, ScriptName, DateInstall from A_SCHEMA_CHANGES_LOG where ChangeNo = {0}", changeNo)); dbConn.Execute(); if (!dbConn.NextRow()) { return null; } var sch = new DbSchemaChange(); sch.FromDb(dbConn); return sch; }
public static DbSchemaChange GetLast(DbConnector dbConn) { dbConn.SetQueryText("select ChangeID, ChangeNo, ScriptName, DateInstall from A_SCHEMA_CHANGES_LOG order by ChangeNo desc"); dbConn.Execute(); if (!dbConn.NextRow()) { return null; } var sch = new DbSchemaChange(); sch.FromDb(dbConn); return sch; }
public static List<DbTrigger> GetAll(DbConnector dbConn) { dbConn.SetQueryText(string.Format("{0} where type = N'TR'", _selectQuery)); dbConn.Execute(); List<DbTrigger> trigs = new List<DbTrigger>(); while (dbConn.NextRow()) { var t = new DbTrigger(); t.FromDb(dbConn); trigs.Add(t); } return trigs; }
public static List<DbTable> GetAll(DbConnector dbConn) { dbConn.SetQueryText(string.Format("{0} where type = 'U'", _selectQuery)); dbConn.Execute(); List<DbTable> tables = new List<DbTable>(); while (dbConn.NextRow()) { var t = new DbTable(); t.FromDb(dbConn); tables.Add(t); } return tables; }
public static List<DbFunction> GetAll(DbConnector dbConn) { dbConn.SetQueryText(string.Format("{0} where type in (N'FN', N'IF', N'TF', N'FS', N'FT')", _selectQuery)); dbConn.Execute(); List<DbFunction> functions = new List<DbFunction>(); while (dbConn.NextRow()) { var f = new DbFunction(); f.FromDb(dbConn); functions.Add(f); } return functions; }
public static List<DbView> GetAll(DbConnector dbConn) { dbConn.SetQueryText(string.Format("{0} where type = N'V'", _selectQuery)); dbConn.Execute(); List<DbView> views = new List<DbView>(); while (dbConn.NextRow()) { var v = new DbView(); v.FromDb(dbConn); views.Add(v); } return views; }
public static List<DbProcedure> GetAll(DbConnector dbConn) { dbConn.SetQueryText(string.Format("{0} where type in (N'P', N'PC')", _selectQuery)); dbConn.Execute(); List<DbProcedure> procs = new List<DbProcedure>(); while (dbConn.NextRow()) { var p = new DbProcedure(); p.FromDb(dbConn); procs.Add(p); } return procs; }
public void Delete(DbConnector dbConn) { dbConn.SetQueryText(string.Format("drop trigger [dbo].[{0}]", Name)); dbConn.Execute(); }
private static bool _executeScript(DbConnector dbConn, string scriptFile) { try { Console.WriteLine("DbBuilder: Executing script '{0}'", scriptFile); if (!File.Exists(scriptFile)) { Console.WriteLine("DbBuilder: Error: Script file'{0} not found, STOP !", scriptFile); return false; } var script = File.ReadAllText(scriptFile); var queries = script.Split(new []{ "GO\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (var qd in queries) { string q = qd.Trim(); if (q.Length == 0) { continue; } dbConn.SetQueryText(q); dbConn.Execute(); } } catch (System.Exception e) { _printException(e); Console.WriteLine("DbBuilder: Error: Exception in execution, STOP !"); return false; } return true; }