1

For learning and understanding purpose, I currently want to try to make a small relational DBMS with simple features like (for now) only sequential reading/writing and CREATE TABLE, INSERT, SELECT, UPDATE and DELETE management.

I am currently on the "think" part of the project and I am stuck on the way to store the read data in memory. First I was thinking of putting them properly on a structure, but the problem is that tables are all different, know the type of each column is not an issue, but I am not sure C provide a way to make fully dynamic structure.

My second and current idea is to make a simple char array of the required length and just get the data by order with cast. But I am not sure if it is the good way to do that part, so I wanted to ask for your opinion and advices about that.

Thanks in advance for your help.


nb: I hope my question is enough clear and understandable, I still lack of pratice in english

  • Your question indicates that even a "little" DBMS may be a too heavy goal for the first steps in C. And yes, C of course provides means to build dynamic structures of all kind. – JensG Oct 9 '13 at 18:43
  • 1
    @JensG As I was think, I have miss something in my message. It's not my first step in C at all and I know it well, and as dynamic structures I was more speaking of the content of the struct (if my table have two int and a text column I will have struct myTable { int a, int b, char *c; =; inside, if it's one int and a real, i will have struct myTable { int a; float b; };, I was thinking of "dynamic" in that sens. – Kane Oct 9 '13 at 18:55
  • Ok, then just a few thoughs: A table consists basically of a list of field (column) descriptors. Each of them has (at least) a data type assigned, and a pointer to some other memory, where the actual data are stored. These exact layout of These data depend on the data type set in the column descriptor. With C++, the columns descriptors could inherit from a base class, and the columns could be Held in a list<column> or the like. Good luck! – JensG Oct 9 '13 at 20:14
0

It has been a long time since I programmed in straight C, but I think I can point you in the right direction. There are 2 things you can use together. First somthing like:

union data {
    // all the data types you will support
}

You will need a way to identify each element. That is where struct can come in:

struct dataNode {
   data *value;
   // some type id system with either enum or ints
}

A row of data then becomes a linked list & a result set a linked list of linked lists. You will probably need to straighten out the syntax, but it is a start.

  • Oh, good idea ! I always forget union exist, that will certainly help me. – Kane Oct 10 '13 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.