/C_Database

A Database written entirely in C.

Primary LanguageCMIT LicenseMIT

C Database

A Database written entirely in C.

Authors

Usage

The project simulates the management of a Database using text files (.txt) for data storage. To test it's enought to compile everything with c99 and run main.c.

Project structure

The project is structured in 3 folders:

  • data, which contains the queries that will be executed when the program is run;
  • results, which contains the output files generated by the program;
  • src, which contains the program;

About the Project

Data storage

Each table of the Database will be stored in a different text file.

Input Commands

  • The management of each table of the Database will be done using commands in a language provided in the project specifications, which echoes the SQL syntax. Here all the possible commands:
    • CREATE TABLE table_name (column1_name,…)
    • INSERT INTO table_name (column1_name,…) VALUES (value1,…)
    • CREATE TABLE table_name (column1_name,…)
    • SELECT * FROM table_name
    • SELECT * FROM table_name ORDER BY column1_name ASC, instead of ASC, DESC can be used
    • SELECT * FROM table_name WHERE condition, where condition can be ==, >, >=, < or <=
    • SELECT column1_name,… FROM table_name
    • SELECT column1_name,… FROM table_name WHERE condition, where condition can be ==, >, >=, < or <=
    • SELECT column1_name,… FROM table_name ORDER BY column2_name ASC, instead of ASC, DESC can be used
    • SELECT column1_name FROM table_name GROUP BY column1_name

Output

To represent the Database in the text files (output) the output is provided in the following way.

TABLE table_name COLUMNS column1_name,..; 
ROW value1,...;
ROW value2,...;

Data storing

In order to better manage the database tables, we chose to rely on a data structure that consists in a dynamic array of pointers, each of which identifies an array of strings corresponding to the values of each column in the row.

Below an example of a possible table and how it is stored by the program.

Surname Name Phone
Bianchi Mario 123456
Rossi Paolo 43215
... ... ...

Alt text