Problem with queries
To tackle this problem, you will need to create a simplified SQL server capable of executing specific queries. The input file will contain these queries, which will be one of the following three types: CREATE TABLE, INSERT, and SELECT.
The queries will follow these formats:
- CREATE TABLE <table name> (<list of field names>); - INSERT INTO <table name> VALUES (<list of constants>); - SELECT <list of specialized field names> FROM <list of tables> WHERE <logical expression>;
Please note that the query formats will strictly adhere to the specified structure (for instance, the WHERE clause in a SELECT query is mandatory). The language keywords are not case-sensitive.
Table and field names are non-empty sequences of lowercase Latin letters. Constants are string literals enclosed in single quotes, such as 'constant'. These constants, along with table and field names, consist of lowercase Latin letters. Table names, column names, and constant values will not exceed 30 characters in length. No table or column name will coincide with any of the language keywords: CREATE, TABLE, INSERT, INTO, VALUES, SELECT, FROM, WHERE.
A list in the specified format is a comma-separated enumeration of elements (refer to the example input file).
A specialized field name is denoted as <table name>.<table field name>.
A logical expression consists of one or more comparisons (equality checks) of table fields from which the selection is made, specified by specialized field names, separated by logical operators AND or OR. The logical expression should be evaluated with consideration for the priority of these operations (AND has higher precedence). For further clarification on the input data format, see the example input file.
Your task is to output the resulting table for each SELECT query, with its rows sorted in lexicographical order. A row is considered lexicographically smaller than another if the initial columns in both rows are identical, and in the subsequent column, the value in the first row is less than that in the second row (implying lexicographical string comparison).
It is guaranteed that all queries are valid, adhering to the rules outlined above, and all table names, field names, and specialized field names used in the queries will be defined by a CREATE TABLE query before they are used. Tables with identical names will not be created. Each table will contain at least one field.
Input
The input file will contain a sequence of queries in the simplified SQL language as described in the problem statement. Each query will be on a separate line, and each line will contain one query. No more than 20 rows will be inserted into any table (using the INSERT command). Each SELECT query will reference no more than three tables, and within a single query, the same table will not appear twice in the list of tables.
Output
For each SELECT query, you need to output the resulting table. Each row of the resulting table should be on a separate line of the output file and should consist of the field values listed in the first part of the SELECT query, separated by a single space. After each table, you need to output a line containing three characters '-' (i.e., '—').