public void CreateDatabaseIfNotExists_ODBCMySql_Test() { FreeSqlBuilder fsqlBuilder2 = new FreeSqlBuilder() .UseConnectionString(DataType.OdbcMySql, "Driver={MySQL ODBC 8.0 Unicode Driver}; Server=127.0.0.1;Port=3308;Persist Security Info=False; Trusted_Connection=Yes;UID=root;PWD=123456; DATABASE=cccddd_odbc;Charset=utf8; SslMode=none;Min Pool Size=1"); fsqlBuilder2.CreateDatabaseIfNotExists_ODBCMySql(); }
/// <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: break; 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); }