Пример #1
0
        /// <summary>
        /// 请在UseConnectionString配置后调用此方法
        /// </summary>
        /// <param name="this"></param>
        /// <returns></returns>
        public static FreeSqlBuilder CreateDatabaseIfNotExists(this FreeSqlBuilder @this)
        {
            FieldInfo dataTypeFieldInfo = @this.GetType().GetField("_dataType", BindingFlags.NonPublic | BindingFlags.Instance);

            if (dataTypeFieldInfo is null)
            {
                throw new ArgumentException("_dataType is null");
            }

            string   connectionString = GetConnectionString(@this);
            DataType dbType           = (DataType)dataTypeFieldInfo.GetValue(@this);

            switch (dbType)
            {
            case DataType.MySql:
                return(@this.CreateDatabaseIfNotExistsMySql(connectionString));

            case DataType.SqlServer:
                return(@this.CreateDatabaseIfNotExistsSqlServer(connectionString));

            case DataType.PostgreSQL:
                return(@this.CreateDatabaseIfNotExistsPgSql(connectionString));

            case DataType.Oracle:
                break;

            case DataType.Sqlite:
                return(@this);

            case DataType.OdbcOracle:
                break;

            case DataType.OdbcSqlServer:
                return(@this.CreateDatabaseIfNotExists_ODBCSqlServer(connectionString));

            case DataType.OdbcMySql:
                return(@this.CreateDatabaseIfNotExists_ODBCMySql(connectionString));

            case DataType.OdbcPostgreSQL:
                break;

            case DataType.Odbc:
                break;

            case DataType.OdbcDameng:
                break;

            case DataType.MsAccess:
                break;

            case DataType.Dameng:
                break;

            case DataType.OdbcKingbaseES:
                break;

            case DataType.ShenTong:
                break;

            case DataType.KingbaseES:
                break;

            case DataType.Firebird:
                break;

            default:
                break;
            }

            Log.Error($"不支持创建数据库");
            return(@this);
        }