Example #1
0
        public ColumnIndexOutOfBoundsException(TextualDatabase database, TextualTable table, int index)
        {
            TextualDatabase = database;
            TextualTable    = table;

            message = string.Format(MESSAGE_FORMAT, table.Name, index);
        }
Example #2
0
        private TextualRow parseRow(TextualTable table)
        {
            TextualRow row = new TextualRow(table);

            // | "val1" | 2 | "val3" |
            expectToken(TokenType.Pipe);
            while (!matchToken(TokenType.Dash))
            {
                if (matchToken(TokenType.Number))
                {
                    row.SetValueOrdered(Convert.ToDouble(expectToken(TokenType.Number).Value));
                }
                else
                {
                    row.SetValueOrdered(expectToken(TokenType.String).Value);
                }
                expectToken(TokenType.Pipe);
            }

            // -------------
            while (acceptToken(TokenType.Dash))
            {
                ;
            }

            return(row);
        }
Example #3
0
        public IncorrectValueFormatException(TextualOperation operation, TextualTable table)
        {
            TextualOperation = operation;
            TextualTable     = table;

            message = MESSAGE_FORMAT;
        }
        public ColumnAlreadyExistsException(TextualDatabase database, TextualTable table, string column)
        {
            TextualDatabase = database;
            TextualTable    = table;

            message = string.Format(MESSAGE_FORMAT, table.Name, column);
        }
Example #5
0
        private TextualTable parseTable(TextualDatabase db)
        {
            // name:
            string name = expectToken(TokenType.Identifier).Value;

            expectToken(TokenType.Colon);

            TextualTable table = new TextualTable(db, name);

            // | column1 | column2 | column3 |
            expectToken(TokenType.Pipe);
            while (!matchToken(TokenType.Dash))
            {
                table.Columns.Add(expectToken(TokenType.Identifier).Value);
                expectToken(TokenType.Pipe);
            }

            // -------------
            while (acceptToken(TokenType.Dash))
            {
                ;
            }

            // Rows
            while (!matchToken(TokenType.Question))
            {
                table.AddRow(parseRow(table));
            }

            // ?
            expectToken(TokenType.Question);

            return(table);
        }
Example #6
0
        private TextualTable parseShowTables()
        {
            var result = new TextualTable(database, database.Name);

            result.AddColumn("table");
            result.AddColumn("columns");
            result.AddColumn("rowCount");

            foreach (var pair in database.Tables)
            {
                var row = new TextualRow(result);
                row.SetValueOrdered(pair.Key);

                var sb = new StringBuilder();
                foreach (var column in pair.Value.Columns)
                {
                    sb.AppendFormat("{0} ", column);
                }
                row.SetValueOrdered(sb.ToString());

                row.SetValueOrdered(pair.Value.Rows.Count);

                result.AddRow(row);
            }

            return(result);
        }
        public TextualDeleteRowOperation(TextualTable table)
        {
            this.table = table;

            mirroredSourceRows = new List <TextualRow>();

            Result = table;
        }
        public RowNotFoundException(TextualDatabase database, TextualTable table, TextualRow row)
        {
            TextualDatabase = database;

            TextualTable = table;
            TextualRow   = row;

            message = string.Format(MESSAGE_FORMAT, table.Name);
        }
        public TextualSelectOperation(TextualTable table, params string[] columns)
        {
            Result     = new TextualTable(table.ParentDatabase, table.Name);
            this.table = table;

            if (columns.Length == 0)
            {
                columns = table.Columns.ToArray();
            }

            foreach (var column in columns)
            {
                Result.AddColumn(column);
            }
            foreach (var srcRow in table.Rows)
            {
                Result.AddRow(srcRow);
            }
        }
Example #10
0
        private TextualTable parseShowColumns()
        {
            // IN table
            expectToken(TokenType.Identifier, "IN");
            string table = expectToken(TokenType.Identifier).Value;

            var result = new TextualTable(database, table);

            result.AddColumn("column");

            foreach (var column in database.GetTable(table).Columns)
            {
                var row = new TextualRow(result);
                row.SetValueOrdered(column);
                result.AddRow(row);
            }

            return(result);
        }
Example #11
0
        public TextualUpdateOperation(TextualTable table, string[] columns, object[] values)
        {
            this.table   = table;
            this.columns = columns;
            this.values  = values;

            mirroredSourceRows = new List <TextualRow>();

            foreach (var srcRow in table.Rows)
            {
                mirroredSourceRows.Add(srcRow);
            }

            if (columns.Length != values.Length)
            {
                throw new ColumnValueCountMismatchException(this, columns.Length, values.Length);
            }

            Result = table;
        }
Example #12
0
        private void handleResult(TextualTable table)
        {
            if (table == null)
            {
                return;
            }

            if (table.Rows.Count > 15)
            {
                Console.WriteLine("Result table has more than 15 values. Display (y/N)? ");
                string res = Console.ReadLine();
                if (res.ToUpper() == "Y" || res.ToUpper() == "YES")
                {
                    Console.WriteLine(table);
                }
            }
            else
            {
                Console.WriteLine(table);
            }
        }
Example #13
0
 public TextualInsertOperation(TextualTable table)
 {
     this.table = table;
 }
 public TextualCreateColumnOperation(TextualTable table)
 {
     this.table = table;
 }
Example #15
0
        public TextualRenameTableOperation(TextualTable table)
        {
            this.table = table;

            Result = table;
        }
Example #16
0
 public TextualCreateTableOperation(TextualDatabase database, string name)
 {
     Result = new TextualTable(database, name);
 }