2
\file lib/db/dbmi_driver/d_error.c
4
\brief DBMI Library (driver) - error reporting
8
(C) 1999-2008, 2012 by the GRASS Development Team
10
This program is free software under the GNU General Public
11
License (>=v2). Read the file COPYING that comes with GRASS
14
\author Joel Jones (CERL/UIUC)
16
\author Adopted for DBMI by Martin Landa <landa.martin@gmail.com>
20
#include <grass/dbmi.h>
21
#include <grass/glocale.h>
23
/* initialize the global struct */
29
static struct error_state state;
30
static struct error_state *st = &state;
34
db_set_string(st->errMsg, "");
35
db_d_append_error(_("DBMI-%s driver error:"), st->driver_name);
36
db_append_string(st->errMsg, "\n");
41
\brief Init error message for DB driver
45
\param name driver name (eg. "SQLite"))
47
void db_d_init_error(const char *name)
50
st->errMsg = (dbString *) G_malloc(sizeof(dbString));
51
db_init_string(st->errMsg);
54
G_debug(1, "db_d_init_error(): %s", name);
56
st->driver_name = G_malloc(strlen(name) + 1);
57
strcpy(st->driver_name, name);
62
\brief Append error message for DB driver
64
\param fmt formatted message
66
void db_d_append_error(const char *fmt, ...)
74
if ((fp = tmpfile())) {
75
count = vfprintf(fp, fmt, ap);
76
if (count >= 0 && (work = G_calloc(count + 1, 1))) {
78
fread(work, 1, count, fp);
79
db_append_string(st->errMsg, work);
88
\brief Report error message for DB driver
90
void db_d_report_error(void)
92
db_append_string(st->errMsg, "\n");
93
db_error(db_get_string(st->errMsg));