コード例 #1
0
 /// <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();
 }
コード例 #2
0
ファイル: DbVisualizer.cs プロジェクト: Diogny/CsvDb
        /// <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;
        }
コード例 #3
0
ファイル: DbVisualizer.cs プロジェクト: Diogny/CsvDb
 /// <summary>
 /// free reader resources
 /// </summary>
 public void Dispose()
 {
     if (handler != null)
     {
         handler.Dispose();
         handler = null;
     }
 }
コード例 #4
0
ファイル: DbQueryHandler.cs プロジェクト: Diogny/CsvDb
        /// <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));
        }
コード例 #5
0
        /// <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}");
        }
コード例 #6
0
 /// <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));
     }
 }
コード例 #7
0
        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}");
            }
        }
コード例 #8
0
 /// <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);
 }
コード例 #9
0
 /// <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));
 }