Esempio n. 1
0
        private void setConnectionType(string providerName)
        {
            switch (providerName)
            {
            case "Oracle":
                sqlConnectionType = SQLConnectionType.Oracle;
                break;

            case "PostgreSQL":
                sqlConnectionType = SQLConnectionType.PostgreSQL;
                break;

            case "SQLServer":
                sqlConnectionType = SQLConnectionType.SQLServer;
                break;

            case "MySQL":
            case "MySql.Data.MySqlClient":
            case "MySql.Data":
                sqlConnectionType = SQLConnectionType.MySQL;
                break;

            case "Dm":
                sqlConnectionType = SQLConnectionType.Dm;
                break;
            }
        }
        public static string genarateSQL(string sql, SQLConnectionType sqlConnectionType)
        {
            switch (sqlConnectionType)
            {
            case SQLConnectionType.Oracle:
                MatchCollection dateMatchs = Regex.Matches(sql, pattern);
                List <string>   list       = new List <string>();
                foreach (Match dateMatch in dateMatchs)
                {
                    if (!list.Contains(dateMatch.Value))    //去除重复的匹配项
                    {
                        list.Add(dateMatch.Value);
                        sql = sql.Replace(dateMatch.Value, "to_date(" + dateMatch.Value + ",'yyyy-mm-dd hh24:mi:ss')");
                    }
                }
                MatchCollection predictiontimeMatchs11 = Regex.Matches(sql, monitorTime_pattern);
                list = new List <string>();
                foreach (Match predictiontimeMatch in predictiontimeMatchs11)
                {
                    if (!list.Contains(predictiontimeMatch.Value))
                    {
                        list.Add(predictiontimeMatch.Value);
                        sql = sql.Replace(predictiontimeMatch.Value, "to_char(\"" + predictiontimeMatch.Value.Replace("@", "") + "\",'hh24')");
                    }
                }
                break;

            case SQLConnectionType.PostgreSQL:
                MatchCollection predictiontimeMatchs21 = Regex.Matches(sql, monitorTime_pattern);
                list = new List <string>();
                foreach (Match predictiontimeMatch in predictiontimeMatchs21)
                {
                    if (!list.Contains(predictiontimeMatch.Value))
                    {
                        list.Add(predictiontimeMatch.Value);
                        sql = sql.Replace(predictiontimeMatch.Value, "to_char(\"" + predictiontimeMatch.Value.Replace("@", "") + "\",'hh24')");
                    }
                }
                break;
            }
            return(sql);
        }
Esempio n. 3
0
        /// <summary>
        /// 自定义连接数据库字符串函数
        /// </summary>
        /// <param name="dbServerIP">数据库服务器对应IP</param>
        /// <param name="dbServerPort">数据库服务器对应端口</param>
        /// <param name="dbServerUserId">数据库用户名</param>
        /// <param name="dbServerUserPassword">数据库密码</param>
        /// <param name="providerName">对应数据库类型,PostgreSQL,Oracle,SQLServer</param>
        /// <param name="dbName"></param>
        /// <returns></returns>
        public ConnectionStringSettings GetSQLConnection(string dbServerIP, string dbServerPort, string dbServerUserId, string dbServerUserPassword, string providerName, string dbName)
        {
            ConnectionStringSettings con = new ConnectionStringSettings();

            con.ProviderName = providerName;
            switch (con.ProviderName)
            {
            case "PostgreSQL":
                con.ConnectionString = String.Format("Server={0};Port={1};User Id={2};Password={3};Database={4};Pooling=true;Protocol=3;MinPoolSize=3; MaxPoolSize=20; Encoding=UNICODE; CommandTimeout = 3600; SslMode=Disable", dbServerIP, dbServerPort, dbServerUserId, dbServerUserPassword, dbName);
                break;

            case "Oracle":
                con.ConnectionString = String.Format("Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1})))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));User Id={2};Password={3}", dbServerIP, dbServerPort, dbServerUserId, dbServerUserPassword);
                break;

            case "SQLServer":
                string portFilter = "";
                if (!String.IsNullOrEmpty(dbServerPort))
                {
                    portFilter = "," + dbServerPort;
                }
                con.ConnectionString = String.Format("Data Source={0}{1};User ID={2};Password={3};Initial Catalog={4};Persist Security Info=False;Pooling=true;Connection Lifetime=15;Connect Timeout=120;MAX Pool Size=100;Min Pool Size=1", dbServerIP, portFilter, dbServerUserId, dbServerUserPassword, dbName);
                break;

            case "MySQL":
            case "MySql.Data.MySqlClient":
            case "MySql.Data":
                con.ConnectionString = String.Format("server = {0}; port = {1}; user = {2}; password = {3}; database = {4}; CharSet = utf8", dbServerIP, dbServerPort, dbServerUserId, dbServerUserPassword, dbName);
                break;

            case "Dm":
                sqlConnectionType    = SQLConnectionType.Dm;
                con.ConnectionString = String.Format("server = {0}; port = {1}; user = {2}; password = {3}", dbServerIP, dbServerPort, dbServerUserId, dbServerUserPassword, dbName);
                break;
            }
            return(con);
        }