• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Looking for a lightweight database

Cogman

Lifer
Hey all, I want to do a personal project (meal planner) and was looking for a good lightweight opensource database to use. it isn't going to be an extremely large database, just something to store several recipes, ingredients, and expiration dates.

Mostly this is just a "for fun" type project, thought it would be helpful in giving me a little training in working with databases.
 
How about Berkeley DB? It looks like it is fairly lightweight and doesn't require me to setup username and passwords.
 
sqlite is great and there is a great firefox extension that lets you manage it. It is self contained (no server requried, just a file) so it is great for small apps.
 
Ok, i've been trying to give SQLite a whirl but to no avail. perhaps you guys could give me a hand.

Here is the problem, I want to get the thing to create the database if it doesn't exist and create a new table if it doesn't exist. Right now, I can create the database file (which is empty) but when I execute the command to create a new table I get a segment fault. I wonder if it is because there is no callback function (even though the documentation says there doesn't need to be one).

Any suggestions?

The code

#include <sqlite3.h>
#include <iostream>

using namespace std;

bool createDataBase(sqlite3* db)
{
int rc = 0;
rc = sqlite3_open_v2("food.db", &db,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
if (rc)
{
cout << "Could not open database: " << sqlite3_errmsg(db) << endl;
sqlite3_close(db);
return false;
}
return true;
}

void createTable(sqlite3* db)
{
int rc;
char* errmsg = NULL;

cout << "Executing command...\n";

rc = sqlite3_exec(db,
"CREATE TABLE IF NOT EXISTS ingredients(name TEXT, amount INT, expires TEXT);",
NULL, NULL, &errmsg);

cout << "Checking for errors..\n";
if (rc != SQLITE_OK)
cout << "SQL Error: " << *errmsg << endl;
sqlite3_free(errmsg);
}

int main()
{
sqlite3* db;
if(createDataBase(db))
{
cout << "Created Database...\n";
createTable(db);
cout << "Created Table\n";
}
sqlite3_close(db);
return 0;
}
 
If you're working in java then HSQLDb is the way to go. It's completely in memory and can be started and setup with 5 lines of code.
 
Back
Top