Example #1
0
        public async Task <ICollection <TableColumn> > GetTableColumns(IDbConnection connection, string tableName)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (string.IsNullOrWhiteSpace(tableName))
            {
                throw new ArgumentNullException(nameof(tableName));
            }

            var columnList = new List <TableColumn>();

            using (var query = queryBuilder.GetTableDescriptionQuery(tableName))
            {
                await connection.EnsureConnected();

                query.Connection = (SqlConnection)connection;
                using (var reader = await query.ExecuteReaderAsync())
                {
                    while (await reader.ReadAsync())
                    {
                        var columnName    = reader[columnNameColumnName] as string;
                        var rawColumnType = reader[dataTypeColumnName] as string;
                        var parsedType    = dataTypeDeterminator.FromDataTypeField(rawColumnType);
                        columnList.Add(new TableColumn(columnName, parsedType));
                    }
                }
            }

            return(columnList);
        }
Example #2
0
        public QueryResult(DbDataReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            if (!reader.CanGetColumnSchema())
            {
                throw new CannotGetColumnSchemaException();
            }

            var columnSchema = reader.GetColumnSchema();

            Columns = new List <QueryResultColumn>(columnSchema.Count());
            for (var columnIndex = 0; columnIndex < columnSchema.Count(); columnIndex++)
            {
                var currentColumn = columnSchema.ElementAt(columnIndex);
                var parsedColumn  = new QueryResultColumn(currentColumn.ColumnName, columnIndex, typeDeterminator.FromDataTypeField(currentColumn.DataTypeName));
                Columns.Add(parsedColumn);
            }

            Rows = new List <QueryResultRow>();
            while (reader.Read())
            {
                var values = new string[columnSchema.Count()];
                for (var columnIndex = 0; columnIndex < columnSchema.Count(); columnIndex++)
                {
                    values[columnIndex] = reader[columnIndex].ToString();
                }
                var parsedRow = new QueryResultRow(values);
                Rows.Add(parsedRow);
            }
        }