How To Create Database Tables in C -


i need code small/simple database application using c, cs degree (so using sqlite or other available application not option. in other words, need re-invent wheel here).

my idea use b-tree store items of each table. problem facing tables need flexible hold unknown number of columns, , each column can either string or int. example, command:

create table student (string name, int age) 

i need create table holds string , integer. command instead:

create table grade (int grade1, int grade2, int grade3) 

i need create table holds 3 integers.

how can achieve such flexibility?

my idea far create struct several unions inside it, each union can either string or int. need put lot of unions inside, sure accommodate columns requested table. example:

struct table{     union{         int number;         char *text;     }column1;      union{         int number;         char *text;     }column2;      union{         int number;         char *text;     }column3;      ....  }; 

is there better way this?

i can think of 2 different approaches:

  1. make 'schema compiler' gets table definition, writes structs , compiles database engine.
  2. from schema definition calculate byte offset , length of each column. save , restore records byte array , pick fields using offset/length list.

most common #2, #1 has advantage c compiler 'knows' table structure, , type-check columns.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -