NO

Author Topic: In-memory relational database  (Read 688 times)

Offline cosh

  • Member
  • *
  • Posts: 25
In-memory relational database
« on: July 18, 2023, 07:37:03 AM »
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: [Select]
#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;
}
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:

Offline Vortex

  • Member
  • *
  • Posts: 802
    • http://www.vortex.masmcode.com
Re: In-memory relational database
« Reply #1 on: July 18, 2023, 10:51:53 AM »
Hi cosh,

Thanks for your work. Could you upload here your Pelles C example using the library? Thanks.
Code it... That's all...

Offline cosh

  • Member
  • *
  • Posts: 25
Re: In-memory relational database
« Reply #2 on: July 18, 2023, 11:15:38 AM »
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. :)

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: In-memory relational database
« Reply #3 on: July 18, 2023, 11:34:15 AM »
Good.  :)
I'll have a look.  ;)
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

Offline MrBcx

  • Global Moderator
  • Member
  • *****
  • Posts: 176
    • Bcx Basic to C/C++ Translator
Re: In-memory relational database
« Reply #4 on: July 18, 2023, 02:44:33 PM »
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


Bcx Basic to C/C++ Translator
https://www.BcxBasicCoders.com

Offline cosh

  • Member
  • *
  • Posts: 25
Re: In-memory relational database
« Reply #5 on: July 18, 2023, 04:22:05 PM »
Hi, MrBcx
SQLITE is definitely a triumph database system to developers.
While I think svimrdb is a lite version of SQLITE, it is simple to read(but not very simple to program with..).
svimrdb is under developing, if you wanna support it, comment here or give me a thumbs up, I would greatly appreciate you.

By the way, since year 2014, I've introduced BCX compiler to our community. Are you the author of BCX? I would like to thank you.
I was a Visual Basic programmer a long time ago till I found BCX, but I hardly use BCX recently.

Offline MrBcx

  • Global Moderator
  • Member
  • *****
  • Posts: 176
    • Bcx Basic to C/C++ Translator
Re: In-memory relational database
« Reply #6 on: July 18, 2023, 05:56:35 PM »
Hi, MrBcx
SQLITE is definitely a triumph database system to developers.
While I think svimrdb is a lite version of SQLITE, it is simple to read(but not very simple to program with..).
svimrdb is under developing, if you wanna support it, comment here or give me a thumbs up, I would greatly appreciate you.

By the way, since year 2014, I've introduced BCX compiler to our community.
Are you the author of BCX?   I would like to thank you.  I was a Visual Basic programmer
a long time ago till I found BCX, but I hardly use BCX recently.

As I said previously, your generous SV efforts are very much appreciated. 
Here is my thumbs up =^      ;D

My database development has mostly ended since I retired almost 10 years ago but I
understand the many ways that in-memory databases can be useful to programmers.
We all tend to use the tools that we have experience using and that serve our goals.

Re:  BCX ... yes, I am the author and current maintainer.  I am pleased you found BCX
useful in the past and that you promoted it to your community.  BCX continues to receive
regular updates.

Thanks again for your contributions.
Bcx Basic to C/C++ Translator
https://www.BcxBasicCoders.com