コード例 #1
0
        /// <summary>
        /// 创建实体
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="dbProviderType"></param>
        /// <returns></returns>
        internal static ReflectionBuilder <T> CreateBuilder(IDataReader reader, DbProviderType dbProviderType = DbProviderType.SqlServer)
        {
            ReflectionBuilder <T> result = new ReflectionBuilder <T>();

            result.properties = new PropertyInfo[reader.FieldCount];
            var allProperties = typeof(T).GetProperties();

            for (int i = 0; i < reader.FieldCount; i++)
            {
                if (dbProviderType == DbProviderType.Oracle)
                {
                    //oracle的reader读出来的字段全是大写的,无法和实体类的属性直接匹配上 这是非常f**k的事
                    //所以我们要先匹配一下,不区分大小写
                    var temp = allProperties.Where(p => string.Compare(p.Name, reader.GetName(i), true) == 0).FirstOrDefault();
                    if (temp != null)
                    {
                        result.properties[i] = typeof(T).GetProperty(temp.Name);
                    }
                }
                else
                {
                    result.properties[i] = typeof(T).GetProperty(reader.GetName(i));
                }
            }

            return(result);
        }
コード例 #2
0
        public static DbProviderType ToDbProviderType(this string value)
        {
            DbProviderType dbProviderType = DbProviderType.MSSQL;
            string         a = value.ToUpper();

            if (!(a == "MSSQL"))
            {
                if (!(a == "ORACLE"))
                {
                    if (a == "POSTGRESQL")
                    {
                        dbProviderType = DbProviderType.PostgreSQL;
                    }
                }
                else
                {
                    dbProviderType = DbProviderType.ORACLE;
                }
            }
            else
            {
                dbProviderType = DbProviderType.MSSQL;
            }
            return(dbProviderType);
        }
コード例 #3
0
        /// <summary>
        /// 获取指定数据库类型的DbProviderFactory
        /// </summary>
        /// <param name="providerType"></param>
        /// <returns></returns>
        public static DbProviderFactory GetDbProviderFactory(DbProviderType providerType)
        {
            DbProviderFactory Ada = null;

            switch (providerType)
            {
            case DbProviderType.SQLite:
            {
                // Ada = new SQLiteFactory();
                break;
            }

            case DbProviderType.Oracle:
            {
                Ada = new OracleClientFactory();
                break;
            }

            default:
            {
                Ada = ProviderFactory.ImportDbProviderFactory(providerType);
                break;
            }
            }
            return(Ada);
        }
コード例 #4
0
        public string ToLanguageType(DbProviderType dbProviderType, LanguageType targetLanguage, string dbColumnType)
        {
            Check.NotNullOrEmpty(dbColumnType, nameof(dbColumnType));

            var providerMapping = _mappingsLoader.Get(dbProviderType);

            if (null == providerMapping)
            {
                throw new DbProviderMappingUndefinedException(dbProviderType);
            }

            var columnMapping = providerMapping.Columns
                                .FirstOrDefault(e => e.Source == dbColumnType);

            if (null == columnMapping)
            {
                throw new DbColumnTypeMappingUndefinedException(dbColumnType);
            }

            var languageTypeMapping = columnMapping.Targets
                                      .FirstOrDefault(e => e.Language == targetLanguage.ToString());

            if (null == languageTypeMapping)
            {
                throw new ColumnTypeLanguageMappingUndefinedException(targetLanguage, dbColumnType);
            }

            return(languageTypeMapping.TypeName);
        }
コード例 #5
0
 public static string ToMaxComputeType(
     this IDbTypeConvert dbTypeConvert,
     DbProviderType dbProviderType,
     string dbColumnType)
 {
     return(dbTypeConvert.ToLanguageType(dbProviderType, LanguageType.MaxCompute, dbColumnType));
 }
コード例 #6
0
        //public DbUtility(string connectionString, DbProviderType dbProviderType)
        //{
        //    ConnectionString = connectionString;
        //    providerFactory = ProviderFactory.GetDbProviderFactory(dbProviderType);
        //    if (providerFactory == null)
        //    {
        //        throw new ArgumentException("Can't load DbProviderFactory for given value of providerType");
        //    }
        //}

        public DbUtility(SQLConnModel sqlconModel, DbProviderType dbProviderType)
        {
            this.SqlconModel    = sqlconModel;
            this.DbProviderType = dbProviderType;

            string conStr = null;

            switch (dbProviderType)
            {
            case DbProviderType.MySql:
                conStr           = "server = " + sqlconModel.DBIP + ";uid = " + sqlconModel.DBUser + ";pwd = " + sqlconModel.DBPasswd + ";database = " + sqlconModel.DBName;
                ConnectionString = conStr;
                providerFactory  = ProviderFactory.GetDbProviderFactory(dbProviderType);

                if (providerFactory == null)
                {
                    throw new ArgumentException("Can't load DbProviderFactory for given value of providerType");
                }
                break;

            case DbProviderType.SqlServer:
                conStr = "Data Source= " + sqlconModel.DBIP + "; Initial Catalog = " + sqlconModel.DBName +
                         "; User ID = " + sqlconModel.DBUser + "; Password = "******"Can't load DbProviderFactory for given value of providerType");
                }
                break;
            }
        }
