Пример #1
0
 public GenerateSql(DbSetting dbSetting)
 {
     if (dbSetting == null) throw new ArgumentNullException("dbSetting");
     this._dbSetting = dbSetting;
     this._db = new DbAccesser(dbSetting);
     datatype = new INIFile();
 }
Пример #2
0
        /// <summary>
        /// 查找或者根据约定创建连接字符串
        /// </summary>
        /// <param name="dbSetting"></param>
        /// <returns></returns>
        public static DbSetting FindOrCreate(string dbSetting)
        {
            if (dbSetting == null) throw new ArgumentNullException("dbSetting");//可以是空字符串。

            DbSetting setting = null;

            if (!_generatedSettings.TryGetValue(dbSetting, out setting))
            {
                lock (_generatedSettings)
                {
                    if (!_generatedSettings.TryGetValue(dbSetting, out setting))
                    {
                        var config = ConfigurationManager.ConnectionStrings[dbSetting];
                        if (config != null)
                        {
                            setting = new DbSetting
                            {
                                ConnectionString = config.ConnectionString,
                                ProviderName = config.ProviderName,
                            };
                        }
                        else
                        {
                            setting = Create(dbSetting);
                        }

                        setting.Name = dbSetting;

                        _generatedSettings.Add(dbSetting, setting);
                    }
                }
            }

            return setting;
        }
Пример #3
0
        public Generate2000Sql(DbSetting dbSetting)
            : base(dbSetting)
        {
            this.sql_tablesInfos = @"SELECT TOP 100 PERCENT --a.id, 
      CASE WHEN a.colorder = 1 THEN d.name ELSE '' END AS 表名, 
      CASE WHEN a.colorder = 1 THEN isnull(f.value, '') ELSE '' END AS 表说明, 
      a.colorder AS 字段序号, a.name AS 字段名, CASE WHEN COLUMNPROPERTY(a.id, 
      a.name, 'IsIdentity') = 1 THEN '√' ELSE '' END AS 标识, 
      CASE WHEN EXISTS
          (SELECT 1
         FROM dbo.sysindexes si INNER JOIN
               dbo.sysindexkeys sik ON si.id = sik.id AND si.indid = sik.indid INNER JOIN
               dbo.syscolumns sc ON sc.id = sik.id AND sc.colid = sik.colid INNER JOIN
               dbo.sysobjects so ON so.name = si.name AND so.xtype = 'PK'
         WHERE sc.id = a.id AND sc.colid = a.colid) THEN '√' ELSE '' END AS 主键, 
      b.name AS 类型, a.length AS 长度, COLUMNPROPERTY(a.id, a.name, 'PRECISION') 
      AS 精度, ISNULL(COLUMNPROPERTY(a.id, a.name, 'Scale'), 0) AS 小数位数, 
      CASE WHEN a.isnullable = 1 THEN '√' ELSE '' END AS 允许空, ISNULL(e.text, '') 
      AS 默认值, ISNULL(g.[value], '') AS 字段说明, d.crdate AS 创建时间, 
      CASE WHEN a.colorder = 1 THEN d.refdate ELSE NULL END AS 更改时间
FROM dbo.syscolumns a LEFT OUTER JOIN
      dbo.systypes b ON a.xtype = b.xusertype INNER JOIN
      dbo.sysobjects d ON a.id = d.id AND d.xtype = 'U' AND 
      d.status >= 0 LEFT OUTER JOIN
      dbo.syscomments e ON a.cdefault = e.id LEFT OUTER JOIN
      dbo.sysproperties g ON a.id = g.id AND a.colid = g.smallid AND 
      g.name = 'MS_Description' LEFT OUTER JOIN
      dbo.sysproperties f ON d.id = f.
id AND f.smallid = 0 AND 
      f.name = 'MS_Description'
 where d.name<>'dtproperties' ";
        }
        /// <summary>
        /// 构造一个本地事务代码块
        /// </summary>
        /// <param name="dbSetting">数据库配置</param>
        /// <param name="level">
        /// 此级别只在最外层的代码块中有效。
        /// </param>
        public LocalTransactionBlock(DbSetting dbSetting, IsolationLevel level)
        {
            this._dbSetting = dbSetting;
            this._level = level;

            var name = LocalContextName(_dbSetting.Database);
            this.EnterScope(name);
        }
        /// <summary>
        /// 构造一个本地事务代码块
        /// </summary>
        /// <param name="dbSetting">数据库配置</param>
        /// <param name="level">
        /// 此级别只在最外层的代码块中有效。
        /// </param>
        public LocalTransactionBlock_1_0(DbSetting dbSetting, IsolationLevel level)
        {
            this._dbSetting = dbSetting;
            this._level = level;

            var tranRef = GetTransactionRef(this._dbSetting.Database, this);

            tranRef.RefCount++;

            this._currentRef = tranRef;
        }
