Beispiel #1
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();
            }
        }
Beispiel #2
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 ReturnNullIfTableDoesNotExistCore(OleDbConnection cn)
        {
            MsAccessSchemaLoader loader = new MsAccessSchemaLoader();

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

            actual.Should().BeNull();
        }
 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)}");
         }
     }
 }
        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));
                }
            }
        }
 /// <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));
        }