Trabalho 1 Bd2
Esta atividade consiste em ler arquivos de metadados e dados para simular um select * from table. Para tal, serão fornecidos três arquivos: um contendo o metadado da tabela (table.dic), outro o metadado dos atributos (att.dic) e um outro com os dados de uma das tabelas presentes no table.dic (11.dat).
T1 - Data File Reading
This activity involves reading metadata and data files to simulate a SELECT * FROM table operation. Three files will be provided for this purpose: one containing table metadata (table.dic), another containing attribute metadata (att.dic), and a third containing the actual data for one of the tables listed in table.dic (e.g., 11.dat).
+-----------+ idtable +---------+
| table.dic |---------------<| att.dic |
+-----------+ +---------+
Implement a C application that performs the following:
- Upon execution, the program must receive a parameter (a string) corresponding to the logical name (table) within the database. For example, if the program is named
select, the command line entry (on Linux) would be./select table. The result should be equivalent to aSELECT * FROM tableSQL query. - The application will search
table.dicfor the table name passed as a parameter; if found, it must open the file corresponding to the physical name for reading. The structure oftable.dicis as follows:
struct ttable {
int idtable; // table's id
char ctname[20]; // conceptual table's name
char ptname[20]; // physical table's name
}
- If the logical name is found in
table.dic, theatt.dicfile must be opened to retrieve the file schema. It is organized as follows:
struct tatt {
int idtable; // table's id
char atname[20]; // attribute's name
char attype; // S (string) I (integer) F (float) (C Char)
char isKey; // 1 is a primary key
char atopt; // mandatory (0) optional (1)
int atlen; // length
}
Submit a ZIP file containing the source code created (using separate .h and .c files is recommended), or just the source file if everything is contained in a single file. The name of the ZIP or source file must be your student ID number. Example:
Imagine an instance of table.dic with
<1, "car", "xyz.dat">, <2, "owner", "d001.dat"> and
an instance of att.dic with
<1, "model", 'S', 1, 0, 30>, <1, "year", 'I',0, 0, 4>,
<2, "issn", 'S', 1,0, 12>, <2, "name", 'S', 0, 0, 30>
If the application name is selectDB, execution on Linux would be ./selectDB owner (where "owner" corresponds to the table name—the logical name).
The file d001.dat will contain data following the schema corresponding to table ID 2 ("owner") in the att.dic file: specifically, "issn" (a 12-character string, mandatory and a key) and "name" (a 30-character string, mandatory, not a key).
Finally, the contents of the physical file (d001.dat) must be listed. To simplify matters, you do not need to handle optional attributes, as all will be considered mandatory. Suggested output:
issn name
002322 John Wayne
230011 Anthony Hopkins
450001 Greta Garbo
For the proposed task, table.dic and att.dic store metadata for the tables "student", "course", and "enrollment". Only the physical file for "student" has been provided. Perform your tests using this table. During grading, we will use the "course" and "enrollment" tables in addition to "student".
