From 915549ec38feb09d0f4c49443b2639640cbe257d Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Tue, 30 Oct 2007 22:05:14 +0200 Subject: [PATCH] Add sql exec helper. Add GPL header. --- src/db.c | 38 +++++++++++++++++++++++++++++++++++++- src/db.h | 21 +++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/db.c b/src/db.c index 86dcd64..b966f8b 100644 --- a/src/db.c +++ b/src/db.c @@ -1,10 +1,29 @@ +/* + * This file is part of mapper + * + * Copyright (C) 2007 Kaj-Michael Lang + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + #include "config.h" #include #include #include "db.h" -#include "utils.h" sqlite3 *_db=NULL; gchar *_mapper_db=NULL; @@ -29,6 +48,23 @@ sqlite3_free_table(pszResult); return TRUE; } +/** + * Helper that execs a given prepared sql statment and resets clears bindings. + * return TRUE or FALSE depending on success of the query. + * + */ +gboolean +db_exec(sqlite3_stmt *sql) +{ +gint r; + +r=sqlite3_step(sql); +sqlite3_reset(sql); +sqlite3_clear_bindings(sql); + +return (r==SQLITE_OK) ? TRUE : FALSE; +} + /** * Close the database connection * diff --git a/src/db.h b/src/db.h index 9c84608..b84a2da 100644 --- a/src/db.h +++ b/src/db.h @@ -1,3 +1,23 @@ +/* + * This file is part of mapper + * + * Copyright (C) 2007 Kaj-Michael Lang + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + #include #include @@ -10,5 +30,6 @@ gchar *_mapper_db; gboolean db_connect(sqlite3 **db, const gchar *mapper_db); gboolean db_check(sqlite3 *db, const gchar *table); gboolean db_close(sqlite3 **db); +gboolean db_exec(sqlite3_stmt *sql); #endif -- 2.39.5