public static DbMigrationProvider GetProvider(DbSetting dbSetting)
        {
            DbMigrationProvider provider = null;

            switch (dbSetting.ProviderName)
            {
            case DbConnectionSchema.Provider_SqlClient:
                provider = new SqlServerMigrationProvider();
                break;

            case DbConnectionSchema.Provider_SqlCe:
                provider = new SqlServerCeMigrationProvider();
                break;

            case DbConnectionSchema.Provider_MySql:
                provider = new MySqlMigrationProvider();
                break;

            default:
                if (DbConnectionSchema.IsOracleProvider(dbSetting))
                {
                    provider = new OracleMigrationProvider();
                    break;
                }
                throw new NotSupportedException("This type of database is not supportted now:" + dbSetting.ProviderName);
            }

            provider.DbSetting = dbSetting;

            return(provider);
        }
Exemple #2
0
        public static DbMigrationProvider GetProvider(DbSetting dbSetting)
        {
            DbMigrationProvider provider = null;

            //ISqlConverter Factory
            switch (dbSetting.ProviderName)
            {
            case DbConnectionSchema.Provider_SqlClient:
                provider = new SqlServerMigrationProvider();
                break;

            case DbConnectionSchema.Provider_SqlCe:
                provider = new SqlServerCeMigrationProvider();
                break;

            //Patrickliu增加的代码块
            case DbConnectionSchema.Provider_MySql:
                provider = new MySqlMigrationProvider();
                break;

            //case "System.Data.Odbc":
            //    return new ODBCProvider();
            default:
                if (DbConnectionSchema.IsOracleProvider(dbSetting))
                {
                    provider = new OracleMigrationProvider();
                    break;
                }
                throw new NotSupportedException("This type of database is not supportted now:" + dbSetting.ProviderName);
            }

            provider.DbSetting = dbSetting;

            return(provider);
        }
Exemple #3
0
        protected virtual RdbTable CreateRdbTableCore(IRepositoryInternal repo, string dbProvider)
        {
            switch (dbProvider)
            {
            case DbSetting.Provider_SqlClient:
                return(new SqlServerTable(repo, dbProvider));

            case DbSetting.Provider_SqlCe:
                return(new SqlCeTable(repo, dbProvider));

            case DbSetting.Provider_SQLite:
                return(new SQLiteTable(repo, dbProvider));

            case DbSetting.Provider_MySql:
                return(new MySqlTable(repo, dbProvider));

            default:
                if (DbConnectionSchema.IsOracleProvider(dbProvider))
                {
                    return(new OracleTable(repo, dbProvider));
                }
                break;
            }

            throw new NotSupportedException();
        }
Exemple #4
0
        /// <summary>
        /// 为某个指定的仓库对象构造一个 DbTable
        /// </summary>
        /// <param name="repo"></param>
        /// <returns></returns>
        internal static RdbTable CreateORMTable(IRepositoryInternal repo)
        {
            RdbTable table = null;

            var provider = RdbDataProvider.Get(repo).DbSetting.ProviderName;

            switch (provider)
            {
            case DbSetting.Provider_SqlClient:
                table = new SqlServerTable(repo);
                break;

            case DbSetting.Provider_SqlCe:
                table = new SqlCeTable(repo);
                break;

            case DbSetting.Provider_MySql:
                table = new MySqlTable(repo);
                break;

            default:
                if (DbConnectionSchema.IsOracleProvider(provider))
                {
                    table = new OracleTable(repo);
                    break;
                }
                throw new NotSupportedException();
            }

            table.IdentifierProvider = DbMigrationProviderFactory.GetIdentifierProvider(provider);
            table.DbTypeConverter    = DbMigrationProviderFactory.GetDbTypeConverter(provider);

            var em = repo.EntityMeta;

            foreach (var columnInfo in table.Info.Columns)
            {
                var epm = em.Property(columnInfo.Property);
                if (epm == null)
                {
                    throw new ArgumentNullException(string.Format("{0}.{1} 属性需要使用托管属性进行编写。", table.Info.Class.FullName, columnInfo.Property.Name));
                }

                var column = table.CreateColumn(columnInfo);

                table.Add(column);
            }

            return(table);
        }
Exemple #5
0
        /// <summary>
        /// 把 Sql 和 参数写入到 content 中。
        /// </summary>
        /// <param name="content"></param>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <param name="connectionSchema"></param>
        protected virtual void WriteSqlAndParameters(StringBuilder content, string sql, IDbDataParameter[] parameters, DbConnectionSchema connectionSchema)
        {
            var isOracle = DbConnectionSchema.IsOracleProvider(connectionSchema);

            var pValues = parameters.Select(p =>
            {
                var value = p.Value;
                if (p.DbType == DbType.DateTime || p.DbType == DbType.Date)
                {
                    if (isOracle)
                    {
                        value = string.Format("to_date('{0}', 'yyyy-MM-dd hh24:mi:ss')", value);
                    }
                    else
                    {
                        value = '\'' + value.ToString() + '\'';
                    }
                }
                else if (value is string)
                {
                    value = '\'' + value.ToString() + '\'';
                    //value = '"' + value.ToString() + '"';
                }
                else if (p.DbType == DbType.Boolean)
                {
                    value = Convert.ToByte(value);
                }
                else if (value == null)
                {
                    value = "null";
                }
                return(value);
            }).ToArray();

            if (this.EmbadParameters)
            {
                var toReplace    = isOracle ? @"\:" : "@";
                var formattedSql = Regex.Replace(sql, toReplace + @"p(?<number>\d+)", @"{${number}}");
                content.AppendFormat(formattedSql, pValues);
            }
            else
            {
                content.Append(sql);
                content.AppendLine();
                content.Append("Parameters:").Append(string.Join(",", pValues));
            }
        }
        public static DbIdentifierQuoter GetIdentifierProvider(string providerName)
        {
            switch (providerName)
            {
            case DbConnectionSchema.Provider_SqlClient:
            case DbConnectionSchema.Provider_SqlCe:
                return(SqlServerIdentifierQuoter.Instance);

            case DbConnectionSchema.Provider_MySql:
                return(MySqlIdentifierQuoter.Instance);

            default:
                if (DbConnectionSchema.IsOracleProvider(providerName))
                {
                    return(OracleIdentifierQuoter.Instance);
                }
                throw new NotSupportedException("This type of database is not supportted now:" + providerName);
            }
        }