コード例 #7
0
ファイル: DbUtility.cs プロジェクト: chxl800/DbUtilityDemo
        /// <summary>
        /// SqlParameter
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public DbParameter GetParameter(DbProviderType providerType, string name, object value)
        {
            if (value == null)
            {
                value = System.DBNull.Value;
            }

            if (providerType == DbProviderType.SqlServer)
            {
                return(new System.Data.SqlClient.SqlParameter(name, value));
            }
            else if (providerType == DbProviderType.OleDb)
            {
                return(new System.Data.OleDb.OleDbParameter(name, value));
            }
            else
            {
                return(new System.Data.SqlClient.SqlParameter(name, value));
            }
            //System.Data.Odbc.OdbcParameter
            //System.Data.OleDb.OleDbParameter
            //System.Data.OracleClient.OracleParameter
            //System.Data.SqlClient.SqlParameter
            //System.Data.SqlServerCe.SqlCeParameter
        }
コード例 #8
0
		public static DbDataAdapter CreateDataAdapter(DbProviderType DbProviderType, IDbCommand command, IDbConnection connection)
		{
			switch (DbProviderType)
			{
				case DbProviderType.SQLSERVER:
					SqlDataAdapter sqlda = new SqlDataAdapter();
					sqlda.SelectCommand = (SqlCommand) command;
					command.Connection = connection;
					return sqlda;
				case DbProviderType.ORACLE:
					OracleDataAdapter orada = new OracleDataAdapter();
					orada.SelectCommand = (OracleCommand) command;
					command.Connection = connection;
					return orada;
//				case DbProviderType.MYSQL:
//					MySqlDataAdapter mysqlda = new MySqlDataAdapter();
//					mysqlda.SelectCommand = (MySqlCommand) command;
//					command.Connection = connection;
//					return mysqlda;
				default:
					OleDbDataAdapter oleda = new OleDbDataAdapter();
					oleda.SelectCommand = (OleDbCommand) command;
					command.Connection = connection;
					return oleda;
			}
		}
コード例 #9
0
        public static IInsertQuery CreateInsertQuery(string db, DbProviderType provider)
        {
            IInsertQuery query = CreateInsertQuery(db);

            query.DbProviderType = provider;
            return(query);
        }
コード例 #10
0
        public static IDeleteQuery CreateDeleteQuery(string db, DbProviderType provider)
        {
            IDeleteQuery query = CreateDeleteQuery(db);

            query.DbProviderType = provider;
            return(query);
        }
コード例 #11
0
        public static IUpdateQuery CreateUpdateQuery(DbType db, DbProviderType provider)
        {
            IUpdateQuery query = CreateUpdateQuery(db);

            query.DbProviderType = provider;
            return(query);
        }
