decimal lengthFromColumn(DataRow c) { try { switch (c["DATA_TYPE"].ToString().ToLower()) { case "int": case "integer": return(11); case "tinyint": case "bit": return(1); case "decimal": string s = c["NUMERIC_PRECISION"] + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + c["NUMERIC_SCALE"]; return(s == "." ? 10.2M : decimal.Parse(s)); case "double": case "float": return(10.4M); case "varchar": return(Convert.ToDecimal(c["CHARACTER_MAXIMUM_LENGTH"])); default: return(0); } } catch (Exception ex) { WebServer.Log(ex.ToString()); return(0); } }
int executeLog(string sql) { WebServer.Log(sql); using (MySqlCommand cmd = command(sql)) { return(cmd.ExecuteNonQuery()); } }
static public void Load(string filename) { WebServer.Log("Loading config from {0}", filename); using (StreamReader s = new StreamReader(filename)) { Default = Utils.JsonTo <AppSettings>(s.ReadToEnd()); Default.Filename = Path.GetFileNameWithoutExtension(filename); } }
int executeLogSafe(string sql) { try { return(executeLog(sql)); } catch (Exception ex) { WebServer.Log(ex.Message); return(-1); } }
public override object Invoke(object[] args) { try { return(Utils.Now.ToString("yyyy-MM-ddThh:mm:ss")); } catch (Exception ex) { WebServer.Log("Exception: {0}", ex); return(null); } }
int executeLog(string sql) { WebServer.Log(sql); lock (_lock) { using (SqliteCommand cmd = command(sql)) { return(cmd.ExecuteNonQuery()); } } }
static void createDatabase(string connectionString) { Match m = Regex.Match(connectionString, @"Data Source=([^;]+)", RegexOptions.IgnoreCase); if (m.Success && !File.Exists(m.Groups[1].Value)) { WebServer.Log("Creating SQLite database {0}", m.Groups[1].Value); Directory.CreateDirectory(Path.GetDirectoryName(m.Groups[1].Value)); SqliteConnection.CreateFile(m.Groups[1].Value); } }
public override object Invoke(object[] args) { if (args.Length < 2 || args[0] == null || args[0] == DBNull.Value || args[1] == null || args[1] == DBNull.Value) { return(null); } try { DateTime d1 = DateTime.Parse(args[0].ToString()); DateTime d2 = DateTime.Parse(args[1].ToString()); return((d1 - d2).TotalDays); } catch (Exception ex) { WebServer.Log("Exception: {0}", ex); return(null); } }
public override void Step(object[] args, int stepNumber, ref object contextData) { if (args.Length < 1 || args[0] == null || args[0] == DBNull.Value) { return; } try { decimal d = Math.Round(Convert.ToDecimal(args[0]), 4); if (contextData != null) { d += (Decimal)contextData; } contextData = d; } catch (Exception ex) { WebServer.Log("Exception: {0}", ex); } }
void reCreateTable(Table code, Table database) { string newTable = "_NEW_" + code.Name; try { executeLogSafe("PRAGMA foreign_keys=OFF"); executeLog("BEGIN TRANSACTION"); createTable(code, newTable); executeLog(string.Format("INSERT INTO {0} ({2}) SELECT {2} FROM {1}", newTable, database.Name, string.Join(", ", code.Fields.Select(f => f.Name) .Where(f => database.Fields.FirstOrDefault(d => d.Name == f) != null).ToArray()))); DropTable(database); executeLog("ALTER TABLE " + newTable + " RENAME TO " + code.Name); createIndexes(code); executeLog("PRAGMA foreign_key_check"); executeLog("COMMIT TRANSACTION"); } catch (Exception ex) { WebServer.Log("Exception: {0}", ex); executeLogSafe("ROLLBACK TRANSACTION"); throw; } finally { executeLogSafe("PRAGMA foreign_keys=ON"); } }