Exemple #1
0
        private bool ReadRows(DbDataReader rdr, DatabaseInserter inserter, DatabaseTable databaseTable, SqlWriter destinationSql)
        {
            if (!rdr.HasRows)
            {
                return(true);
            }
            int i = 0;

            while (rdr.Read() && i < _maxiumumRecords)
            {
                //we only do the first 1000 rows. This is for small databases only!
                i++;
                var result = CopyRow(databaseTable, destinationSql, rdr, inserter);
                //if there's a problem, stop doing anything
                if (!result)
                {
                    LastErrorMessage = inserter.LastErrorMessage;
                    return(false);
                }
            }
            Debug.WriteLine(databaseTable.Name + " copied " + i + " rows");
            return(true);
        }
Exemple #2
0
        private static bool CopyRow(DatabaseTable databaseTable, SqlWriter destinationSql, DbDataReader rdr, DatabaseInserter inserter)
        {
            var dictionary = new Dictionary <string, object>();

            if (rdr.FieldCount != databaseTable.Columns.Count)
            {
                //something has gone wrong
                return(false);
            }
            for (int index = 0; index < databaseTable.Columns.Count; index++)
            {
                var column        = databaseTable.Columns[index];
                var parameterName = destinationSql.ParameterName(column.Name);
                var value         = rdr.GetValue(index);
                //we don't care about DBNull here
                dictionary.Add(parameterName, value);
            }
            return(inserter.Insert(dictionary));
        }