コード例 #12
0
ファイル: DbProvider4DAL.cs プロジェクト: ztshandong/WebApi
        internal DbProvider4DAL(string procedureName, ChooseDataBase chooseDataBase, DbProviderType dbProviderType)
        {
            CurrentDbProviderType = dbProviderType;
            CurrentChooseDataBase = chooseDataBase;

            CurrentCommand             = ProviderFactory.Instance.GetDbProviderFactory(dbProviderType).CreateCommand();
            CurrentCommand.CommandText = procedureName;
            CurrentCommand.CommandType = CommandType.StoredProcedure;

            CurrentDbDataAdapter = ProviderFactory.Instance.GetDbProviderFactory(dbProviderType).CreateDataAdapter();
            CurrentDbDataAdapter.SelectCommand = CurrentCommand;

            //_CurrentDbProviderType = dbProviderType;
            //_CurrentCommand = ProviderFactory.GetDbProviderFactory(dbProviderType).CreateCommand();
            ////_CurrentConnection = ProviderFactory.GetDbProviderFactory(dbProviderType).CreateConnection();
            //_CurrentDbDataAdapter = ProviderFactory.GetDbProviderFactory(dbProviderType).CreateDataAdapter();
            //_CurrentConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings[ConnectionString].ConnectionString;

            //_CurrentCommand.CommandType = CommandType.StoredProcedure;

            //_CurrentDbDataAdapter.SelectCommand = ProviderFactory.GetDbProviderFactory(dbProviderType).CreateCommand();
            //_CurrentDbDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;
            ////_CurrentDbDataAdapter.InsertCommand = ProviderFactory.GetDbProviderFactory(dbProviderType).CreateCommand();
            ////_CurrentDbDataAdapter.UpdateCommand = ProviderFactory.GetDbProviderFactory(dbProviderType).CreateCommand();
            ////_CurrentDbDataAdapter.DeleteCommand = ProviderFactory.GetDbProviderFactory(dbProviderType).CreateCommand();

            ////_CurrentDbDataAdapter.InsertCommand.CommandType = CommandType.Text;
            ////_CurrentDbDataAdapter.UpdateCommand.CommandType = CommandType.Text;
            ////_CurrentDbDataAdapter.DeleteCommand.CommandType = CommandType.Text;
        }
コード例 #13
0
 public static string ToCSharpType(
     this IDbTypeConvert dbTypeConvert,
     DbProviderType dbProviderType,
     string dbColumnType)
 {
     return(dbTypeConvert.ToLanguageType(dbProviderType, LanguageType.CSharp, dbColumnType));
 }
コード例 #14
0
		/// <summary>
		/// Builds the DatabaseSchema for a specified database
		/// </summary>
		/// <param name="connectionString">The OleDb connection to use</param>
		/// <param name="providerType">The DbProviderType to set the DatabaseSchema to</param>
		/// <returns></returns>
		public static DatabaseSchema CreateDatabaseSchema(string connectionString, Adapdev.Data.DbType databaseType, DbProviderType providerType, string schemaFilter, Adapdev.IProgressCallback progress)
		{
			int recordCount = 0;
			_callback = progress as Adapdev.IProgressCallback;

			if (_callback != null) {
				_callback.SetText("Obtaining Schema Details","");
				_callback.SetAutoClose(ProgressAutoCloseTypes.WaitOnError);
			}

			DatabaseSchema ds = null;
			switch(providerType)
			{
				case DbProviderType.OLEDB:
				case DbProviderType.SQLSERVER:
				case DbProviderType.ORACLE:
					ds = new OleDbSchemaBuilder(_callback, ref recordCount).BuildDatabaseSchema(connectionString, databaseType, providerType, schemaFilter);
					break;
//				case DbProviderType.MYSQL:
//					ds = new MySqlSchemaBuilder(_callback, ref recordCount).BuildDatabaseSchema(connectionString, databaseType, providerType, schemaFilter);
//					break;
			}

			return ds;
		}
コード例 #15
0
        public async Task <List <TableDto> > GetSchemaAsync(
            DbProviderType dbProviderType,
            string connectionString,
            string dbName,
            string dbSchema = null)
        {
            Logger.LogInformation($"---- 数据库类型:{dbProviderType.ToString()}, 开始读取. ----");
            var dtoTables = new List <TableDto>();

            try
            {
                _dbProviderManager.TryGet(dbProviderType, out var dbProvider);
                if (null == dbProvider)
                {
                    Logger.LogInformation($"----数据库类型:{dbProviderType.ToString()} 对应的Provider未找到! ----");
                    return(null);
                }

                var tables = await GetSchemaByDbProviderAsync(dbProvider, connectionString, dbName, dbSchema);

                Logger.LogInformation($"---- 数据库类型:{dbProviderType.ToString()}, 结束读取. ----");

                dtoTables = _objectMapper.Map <List <Table>, List <TableDto> >(tables);
                return(dtoTables);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "读取数据库Schema发生异常.");
            }

            return(dtoTables);
        }
コード例 #16
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="providerType">The specified provider type</param>
		/// <param name="databaseType">The specified database type</param>
		/// <param name="tableName">The table being accessed</param>
		/// <param name="connectionString">The specified connection string</param>
		public AbstractDAO(DbProviderType providerType, DbType databaseType, string tableName, string connectionString)
		{
			this.provider = providerType;
			this.db = databaseType;
			this.table = tableName;
			this.connectionString = connectionString;
		}
コード例 #17
0
        public static ISelectQuery CreateSelectQuery(DbType db, DbProviderType provider)
        {
            ISelectQuery query = CreateSelectQuery(db);

            query.DbProviderType = provider;
            return(query);
        }
