Beispiel #1
0
        private ISQLHelper GetSQLHelper(SqlAnalyModel model)
        {
            if (model == null || string.IsNullOrWhiteSpace(model.SqlConnStringName))
            {
                throw new Exception(string.Format("数据库连接配置不正确"));
            }
            ISQLHelper sqlHelper = null;

            switch (model.DBType.ToLower())
            {
            case "mysql":
                sqlHelper = new MySqlHelper();
                break;

            case "sqlserver":
                sqlHelper = new SqlServerHelper();
                break;

            default:
                throw new Exception("暂不支持" + model.DBType + "数据库");
            }
            if (!ConnectionStringsDic.ContainsKey(model.SqlConnStringName))
            {
                ConnectionStringsDic[model.SqlConnStringName] = System.Configuration.ConfigurationManager.ConnectionStrings[model.SqlConnStringName].ConnectionString;
            }

            sqlHelper.ConnectionString = ConnectionStringsDic[model.SqlConnStringName];
            if (string.IsNullOrWhiteSpace(sqlHelper.ConnectionString))
            {
                throw new Exception(string.Format("数据库连接地址【{0}】不正确", model.SqlConnStringName));
            }

            return(sqlHelper);
        }
Beispiel #2
0
        public SqlAnalyModel SqlAnaly(Dictionary <string, object> keyValue)
        {
            SqlAnalyModel model = new SqlAnalyModel();

            GetAllParseItem(keyValue);
            model.SqlText = SqlCommand;
            if (keyValue != null && keyValue.ContainsKey("ConnectionPrefix"))
            {
                model.SqlConnStringName = keyValue["ConnectionPrefix"] + SqlConnStringName;
            }
            else
            {
                model.SqlConnStringName = SqlConnStringName;
            }
            //model.SqlConnStringName = SqlConnStringName;
            model.DBType         = SqlDBType;
            model.Assembly       = Assembly;
            model.ModelClassName = ModelClassName;
            model.Timeout        = Timeout;
            if (this.ParentSqlDefinition != null)
            {
                var parentModel = this.ParentSqlDefinition.SqlAnaly(keyValue);
                if (parentModel.SqlText.Trim().LastIndexOf(';') == parentModel.SqlText.Trim().Length - 1)
                {
                    model.SqlText = parentModel.SqlText + model.SqlText;
                }
                else
                {
                    //最后位置找不到 ; 则自动补齐
                    model.SqlText = parentModel.SqlText + ";" + model.SqlText;
                }
            }
            return(model);
        }
        public SqlAnalyModel SqlAnaly(Dictionary <string, object> keyValue)
        {
            SqlAnalyModel model = new SqlAnalyModel();

            GetAllParseItem(_sql, keyValue);
            model.SqlText           = SqlCommand;
            model.SqlConnStringName = SqlConnStringName;
            model.DBType            = SqlDBType;
            return(model);
        }
Beispiel #4
0
 public SqlDefinition(SqlAnalyModel sqlAnaly)
 {
     this.SqlCommand        = sqlAnaly.SqlText;
     this.SqlDBType         = sqlAnaly.DBType;
     this.SqlConnStringName = sqlAnaly.SqlConnStringName;
     this.Assembly          = sqlAnaly.Assembly;
     this.ModelClassName    = sqlAnaly.ModelClassName;
     this.CanEmptyMC        = sqlAnaly.CanEmptyMC;
     this.ReplaceMC         = sqlAnaly.ReplaceMC;
     this.ParamMC           = sqlAnaly.ParamMC;
 }