Пример #6
0
        /// <summary>
        /// 添加一个数据库连接配置。
        /// </summary>
        /// <param name="name"></param>
        /// <param name="connectionString"></param>
        /// <param name="providerName"></param>
        public static DbSetting SetSetting(string name, string connectionString, string providerName)
        {
            if (string.IsNullOrEmpty(name)) throw new InvalidOperationException("string.IsNullOrEmpty(dbSetting.Name) must be false.");
            if (string.IsNullOrEmpty(connectionString)) throw new ArgumentNullException("connectionString");
            if (string.IsNullOrEmpty(providerName)) throw new ArgumentNullException("providerName");

            var setting = new DbSetting
            {
                Name = name,
                ConnectionString = connectionString,
                ProviderName = providerName
            };

            lock (_generatedSettings)
            {
                _generatedSettings[name] = setting;
            }

            return setting;
        }
Пример #7
0
        /// <summary>
        /// 查找或者根据约定创建连接字符串
        /// </summary>
        /// <param name="dbSetting"></param>
        /// <returns></returns>
        public static DbSetting FindOrCreate(string dbSetting)
        {
            if (dbSetting == null)
            {
                throw new ArgumentNullException("dbSetting");                   //可以是空字符串。
            }
            DbSetting setting = null;

            if (!_generatedSettings.TryGetValue(dbSetting, out setting))
            {
                lock (_generatedSettings)
                {
                    if (!_generatedSettings.TryGetValue(dbSetting, out setting))
                    {
                        var config = ConfigurationManager.ConnectionStrings[dbSetting];
                        if (config != null)
                        {
                            setting = new DbSetting
                            {
                                ConnectionString = config.ConnectionString,
                                ProviderName     = config.ProviderName,
                            };
                        }
                        else
                        {
                            setting = Create(dbSetting);
                        }

                        setting.Name = dbSetting;

                        _generatedSettings.Add(dbSetting, setting);
                    }
                }
            }

            return(setting);
        }
Пример #8
0
 public static IDbo Factory(DbSetting dbSetting)
 {
     IDbo idb = null;
     idb = new Generate2008Sql(dbSetting);
     return idb;
 }
Пример #9
0
        public Generate2005Sql(DbSetting dbSetting)
            : base(dbSetting)
        {

        }
Пример #10
0
 public LongTimeDbAccesser(DbSetting setting) : base(setting)
 {
 }
Пример #11
0
        //private IDbTransaction _transaction;

        #endregion

        #region Constructor

        /// <summary>
        /// Constructor
        ///
        /// this accessor uses <see cref="DbSetting"/> class to find its connection string, and creates connection by itself.
        /// </summary>
        /// <param name="connectionStringSettingName">the setting name in configuration file.</param>
        public DbAccesser(string connectionStringSettingName)
        {
            var setting = DbSetting.FindOrCreate(connectionStringSettingName);

            this.Init(setting);
        }
Пример #12
0
 public LongTimeDbAccesser(DbSetting setting) : base(setting) { }