Compare commits

..

2 Commits

Author SHA1 Message Date
c0c6959774 Regularize token use.
Mainly using the 'not' and 'not_eq' tokens.
2024-10-11 10:54:14 +02:00
08b4834d9e Remove old comments from porting. 2024-10-11 10:52:11 +02:00
2 changed files with 8 additions and 10 deletions

View File

@ -74,7 +74,7 @@ int command_list(int argc, char *argv[]) {
std::vector<std::string> ingredients, tags;
int opt;
while((opt = getopt(argc, argv, "i:t:")) != -1) {
while((opt = getopt(argc, argv, "i:t:")) not_eq -1) {
switch(opt) {
case 'i':
ingredients = split(optarg, ",");

View File

@ -47,7 +47,6 @@ int db_open(void) {
db_path += "/recipes.db";
//if(access(db_path, F_OK) != 0) {
if(not std::filesystem::exists(db_path)) {
std::cout << "Creating database: " << db_path << std::endl;
new_db = true;
@ -55,9 +54,8 @@ int db_open(void) {
rc = sqlite3_open(db_path.c_str(), &db);
if(rc == SQLITE_OK && new_db) {
if(rc == SQLITE_OK and new_db) {
sqlite3_exec(db, "CREATE TABLE db_version(version INTEGER UNIQUE NOT nullptr);", nullptr, nullptr, nullptr);
//snprintf(insert_version_stmt, 64, "INSERT INTO db_version VALUES(%d);", DB_VERSION);
sqlite3_exec(db, std::format("INSERT INTO db_version VALUES({});", DB_VERSION).c_str(), nullptr, nullptr, nullptr);
sqlite3_exec(db, "CREATE TABLE tags(id INTEGER PRIMARY KEY AUTOINCREMENT, name STRING UNIQUE);", nullptr, nullptr, nullptr);
sqlite3_exec(db, "CREATE TABLE ingredients(id INTEGER PRIMARY KEY AUTOINCREMENT, name STRING UNIQUE);", nullptr, nullptr, nullptr);
@ -95,7 +93,7 @@ int table_get_id_by_name(const std::string &table, const std::string &name) {
int id = 0;
if(sqlite3_exec(db, std::format("SELECT id FROM {} WHERE lower(name)=lower('{}');", table, name).c_str(),
query_id_cb, &id, nullptr) != SQLITE_OK)
query_id_cb, &id, nullptr) not_eq SQLITE_OK)
return -2;
return id;
@ -106,7 +104,7 @@ int db_add_recipe(const std::string &name, const std::string &description) {
return -1;
if(sqlite3_exec(db, std::format("INSERT INTO recipes(name,description) VALUES('{}','{}');", name, description).c_str(),
nullptr, nullptr, nullptr) != SQLITE_OK)
nullptr, nullptr, nullptr) not_eq SQLITE_OK)
return -2;
return db_get_recipe_id(name);
@ -250,7 +248,7 @@ int db_add_ingredient(const std::string &name) {
return -1;
if(sqlite3_exec(db, std::format("INSERT INTO ingredients(name) VALUES(lower('{}'));", name).c_str(),
nullptr, nullptr, nullptr) != SQLITE_OK)
nullptr, nullptr, nullptr) not_eq SQLITE_OK)
return -2;
return db_get_ingredient_id(name);
@ -268,7 +266,7 @@ int db_add_tag(const std::string &name) {
return -1;
if(sqlite3_exec(db, std::format("INSERT INTO tags(name) VALUES('{}');", name).c_str(),
nullptr, nullptr, nullptr) != SQLITE_OK)
nullptr, nullptr, nullptr) not_eq SQLITE_OK)
return -2;
return db_get_tag_id(name);
@ -286,7 +284,7 @@ int db_conn_recipe_ingredient(int recipe_id, int ingredient_id) {
return -1;
if(sqlite3_exec(db, std::format("INSERT INTO recipe_ingredient(recipe_id, ingredient_id) VALUES({},{});", recipe_id, ingredient_id).c_str(),
nullptr, nullptr, nullptr) != SQLITE_OK)
nullptr, nullptr, nullptr) not_eq SQLITE_OK)
return -2;
return 1;
@ -297,7 +295,7 @@ int db_conn_recipe_tag(int recipe_id, int tag_id) {
return -1;
if(sqlite3_exec(db, std::format("INSERT INTO recipe_tag(recipe_id, tag_id) VALUES({},{});", recipe_id, tag_id).c_str(),
nullptr, nullptr, nullptr) != SQLITE_OK)
nullptr, nullptr, nullptr) not_eq SQLITE_OK)
return -2;
return 1;