/// <summary> /// Creates a database table binary data reader /// </summary> /// <param name="table">table</param> /// <param name="handler">query handler</param> public DbTableBinDataReader(DbTable table, DbQueryHandler handler = null) : base(table, handler) { reader = new io.BinaryReader(io.File.OpenRead(Path)); //build column type translator ColumnTypeSizes = Table.ColumnTypes.Select(t => t.GetSize()).ToArray(); }
/// <summary> /// creates a database visualizer, must be disposed to release resources /// </summary> /// <param name="db">database</param> /// <param name="query">parsed sql query</param> /// <param name="options">visualize options</param> public DbVisualizer(CsvDb db, DbQuery query, DbVisualize options = DbVisualize.Paged) { //reader = DbRecordReader.Create(db, query); handler = new DbQueryHandler(db, query); Options = options; }
/// <summary> /// free reader resources /// </summary> public void Dispose() { if (handler != null) { handler.Dispose(); handler = null; } }
/// <summary> /// call generic class /// </summary> /// <typeparam name="T"></typeparam> /// <param name="handler"></param> /// <param name="columnOperand"></param> /// <param name="oper"></param> /// <param name="constantOperand"></param> /// <returns></returns> IEnumerable <int> ExecuteColumnExpression <T>(DbQueryHandler handler, DbQuery.ColumnOperand columnOperand, TokenType oper, DbQuery.ConstantOperand constantOperand) where T : IComparable <T> { var executer = new DbQueryExpressionExecuter <T>(handler, columnOperand, oper, constantOperand); return(executer.Execute().SelectMany(pair => pair.Value)); }
/// <summary> /// Creates a database data table reader /// </summary> /// <param name="table">table</param> /// <param name="handler">query handler</param> internal DbTableDataReader(DbTable table, DbQueryHandler handler = null) { Handler = handler; if ((Table = table) == null) { throw new ArgumentException("cannot read table data from undefined table"); } //default to CSV var extension = table.Database.IsBinary ? CsvDb.SchemaTableDataExtension : CsvDb.SchemaTableDefaultExtension; //path to table data file Path = io.Path.Combine(table.Database.BinaryPath, $"{Table.Name}.{extension}"); }
/// <summary> /// Creates a database data table reader /// </summary> /// <param name="db">database</param> /// <param name="table">table</param> /// <param name="handler">query handler</param> /// <returns></returns> public static DbTableDataReader Create(CsvDb db, DbTable table, DbQueryHandler handler = null) { if (db == null || table == null) { return(null); } if ((db.Flags & DbSchemaConfigType.Binary) != 0) { return(new DbTableBinDataReader(table, handler)); } else { return(new DbTableCsvDataReader(table, handler)); } }
internal DbQueryExpressionExecuter(DbQueryHandler handler, DbQuery.ColumnOperand columnOperand, TokenType oper, DbQuery.ConstantOperand constantOperand) { if (columnOperand == null || !(Operator = oper).IsComparison() || constantOperand == null || (Handler = handler) == null) { throw new ArgumentException($"cannot execute comparison expression"); } //get the table column handler Column = handler.Database.Index(columnOperand.Column.Hash); // . handler.WhereColumns[columnOperand.Column.Hash]; //get the constant value to compare Constant = constantOperand.Evaluate(null); Reader = Handler.TableReaders.FirstOrDefault(r => r.Table == Column.Table); if (Reader == null) { throw new ArgumentException($"could not resolve data table reader for column: {Column}"); } }
/// <summary> /// Creates a database table csv/text data reader /// </summary> /// <param name="table">table</param> /// <param name="handler">query handler</param> public DbTableCsvDataReader(DbTable table, DbQueryHandler handler = null) : base(table, handler) { reader = new io.StreamReader(Path); }
/// <summary> /// Creates a database table data reader /// </summary> /// <param name="db">database</param> /// <param name="tableName">table name</param> /// <param name="handler">query handler</param> /// <returns></returns> public static DbTableDataReader Create(CsvDb db, string tableName, DbQueryHandler handler = null) { return(Create(db, db?.Table(tableName), handler)); }