예제 #1
0
        private void initSqlHelper(string _providerName)
        {
            _cacheService    = new MemoryCacheService();
            _events          = new SqlEvents();
            _tableNameManger = new TableNameManger();
            _sqlConfig       = new SqlConfig(this);
            _sql             = new SqlRecord();
            _sqlMonitor      = new NullSqlMonitor();
            _sql.SqlMonitor  = _sqlMonitor;


            _connectionType = ConnectionType.Default;

            if (_providerName != null)
            {
                _sqlType = SqlConfig.GetSqlType(_providerName, _writeConnectionString);
                var _provider = DatabaseProvider.Resolve(_sqlType);
                _factory = _provider.GetFactory();
            }
            else
            {
                _sqlType = SqlConfig.GetSqlType(_factory.GetType().FullName, _writeConnectionString);
            }

            _provider = DatabaseProvider.Resolve(_sqlType);
        }
예제 #2
0
        /// <summary>
        /// SqlHelper 构造方法
        /// </summary>
        /// <param name="connectionString">数据库链接字符串</param>
        /// <param name="factory">provider工厂</param>
        /// <param name="type"></param>
        public SqlHelper(string connectionString, DbProviderFactory factory, SqlType type)
        {
            _sqlType = type;
            _factory = factory;

            _events           = new SqlEvents(this);
            _connectionString = connectionString;
            _sqlConfig        = new SqlConfig(this);
            _provider         = DatabaseProvider.Resolve(_sqlType);
        }
예제 #3
0
        private void initSqlHelper(string connectionString, string providerName)
        {
            _lastConnectionString = connectionString;
            _lastProviderName     = providerName;

            _connectionString = connectionString;
            var txts = connectionString.Split(';');

            foreach (var txt in txts)
            {
                var sp = txt.Split('=');
                if (sp.Length != 2)
                {
                    continue;
                }
                if (sp[0].ToLower() == "database")
                {
                    _schemaName = sp[1];
                    break;
                }
                if (sp[0].ToLower() == "data source")
                {
                    _schemaName = sp[1];
                    break;
                }
            }


            _cacheService = new MemoryCacheService();
            _events       = new SqlEvents();
            _sqlConfig    = new SqlConfig(this);
            _sql          = new SqlRecord();
            _sqlMonitor   = new NullSqlMonitor();


            if (_sqlType == SqlType.None)
            {
                _sqlType = DatabaseProvider.GetSqlType(providerName ?? _factory.GetType().FullName, _connectionString);
            }
            _provider = DatabaseProvider.Resolve(_sqlType);
            if (_factory == null)
            {
                _factory     = _provider.GetFactory();
                _lastFactory = _factory;
            }
            if (_lastSqlHelper == null || _lastSqlHelper._isDisposable)
            {
                _lastSqlHelper = this;
            }
        }