private void LoadCorrectTableSchemaCore(OleDbConnection cn)
        {
            MsAccessSchemaLoader loader = new MsAccessSchemaLoader();
            DatabaseSchema       schema = loader.LoadSchema(cn);

            CheckTableSchema(schema.Tables[TestSchemaTableName]);
        }
        private void ReturnNullIfTableDoesNotExistCore(OleDbConnection cn)
        {
            MsAccessSchemaLoader loader = new MsAccessSchemaLoader();

            TableSchema actual = loader.LoadTableSchema(cn, InvalidTableName);

            actual.Should().BeNull();
        }
예제 #3
0
 private void InitBulkInsert(string dataFilePath, IDataReader data)
 {
     using (StreamWriter schemaFile = InitSchemaFile(dataFilePath))
     {
         var         schemaLoader = new MsAccessSchemaLoader();
         TableSchema tableSchema  = schemaLoader.LoadTableSchema(_connection, DestinationTableName);
         for (int i = 0; i < data.FieldCount; i++)
         {
             MsAccessColumnSchema column = tableSchema.Columns[data.GetName(i)] as MsAccessColumnSchema;
             Columns.Add(column);
             int colNumber = i + 1;
             schemaFile.WriteLine($"Col{colNumber}=F{colNumber} {GetColumnDataType(column)}");
         }
     }
 }
예제 #4
0
        public void CreateTableForIdGeneratorIfNotExits()
        {
            const string tableName = "IdStore";

            using (var helper = CreateHelperWithEmptyDatabase())
            {
                var schemaLoader = new MsAccessSchemaLoader();
                schemaLoader.LoadTableSchema(helper.Connection, tableName).Should().BeNull();

                var idGenerator = new MsAccessIdGenerator(helper.Connection, "TestTable", 1);
                idGenerator.InitDatabaseForIdGenerator();

                schemaLoader.LoadTableSchema(helper.Connection, tableName).Should().NotBeNull();
            }
        }
예제 #5
0
        public void NotThrowWhenCreatingTableAndStoredProcedureForIdGeneratorAndTheyExist()
        {
            const string tableName = "IdStore";

            using (var helper = CreateHelperWithEmptyDatabase())
            {
                var schemaLoader = new MsAccessSchemaLoader();

                var idGenerator = new MsAccessIdGenerator(helper.Connection, "TestTable", 1);
                idGenerator.InitDatabaseForIdGenerator();
                schemaLoader.LoadTableSchema(helper.Connection, tableName).Should().NotBeNull();

                idGenerator.InitDatabaseForIdGenerator();
                schemaLoader.LoadTableSchema(helper.Connection, tableName).Should().NotBeNull();
            }
        }
        private void LoadCorrectIndexesCore(OleDbConnection cn)
        {
            MsAccessSchemaLoader loader = new MsAccessSchemaLoader();
            DatabaseSchema       schema = loader.LoadSchema(cn);
            TableSchema          table  = schema.Tables["IndexesTest"];

            table.PrimaryKey.Should().NotBeNull();
            CheckIndex(table.PrimaryKey, IndexType.PrimaryKey,
                       new Tuple <string, SortOrder>[] { Tuple.Create("Id", SortOrder.Ascending) });
            CheckIndex(table.Indexes["I_Index"], IndexType.Index, new Tuple <string, SortOrder>[] {
                Tuple.Create("ColIndex1", SortOrder.Ascending),
                Tuple.Create("ColIndex2Desc", SortOrder.Descending),
                Tuple.Create("ColIndex3", SortOrder.Ascending)
            });
            CheckIndex(table.Indexes["I_UniqueIndex"], IndexType.UniqueKey,
                       new Tuple <string, SortOrder>[] { Tuple.Create("ColUniqueIndex", SortOrder.Ascending) });
        }
        private void InitExplicitSchemaColumns(StreamWriter schemaFile)
        {
            var         schemaLoader = new MsAccessSchemaLoader();
            TableSchema tableSchema  = schemaLoader.LoadTableSchema(_connection, DestinationTableName);

            for (int columnNumber = 0; columnNumber < ColumnMappings.Count; columnNumber++)
            {
                MsAccessColumnSchema     databaseColumn   = null;
                MsAccessBulkInsertColumn bulkInsertColumn = _columns[columnNumber];
                BulkInsertColumnMapping  mapping          = bulkInsertColumn.Mapping;
                if (!string.IsNullOrWhiteSpace(mapping.DestinationName))
                {
                    if (tableSchema.Columns.Contains(mapping.DestinationName))
                    {
                        databaseColumn = (MsAccessColumnSchema)tableSchema.Columns[mapping.DestinationName];
                    }
                    else
                    {
                        ThrowExceptionInvalidDestinationColumnMapping(columnNumber, null, mapping.DestinationName);
                    }
                }
                else if (mapping.DestinationOrdinal >= 0)
                {
                    if (mapping.DestinationOrdinal >= tableSchema.Columns.Count)
                    {
                        ThrowExceptionInvalidDestinationColumnMapping(columnNumber, mapping.DestinationOrdinal);
                    }
                    else
                    {
                        databaseColumn = (MsAccessColumnSchema)tableSchema.Columns[mapping.DestinationOrdinal];
                    }
                }
                else
                {
                    ThrowExceptionInvalidDestinationColumnMapping(columnNumber);
                }
                bulkInsertColumn.DestinationColumnName = databaseColumn.Name;
                bulkInsertColumn.ColumnType            = GetBulkInsertColumnType(databaseColumn);
                WriteSchemaColumnInfo(schemaFile, columnNumber + 1, databaseColumn);
            }
        }
        private void InitImplicitSchemaColumns(StreamWriter schemaFile, IDataReader data)
        {
            var         schemaLoader = new MsAccessSchemaLoader();
            TableSchema tableSchema  = schemaLoader.LoadTableSchema(_connection, DestinationTableName);

            for (int columnNumber = 0; columnNumber < data.FieldCount; columnNumber++)
            {
                string columnName = data.GetName(columnNumber);
                if (tableSchema.Columns.Contains(columnName))
                {
                    MsAccessColumnSchema column = (MsAccessColumnSchema)tableSchema.Columns[columnName];
                    _columns.Add(new MsAccessBulkInsertColumn(columnName, column.Name, GetBulkInsertColumnType(column)));
                    WriteSchemaColumnInfo(schemaFile, columnNumber + 1, column);
                }
                else
                {
                    throw new InvalidOperationException(
                              string.Format(Resources.BulkInsertColumnDoesNotExistInDestination, columnName));
                }
            }
        }
예제 #9
0
 /// <inheritdoc/>
 public override void InitDatabaseForIdGenerator()
 {
     using (ConnectionHelper.OpenConnection(Connection))
     {
         var schemaLoader = new MsAccessSchemaLoader();
         if (schemaLoader.LoadTableSchema((OleDbConnection)Connection, "IdStore") == null)
         {
             using (var cmd = Connection.CreateCommand())
             {
                 string[] sqlCommands = GetIdStoreTableCreationScript()
                                        .Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                 foreach (string sqlCommand in sqlCommands)
                 {
                     string query = sqlCommand.Trim();
                     if (!string.IsNullOrEmpty(query))
                     {
                         cmd.CommandText = query;
                         cmd.ExecuteNonQuery();
                     }
                 }
             }
         }
     }
 }
        private void LoadCorrectTableSchemaCore2(OleDbConnection cn)
        {
            MsAccessSchemaLoader loader = new MsAccessSchemaLoader();

            CheckTableSchema(loader.LoadTableSchema(cn, TestSchemaTableName));
        }