Example #1
0
        public void OdbcFreeSqlBuilderTest2()
        {
            FreeSqlBuilder fsqlBuilder2 = new FreeSqlBuilder()
                                          .UseConnectionString(DataType.OdbcSqlServer, "Driver={SQL Server};AttachDBFilename=|DataDirectory|\\AdventureWorks2.mdf;Server=.;Initial Catalog=AdventureWorks2;Uid=sa;Pwd=123456");

            fsqlBuilder2.CreateDatabaseIfNotExists_ODBCSqlServer();
        }
Example #2
0
        public void OdbcFreeSqlBuilderTest()
        {
            //using OdbcConnection cnn = new OdbcConnection("Driver={SQL Server};Server=.;Initial Catalog=master;Uid=sa;Pwd=123456");
            //cnn.Open();

            FreeSqlBuilder fsqlBuilder = new FreeSqlBuilder()
                                         .UseConnectionString(DataType.OdbcSqlServer, "Driver={SQL Server};AttachDBFilename=d:\\db\\File\\AdventureWorks.mdf;Server=.;Initial Catalog=AdventureWorks;Uid=sa;Pwd=123456")
                                         .UseAutoSyncStructure(true)
                                         .UseNoneCommandParameter(true);


            fsqlBuilder.CreateDatabaseIfNotExists_ODBCSqlServer();
        }
        /// <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);
        }