Beispiel #5
0
        private ISQLHelper GetSQLHelper(SqlAnalyModel model)
        {
            if (model == null)
            {
                throw new Exception(string.Format("数据库连接配置不正确"));
            }

            ISQLHelper sqlHelper = null;

            if (string.IsNullOrWhiteSpace(model.DBType))
            {
                model.DBType = "mysql";
            }
            sqlHelper = new AllHelper();
            //switch (model.DBType.ToLower())
            //{
            //    case "mysql":
            //        sqlHelper = new MySqlHelper();
            //        break;
            //    case "sqlserver":
            //        sqlHelper = new SqlServerHelper();
            //        break;
            //    default:
            //        sqlHelper = new AllHelper();
            //        break;
            //}
            sqlHelper.DBType = model.DBType;
            if (!string.IsNullOrWhiteSpace(model.SqlConnStringName))
            {
                if (!ConnectionStringsDic.ContainsKey(model.SqlConnStringName))
                {
                    ConnectionStringsDic[model.SqlConnStringName] = System.Configuration.ConfigurationManager.ConnectionStrings[model.SqlConnStringName].ConnectionString;
                }

                sqlHelper.ConnectionString = ConnectionStringsDic[model.SqlConnStringName];
            }
            if (string.IsNullOrWhiteSpace(sqlHelper.ConnectionString))
            {
                if (string.IsNullOrWhiteSpace(DefaultConnectionStrings))
                {
                    throw new Exception(string.Format("数据库连接配置不正确"));
                }
                sqlHelper.ConnectionString = DefaultConnectionStrings;
            }

            if (model.Timeout >= 0)
            {
                sqlHelper.Timeout = model.Timeout;
            }
            return(sqlHelper);
        }
Beispiel #6
0
 public SqlDefinition(SqlAnalyModel sqlAnaly)
 {
     if (sqlAnaly.ParentAnaly != null)
     {
         this.ParentSqlDefinition = new SqlDefinition(sqlAnaly.ParentAnaly);
     }
     this.SqlCommand        = sqlAnaly.SqlText;
     this.SqlDBType         = sqlAnaly.DBType;
     this.SqlConnStringName = sqlAnaly.SqlConnStringName;
     this.Assembly          = sqlAnaly.Assembly;
     this.ModelClassName    = sqlAnaly.ModelClassName;
     this.CanEmptyMC        = sqlAnaly.CanEmptyMC;
     this.ReplaceMC         = sqlAnaly.ReplaceMC;
     this.ParamMC           = sqlAnaly.ParamMC;
     this.ParentKey         = sqlAnaly.ParentKey;
     this.Timeout           = sqlAnaly.Timeout;
 }
Beispiel #7
0
        private ISQLHelper GetSQLHelper(SqlAnalyModel model)
        {
            ISQLHelper sqlHelper = null;

            switch (model.DBType.ToLower())
            {
            case "mysql":
                sqlHelper = new MySqlHelper(model.SqlConnStringName);
                break;

            case "sqlserver":
                sqlHelper = new SqlServerHelper(model.SqlConnStringName);
                break;

            default:
                throw new Exception("暂不支持" + model.DBType + "数据库");
            }
            return(sqlHelper);
        }
Beispiel #8
0
        public SqlAnalyModel SqlAnaly(Dictionary <string, object> keyValue)
        {
            SqlAnalyModel model = new SqlAnalyModel();

            GetAllParseItem(keyValue);
            model.SqlText = SqlCommand;
            if (keyValue != null && keyValue.ContainsKey("ConnectionPrefix"))
            {
                model.SqlConnStringName = keyValue["ConnectionPrefix"] + SqlConnStringName;
            }
            else
            {
                model.SqlConnStringName = SqlConnStringName;
            }
            //model.SqlConnStringName = SqlConnStringName;
            model.DBType         = SqlDBType;
            model.Assembly       = Assembly;
            model.ModelClassName = ModelClassName;
            return(model);
        }
Beispiel #9
0
        private void GetXml(FileInfo file)
        {
            IConfigRefresher refresher = new FileInfoConfigRefresher(file.FullName);

            if (!refresher.IsLatest)
            {
                refresher.Refresh(() =>
                {
                    try
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.Load(file.FullName);
                        foreach (XmlNode nodeChild in doc.DocumentElement.ChildNodes)
                        {
                            if (nodeChild.NodeType != XmlNodeType.Element && nodeChild.Name.ToLower() != "data")
                            {
                                continue;
                            }
                            if (nodeChild.Attributes["name"] == null)
                            {
                                continue;
                            }
                            var key = XmlUtility.getNodeAttributeStringValue(nodeChild, "name").ToLower();
                            lock (_SqlLock)
                            {
                                _sqlDic[key]           = nodeChild["SqlDefinition"];
                                _sqlAnalyModelDic[key] = SqlAnalyModel.XmlToSqlAnalyModel(nodeChild["SqlDefinition"]);
                                if (!string.IsNullOrWhiteSpace(_sqlAnalyModelDic[key].ParentKey))
                                {
                                    KeyParentDic[key] = _sqlAnalyModelDic[key].ParentKey;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                });
            }
        }