C language > User contributions

In-memory relational database

(1/2) > >>

cosh:
Hi, there
I recently wrote an in-memory relational database and tested it by using Pelles C.
Here, you could download this project: https://github.com/coshcage/svimrdb
I'll show you guys demo codes here:

--- Code: ---#include "svimrdb.h"

int main()
{
P_MATRIX pv;
P_TRANS ptrans;
P_TABLE ptbl;

P_ARRAY_Z parrhdr;

parrhdr = strCreateArrayZ(3, sizeof(TBLHDR));
((TBLHDR *)strLocateItemArrayZ(parrhdr, sizeof(TBLHDR), 0))->ct = CT_INTEGER;
((TBLHDR *)strLocateItemArrayZ(parrhdr, sizeof(TBLHDR), 0))->strname = "number";
((TBLHDR *)strLocateItemArrayZ(parrhdr, sizeof(TBLHDR), 1))->ct = CT_STRING;
((TBLHDR *)strLocateItemArrayZ(parrhdr, sizeof(TBLHDR), 1))->strname = "name";
((TBLHDR *)strLocateItemArrayZ(parrhdr, sizeof(TBLHDR), 2))->ct = CT_STRING;
((TBLHDR *)strLocateItemArrayZ(parrhdr, sizeof(TBLHDR), 2))->strname = "Department";

ptrans = siBeginTransaction();

ptbl = siCreateTable(ptrans, "Student", parrhdr);

while (TRUE != siTrylock(ptrans, ptbl, LT_S)) // Share lock.
;

while (TRUE != siTrylock(ptrans, ptbl, LT_X)) // Write lock.
;


siInsertIntoTable(ptrans, ptbl, 2, "Lisa", "CS");
siInsertIntoTable(ptrans, ptbl, 1, "John", "LT");
siInsertIntoTable(ptrans, ptbl, 4, "Amy",  "CS");
siInsertIntoTable(ptrans, ptbl, 3, "Jack", "LT");

siDeleteFromTable(ptrans, ptbl, 3);

siDropTableColumn(ptrans, ptbl, 1);

pv = siCreateViewOfTable(ptbl);

siPrintView(pv);

siDeleteTable(ptrans, ptbl);

// siUnlock(ptrans, ptbl, LT_X);
// siUnlock(ptrans, ptbl, LT_S);

siCommitTransaction(ptrans);

//siRollbackTransaction(&parrtblref, ptrans);

strDeleteMatrix(pv);
strDeleteArrayZ(parrhdr);
siReleaseAllTransaction();

return 0;
}
--- End code ---
I haven't finish sql interface now. But you may use relational algebraic functions for searching from the database.
Here is a picture that I was testing the project in Pelles C:

Vortex:
Hi cosh,

Thanks for your work. Could you upload here your Pelles C example using the library? Thanks.

cosh:
OK, I'll package all source files to an attachment.
You may create a new Pelles C ide workspace by your own.
Thank you for your comment! Welcome your feedbacks.
If you want to develop this project with me, please email me. :)

frankie:
Good.  :)
I'll have a look.  ;)

MrBcx:
Not meaning to take anything away from COSH's generous efforts but developers
looking at integrating an in-memory database into their applications should also
be aware of the following capability that's already built-in to SQLITE. 


https://www.sqlite.org/inmemorydb.html


I've tested it in a previously coded BCX app and found it works as advertised. 
I only had to change one line of code in the app.

   rc = sqlite3_open("sq3.db",&dbHandle);     // open a database

to

   rc = sqlite3_open(":memory:",&dbHandle); //  open a database


Navigation

[0] Message Index

[#] Next page

Go to full version