예제 #1
0
        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);
            }
        }
예제 #2
0
 int executeLog(string sql)
 {
     WebServer.Log(sql);
     using (MySqlCommand cmd = command(sql)) {
         return(cmd.ExecuteNonQuery());
     }
 }
예제 #3
0
 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);
     }
 }
예제 #4
0
 int executeLogSafe(string sql)
 {
     try {
         return(executeLog(sql));
     } catch (Exception ex) {
         WebServer.Log(ex.Message);
         return(-1);
     }
 }
예제 #5
0
 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);
     }
 }
예제 #6
0
 int executeLog(string sql)
 {
     WebServer.Log(sql);
     lock (_lock) {
         using (SqliteCommand cmd = command(sql)) {
             return(cmd.ExecuteNonQuery());
         }
     }
 }
예제 #7
0
        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);
            }
        }
예제 #8
0
 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);
     }
 }
예제 #9
0
 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);
     }
 }
예제 #10
0
        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");
            }
        }