Pelles C forum
C language => User contributions => Topic started by: cosh 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:
#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:
-
Hi cosh,
Thanks for your work. Could you upload here your Pelles C example using the library? Thanks.
-
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. :)
-
Good. :)
I'll have a look. ;)
-
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
-
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.
-
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.