コード例 #18
0
ファイル: DbConfig.cs プロジェクト: zhaoxf101/Friend
        public DbConfig(string dbId, string dbName, DbProviderType dbProviderType, string dbParam)
        {
            bool flag = string.IsNullOrEmpty(dbId);

            if (flag)
            {
                throw new Exception("数据库编码不允许为空!");
            }
            bool flag2 = dbProviderType == DbProviderType.NULL;

            if (flag2)
            {
                throw new Exception("数据库存储引擎未指定或不支持!");
            }
            bool flag3 = string.IsNullOrEmpty(dbParam);

            if (flag3)
            {
                throw new Exception("数据库连接参数未配置");
            }
            this.DbId         = dbId;
            this.DbName       = dbName;
            this.ProviderType = dbProviderType;
            this.DbParam      = dbParam;
        }
コード例 #19
0
        /// <summary>
        /// 根据连接字符串, 创建AdoNetHelper子类实例。
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="dbname"></param>
        /// <returns></returns>
        protected static AdoNetHelper CreateInstance(string connectionString, DbProviderType provider)
        {
            AdoNetHelper helper = null;

            switch (provider)
            {
            case DbProviderType.Odbc:
                helper = new OdbcHelper(connectionString, provider);
                break;

            case DbProviderType.OleDb:
                helper = new OleDbHelper(connectionString, provider);
                break;

            case DbProviderType.Oracle_MS:
                helper = new OracleHelper(connectionString, provider);
                break;

            case DbProviderType.Oracle_ManagedODP:
                helper = new OracleHelper_ManagedODP(connectionString, provider);
                break;

            case DbProviderType.SqlServer:
                helper = new SqlHelper(connectionString, provider);
                break;
            }
            return(helper);
        }
コード例 #20
0
ファイル: BaseDao.cs プロジェクト: EconaDev/SouthStarTitle
 protected BaseDao(DbProviderType providerType, DbType databaseType, string tableName, string connectionString)
 {
     Provider         = providerType;
     Db               = databaseType;
     Table            = tableName;
     ConnectionString = connectionString;
 }
