public static void Config(string dir, string tgt, string cs, string driver) { string configScript = string.Format("{0}/config/{1}.sql", dir, tgt); if (!File.Exists(configScript)) { Console.WriteLine(string.Format("{0} does not exist.", configScript)); } else { dbconn db = new dbconn(cs, driver); using (StreamReader sr = new StreamReader(configScript)) { string sql = sr.ReadToEnd(); bool result = db.exec(sql); Console.WriteLine(string.Format("Applying {0}... {1}", configScript, (result ? "Success" : "Fail"))); } } }
public static void SchemaInit(string cs, string driver) { string sql = null; if (driver == "mssql") { sql = "select count(*) as c from sysobjects where type = 'U' and name = '_dbrel';"; } if (driver == "mysql") { sql = "select count(*) as c from information_schema.tables where table_schema = database() AND table_name = '_dbrel';"; } if (sql != null) { dbconn db = new dbconn(cs, driver); List <Dictionary <string, object> > rows = db.rows(sql); int c = System.Convert.ToInt32(rows[0]["c"]); if (c == 0) { sql = "create table _dbrel (id int not null, primary key (id));"; db.exec(sql); } } }