Пример #1
0
        private static string GetConnectionString(FreeSqlBuilder builder)
        {
            Type      type      = builder.GetType();
            FieldInfo fieldInfo =
                type.GetField("_masterConnectionString", BindingFlags.NonPublic | BindingFlags.Instance);

            if (fieldInfo is null)
            {
                throw new ArgumentException("_masterConnectionString is null");
            }
            return(fieldInfo.GetValue(builder).ToString());
        }
Пример #2
0
        public void FreeSqlBuilderTest()
        {
            FreeSqlBuilder fsql = new FreeSqlBuilder()
                                  .UseConnectionString(DataType.MySql, "Data Source=localhost;Port=3306;User ID=root;Password=root;Initial Catalog=lincms2;Charset=utf8mb4;SslMode=none;Max pool size=1;Connection LifeTime=20")
                                  .UseAutoSyncStructure(true)
                                  .UseNoneCommandParameter(true);


            Type      type      = fsql.GetType();
            FieldInfo fieldInfo = type.GetField("_masterConnectionString", BindingFlags.NonPublic | BindingFlags.Instance);
            string    value     = (string)fieldInfo.GetValue(fsql);

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

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

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

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

            case DataType.SqlServer:
                return(builder.CreateDatabaseIfNotExistsSqlServer(connectionString));

            case DataType.PostgreSQL:
                break;

            case DataType.Oracle:
                break;

            case DataType.Sqlite:
                return(builder);

            case DataType.OdbcOracle:
                break;

            case DataType.OdbcSqlServer:
                break;

            case DataType.OdbcMySql:
                break;

            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(builder);
        }