コード例 #21
0
ファイル: DbProviderType.cs プロジェクト: zhouzu/sharpdata
        public static string GetProviderName(this DbProviderType type)
        {
            switch (type)
            {
            case DbProviderType.OracleManaged:
                return("Oracle.ManagedDataAccess.Client");

            case DbProviderType.OracleOdp:
                return("Oracle.DataAccess.Client");

            case DbProviderType.MySql:
                return("MySql.Data.MySqlClient");

            case DbProviderType.SqlServer:
                return("System.Data.SqlClient");

            case DbProviderType.SqLite:
                return("Microsoft.Data.Sqlite");

            case DbProviderType.OleDb:
                return("System.Data.OleDb");

            case DbProviderType.PostgreSql:
                return("Npgsql");

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
コード例 #22
0
        /// <summary>
        /// 加载指定数据库类型的DbProviderFactory
        /// </summary>
        /// <param name="providerType">数据库类型枚举</param>
        /// <returns></returns>
        private static DbProviderFactory ImportDbProviderFactory(DbProviderType providerType)
        {
            string providerName = providerInvariantNames[providerType];

A:
            if (!DbProviderFactories.TryGetFactory(providerType.ToString(), out DbProviderFactory factory))
            {
                //var wsd = DbProviderFactories.GetProviderInvariantNames();

                //Assembly assembly = Assembly.Load(providerName);
                //Type type = assembly.GetType("System.Data.SqlClient.SqlClientFactory"); //System.Data.SqlClient.SqlClientFactory

                //AddFactory(providerType, type);//type//"System.Data.SqlClient.SqlClientFactory"

                AddFactory(providerType.ToString(), providerName, true);

                //AddFactory<System.Data.SqlClient.SqlClientFactory>("asd");
                goto A;
            }

            //DbProviderFactory factory;
            //try
            //{
            //    //从全局程序集中查找
            //    factory = DbProviderFactories.GetFactory(providerName);
            //}
            //catch //(ArgumentException e)
            //{
            //    factory = null;
            //}
            return(factory);
        }
コード例 #23
0
        object GetInsertId(DbProviderType type, FluDataAdapter adapter = null, string tableName = null, string seqName = null)
        {
            switch (type)
            {
            case DbProviderType.SqlServer:
            {
                string idSql = ";SELECT SCOPE_IDENTITY();";
                return(idSql);
                //return DataHelper.ExcuteScalar(idSql, type: DbConntionType.WriteRead, adapter: adapter);
            }

            case DbProviderType.MySql:
            {
                string idSql = string.Format(";SELECT LAST_INSERT_ID() AS ID FROM {0} LIMIT 1;", tableName);
                return(idSql);
                //return DataHelper.ExcuteScalar(idSql, type: DbConntionType.WriteRead, adapter: adapter);
            }

            default:
            {
                string seq = string.Format("SELECT {0}.NEXTVAL FROM DUAL", seqName);
                return(DataHelper.ExcuteScalar(seq, type: DbConntionType.WriteRead, adapter: adapter, dbString: DBString));
            }
            }
        }
コード例 #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ProviderName">提供程序名称</param>
        /// <param name="connString">连接字符串</param>
        public CurrencyDBHelper(DbProviderType providerType, string connString)
        {
            string providerName = ProviderFactory.providerInvariantNames[providerType];

            provider         = DbProviderFactories.GetFactory(providerName);
            connectionString = connString;
        }
コード例 #25
0
        /// <summary>
        /// 得到数据提供接口(传参)
        /// </summary>
        public static DataProvider GetDataProvider(string configName)
        {
            if (string.IsNullOrEmpty(configName))
            {
                return(GetDataProvider());
            }
            if (provider2 == null)
            {
                string defaultDataProvider = ConfigurationManager.AppSettings["DefaultDataProvider"];
                string dbConnectString     = ConfigurationManager.AppSettings[configName];
                if (defaultDataProvider == null)
                {
                    defaultDataProvider = "SqlServer";
                }
                if (dbConnectString == null)
                {
                    throw new ArgumentNullException("ConnectString Is Not Exist");
                }
                if (!Enum.IsDefined(typeof(DbProviderType), defaultDataProvider))
                {
                    throw new ArgumentNullException("DefaultDataProvider Is Null");
                }

                DbProviderType dbType = (DbProviderType)Enum.Parse(typeof(DbProviderType), defaultDataProvider);
                provider2 = GetDataProvider(dbType, dbConnectString, true);
            }
            return(provider2);
        }
コード例 #26
0
        private static string GetParamTypeString <T>(this T dataValueObject, DbProviderType DbProvider, List <string> excludeProperties = null)
        {
            string paramType = string.Empty;

            List <string> listColumn    = new List <string>();
            List <string> listColumnout = new List <string>();



            listColumn = dataValueObject.GetParamListName(excludeProperties);


            listColumn.ForEach(ParamName =>
            {
                if (DbProvider == DbProviderType.SqlClient || DbProvider == DbProviderType.MySqlClient)
                {
                    paramType = "@" + ParamName;
                }
                else if (DbProvider == DbProviderType.ODBCClient)
                {
                    paramType = "?";
                }

                listColumnout.Add(paramType);
            });


            return(string.Join(",", listColumnout));
        }
コード例 #27
0
 public DbProvider(DbProviderType dbProviderType, string parameterPrefix, DbProviderFactory factory)
 {
     DbProviderType  = dbProviderType;
     Name            = dbProviderType.ToString();
     ParameterPrefix = parameterPrefix;
     Factory         = factory;
 }
コード例 #28
0
        public void Can_Get_Sql(DbProviderType dbProviderType)
        {
            var result = _sqlLoader.Get(dbProviderType);

            result.ShouldNotBeNull();
            result.Table.ShouldNotBeNullOrEmpty();
            result.Column.ShouldNotBeNullOrEmpty();
        }
コード例 #29
0
 public static DbProviderFactory GetDbProviderFactory(DbProviderType providerType)
 {
     if (!providerFactoies.ContainsKey(providerType))
     {
         providerFactoies.Add(providerType, ImportDbProviderFactory(providerType));
     }
     return(providerFactoies[providerType]);
 }
コード例 #30
0
 /// <summary>
 /// 获取指定数据库类型对应的DbProviderFactory
 /// </summary>
 /// <param name="dbProviderType"></param>
 /// <returns></returns>
 public static DbProviderFactory GetDbProviderFactory(DbProviderType dbProviderType)
 {
     if (!providerFactories.ContainsKey(dbProviderType))  //如果字典中不存在DbProviderFactory,则需要加载
     {
         providerFactories[dbProviderType] = ImportDbProviderFactory(dbProviderType);
     }
     return(providerFactories[dbProviderType]);
 }
コード例 #31
0
 protected AdoNetHelper(DbProviderType providerType)
 {
     DbFactory = ProviderFactory.GetDbProviderFactory(providerType);
     if (DbFactory == null)
     {
         throw new ArgumentException("Can't load DbProviderFactory for given value of providerType");
     }
 }
コード例 #32
0
 /// <summary>
 /// 获取指定类型的数据库对应的DbProviderFactory
 /// </summary>
 /// <param name="providerType">数据库类型枚举</param>
 /// <returns></returns>
 internal static DbProviderFactory GetDbProviderFactory(DbProviderType providerType)
 {
     //如果还没有加载,则加载该DbProviderFactory
     if (!providerFactoies.ContainsKey(providerType))
     {
         providerFactoies.Add(providerType, ImportDbProviderFactory(providerType));
     }
     return(providerFactoies[providerType]);
 }
コード例 #33
0
       /// <summary>
       /// 获取指定类型的数据库对应的DbProviderFactory
       /// </summary>
       /// <param name="providerType">数据库类型枚举</param>
       /// <returns></returns>
       public static DbProviderFactory GetProviderFactory(DbProviderType providerType)
       {
           if (!providerFactoies.ContainsKey(providerType))
           {
               providerFactoies.Add(providerType,ImportDbProviderFactory(providerType));  

           }
           return providerFactoies[providerType];
       }
コード例 #34
0
ファイル: DbUtility.cs プロジェクト: hdlovefork/FMSClient
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="connectionString">数据库连接字符串</param>
 /// <param name="providerType">数据库类型枚举,参见<paramref name="providerType"/></param>
 public DbUtility(string connectionString, DbProviderType providerType)
 {
     ConnectionString = connectionString;
     _providerFactory = ProviderFactory.GetDbProviderFactory(providerType);
     if (_providerFactory == null)
     {
         throw new ArgumentException("Can't load DbProviderFactory for given value of providerType");
     }
 }
コード例 #35
0
        /// <summary>
        /// Creates the db provider.
        /// </summary>
        /// <param name="connectionString">Name of the conn STR.</param>
        /// <returns>The db provider.</returns>
        public static DbProvider CreateDbProvider(DbProviderType providerType, string connectionString)
        {
            string[] assAndClass = EnumDescriptionAttribute.GetDescription(providerType).Split(',');

            DbProvider dbProvider = null;
            if (assAndClass.Length > 1)
                dbProvider = CreateDbProvider(assAndClass[0].Trim(), assAndClass[1].Trim(), connectionString);
            else
                dbProvider = CreateDbProvider(assAndClass[0].Trim(), null, connectionString);

            return dbProvider;
        }
コード例 #36
0
		/// <summary>
		/// Builds a trusted Sql Server connection
		/// </summary>
		/// <param name="type">The DbProviderType</param>
		/// <param name="server">The server</param>
		/// <param name="database">The database</param>
		/// <returns></returns>
		public static string BuildSqlServerTrusted( DbProviderType type, string server, string database ) {
			switch (type) {
			case DbProviderType.ODBC:
				return _databases.ConnectionTypes[ "SQL Server - Trusted" ].Providers[ "ODBC" ].ConnectionString( server, database );
			case DbProviderType.OLEDB:
				return _databases.ConnectionTypes[ "SQL Server - Trusted" ].Providers[ "OLEDB" ].ConnectionString( server, database );
			case DbProviderType.SQLSERVER:
				return _databases.ConnectionTypes[ "SQL Server - Trusted" ].Providers[ "Sql Connect" ].ConnectionString( server, database );
			default:
				throw new Exception( type.ToString() + " is not supported.  Please use DbType.ODBC, DbType.OLEDB or DbType.SQLSERVER" );
			}
		}
コード例 #37
0
 public static IDbProvider CreateProvider(DbProviderType type)
 {
     switch (type)
     {
         case DbProviderType.SqlServer:
             return new SqlServerProvider();
         case DbProviderType.MySql:
             return new MySqlProvider();
         default:
             return new SqlServerProvider();
     }
 }
コード例 #38
0
ファイル: Database.cs プロジェクト: mysteryjeans/CoreSystem
 /// <summary>
 /// Converts to DBMS acceptable datetime format
 /// </summary>
 /// <param name="value">DateTime value</param>
 /// <param name="providerType">DBMS provider type</param>
 /// <returns>Datetime in string format</returns>
 public static string ToDate(DateTime value, DbProviderType providerType)
 {
     switch (providerType)
     {
         case DbProviderType.Oracle:
             string strDate = value.ToString(Database.NetDateFormat);
             return string.Format("TO_DATE('{0}','{1}')", strDate, Database.OracleDateFormat);
         case DbProviderType.SqlServer:
             return string.Format("CONVERT(DATETIME,'{0}',120)", value.ToString(Database.SqlDateFormat));
         default:
             throw new DbDataException("Failed to convert Date for provider [{0}]", providerType);
     }
 }
コード例 #39
0
		/// <summary>
		/// Creates an IDbConnection implementation for the specified DbProviderType
		/// </summary>
		/// <param name="DbProviderType"></param>
		/// <returns></returns>
		public static IDbConnection CreateConnection(DbProviderType DbProviderType)
		{
			switch (DbProviderType)
			{
				case DbProviderType.SQLSERVER:
					return new SqlConnection();
				case DbProviderType.ORACLE:
					return new OracleConnection();
//				case DbProviderType.MYSQL:
//					return new MySqlConnection();
				default:
					return new OleDbConnection();
			}
		}
コード例 #40
0
 /// <summary>
 /// 加载指定数据库类型的DbProviderFactory 
 /// </summary>
 /// <param name="providerType">数据库类型枚举</param>
 /// <returns></returns>
 private static DbProviderFactory ImportDbProviderFactory(DbProviderType providerType)
 {
     string providerName = providerInvariantNames[providerType];
     DbProviderFactory factory = null;
     try
     {
         //从全局程序集中查找  
         factory = DbProviderFactories.GetFactory(providerName);
     }
     catch(ArgumentException e)
     {
         factory = null;
     }
     return factory;
 }
コード例 #41
0
		/// <summary>
		/// Returns the fully filled-in sql text for a specified IDbCommand
		/// </summary>
		/// <param name="cmd"></param>
		/// <param name="providerType"></param>
		/// <returns></returns>
		public static string Parse(IDbCommand cmd, DbProviderType providerType)
		{
			if (providerType == DbProviderType.OLEDB) 
			{
				return ParseOleDbCommand(cmd);
			}
			else if (providerType == DbProviderType.SQLSERVER)
			{
				return ParseSqlCommand(cmd);
			}
			else if (providerType == DbProviderType.ORACLE) {
				return ParseOracleCommand(cmd);
			}
			else 
				throw new NotImplementedException(providerType.ToString() + " is not currently supported.");
		}
コード例 #42
0
ファイル: Dbhelper.cs プロジェクト: nkaluva/helper
        public DbHelper(string connectionString, DbProviderType providerType)
        {
            string providername = "System.Data.SqlClient";
            if (providerType == DbProviderType.MySql)
            {
                providername = "MySql.Data.MySqlClient";
            }
            else if (DbProviderType.Oledb == providerType)
            {
                providername = "System.Data.OleDb";
            }

            DbConnectionString = connectionString;
            DbProviderName = providername;
            if (string.IsNullOrEmpty(DbConnectionString) || string.IsNullOrEmpty(DbProviderName))
                throw new Excep.HelperException("database connectionstring can't be null.");
        }
コード例 #43
0
		public static string Convert(DbProviderType t) {

			switch (t) {
				case DbProviderType.UNKNOWN:
					return "UNKNOWN";
				case DbProviderType.ODBC:
					return "ODBC";
				case DbProviderType.OLEDB:
					return "OLEDB";
				case DbProviderType.ORACLE:
					return "ORACLE";
				case DbProviderType.SQLSERVER:
					return "SQLSERVER";
				case DbProviderType.MYSQL:
					return "MYSQL";
				case DbProviderType.DB2:
					return "DB2";
				default:
					throw new Exception("DbProviderType " + t.ToString() + " not found.");
			}
		}
コード例 #44
0
		/// <summary>
		/// Builds the DatabaseSchema for a specified database
		/// </summary>
		/// <param name="oledbConnectionString">The OleDb connection to use</param>
		/// <returns></returns>
		public static DatabaseSchema CreateDatabaseSchema(string oledbConnectionString, Adapdev.Data.DbType databaseType, DbProviderType providerType)
		{
			return SchemaBuilder.CreateDatabaseSchema(oledbConnectionString, databaseType, providerType, "", null);
		}
コード例 #45
0
		/// <summary>
		/// Gets the object by id.
		/// </summary>
		/// <param name="ct">Ct.</param>
		/// <param name="id">Id.</param>
		/// <returns></returns>
		public string GetObjectById(DbProviderType ct, int id)
		{
			return this.GetObjectById(ct.ToString(), id);
		}
コード例 #46
0
		public static DataSet CreateDataSet(IDbConnection connection, IDbCommand command, DbProviderType DbProviderType)
		{
			DataSet ds = new DataSet();
			DbDataAdapter da = DbProviderFactory.CreateDataAdapter(DbProviderType, command, connection);
			connection.Open();
			da.Fill(ds);
			connection.Close();
			return ds;
		}
コード例 #47
0
		public static DataTable CreateDataTable(string connection, IDbCommand command, DbProviderType DbProviderType)
		{
			throw new NotImplementedException();
		}
コード例 #48
0
		public static IDataReader CreateDataReader(IDbConnection connection, IDbCommand command, DbProviderType DbProviderType)
		{
			return CreateDataReader(connection, command, CommandBehavior.Default, DbProviderType);
		}
コード例 #49
0
		public static IDataReader CreateDataReader(IDbConnection connection, IDbCommand command, CommandBehavior behavior, DbProviderType DbProviderType)
		{
			IDataReader reader = null;
			command.Connection = connection;
			reader = command.ExecuteReader(behavior);

			return reader;
		}
コード例 #50
0
		public UpdateQuery(DbType type, DbProviderType provider, string tableName) : this(type, provider)
		{
			this.SetTable(tableName);
		}
コード例 #51
0
		public static IDataReader CreateDataReader(IDbConnection connection, string command, DbProviderType DbProviderType)
		{
			IDbCommand cmd = DbProviderFactory.CreateCommand(DbProviderType);
			cmd.CommandText = command;

			return CreateDataReader(connection, cmd, DbProviderType);
		}
コード例 #52
0
		/// <summary>
		/// Builds a connection string for an Access database
		/// </summary>
		/// <param name="type">The DbProviderType to use</param>
		/// <param name="filePath">The file path to the database</param>
		/// <param name="password">The database password</param>
		/// <param name="userid">The database userid</param>
		/// <returns></returns>
		public static string BuildAccess( DbProviderType type, string filePath, string userid, string password ) {
			return _databases.ConnectionTypes[ "ACCESS" ].Providers[ "OLEDB" ].ConnectionString( filePath, userid, password );
		}
コード例 #53
0
		/// <summary>
		/// Gets the object by name
		/// </summary>
		/// <param name="providerType">Provider type</param>
		/// <param name="typeName">Name of the type.</param>
		/// <returns></returns>
		public string GetObjectByName(DbProviderType providerType, string typeName)
		{
			return this.GetObjectByName(providerType.ToString(), typeName);
		}
コード例 #54
0
		/// <summary>
		/// Gets the prefix by name
		/// </summary>
		/// <param name="ct">Ct.</param>
		/// <param name="typeName">Name of the type.</param>
		/// <returns></returns>
		public string GetPrefixByName(DbProviderType ct, string typeName)
		{
			return this.GetPrefixByName(ct.ToString(), typeName);
		}
コード例 #55
0
		/// <summary>
		/// Gets the name of the id by.
		/// </summary>
		/// <param name="providerType">Provider type.</param>
		/// <param name="typeName">Name of the type.</param>
		/// <returns></returns>
		public int GetIdByName(DbProviderType providerType, string typeName)
		{
			return this.GetIdByName(providerType.ToString(), typeName);
		}
コード例 #56
0
		/// <summary>
		/// Gets the test default by id.
		/// </summary>
		/// <param name="providerType">Provider type.</param>
		/// <param name="id">Id.</param>
		/// <returns></returns>
		public string GetTestDefaultById(DbProviderType providerType, int id)
		{
			return this.GetTestDefaultById(providerType.ToString(), id);
		}
コード例 #57
0
		public static ISelectQuery CreateSelectQuery(DbType db, DbProviderType provider)
		{
			ISelectQuery query = QueryFactory.CreateSelectQuery(db);
			query.DbProviderType = provider;
			return query;
		}
コード例 #58
0
		public static IDataReader CreateDataReader(string connectionString, IDbCommand command, DbProviderType DbProviderType)
		{
			IDbConnection connection = DbProviderFactory.CreateConnection(DbProviderType);
			connection.ConnectionString = connectionString;

			return CreateDataReader(connection, command, DbProviderType);
		}
コード例 #59
0
		/// <summary>
		/// Gets the name by id.
		/// </summary>
		/// <param name="providerType">Provider type.</param>
		/// <param name="id">Id.</param>
		/// <returns></returns>
		public string GetNameById(DbProviderType providerType, int id)
		{
			return this.GetNameById(providerType.ToString(), id);
		}
コード例 #60
0
		public static IDeleteQuery CreateDeleteQuery(string db, DbProviderType provider)
		{
			IDeleteQuery query = QueryFactory.CreateDeleteQuery(db);
			query.DbProviderType = provider;
			return query;
		}