[GRASS-SVN] r50443 - in grass/trunk/db/drivers: dbf mysql odbc ogr
postgres sqlite
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jan 25 09:06:13 EST 2012
Author: martinl
Date: 2012-01-25 06:06:13 -0800 (Wed, 25 Jan 2012)
New Revision: 50443
Modified:
grass/trunk/db/drivers/dbf/column.c
grass/trunk/db/drivers/dbf/create_table.c
grass/trunk/db/drivers/dbf/cursor.c
grass/trunk/db/drivers/dbf/db.c
grass/trunk/db/drivers/dbf/dbfexe.c
grass/trunk/db/drivers/dbf/describe.c
grass/trunk/db/drivers/dbf/driver.c
grass/trunk/db/drivers/dbf/error.c
grass/trunk/db/drivers/dbf/execute.c
grass/trunk/db/drivers/dbf/main.c
grass/trunk/db/drivers/dbf/proto.h
grass/trunk/db/drivers/dbf/select.c
grass/trunk/db/drivers/dbf/table.c
grass/trunk/db/drivers/mysql/create_table.c
grass/trunk/db/drivers/mysql/cursor.c
grass/trunk/db/drivers/mysql/db.c
grass/trunk/db/drivers/mysql/dbe.c
grass/trunk/db/drivers/mysql/describe.c
grass/trunk/db/drivers/mysql/error.c
grass/trunk/db/drivers/mysql/execute.c
grass/trunk/db/drivers/mysql/fetch.c
grass/trunk/db/drivers/mysql/index.c
grass/trunk/db/drivers/mysql/listtab.c
grass/trunk/db/drivers/mysql/parse.c
grass/trunk/db/drivers/mysql/proto.h
grass/trunk/db/drivers/mysql/select.c
grass/trunk/db/drivers/odbc/connect.c
grass/trunk/db/drivers/odbc/create_table.c
grass/trunk/db/drivers/odbc/cursor.c
grass/trunk/db/drivers/odbc/db.c
grass/trunk/db/drivers/odbc/describe.c
grass/trunk/db/drivers/odbc/driver.c
grass/trunk/db/drivers/odbc/error.c
grass/trunk/db/drivers/odbc/execute.c
grass/trunk/db/drivers/odbc/listdb.c
grass/trunk/db/drivers/odbc/listtab.c
grass/trunk/db/drivers/odbc/proto.h
grass/trunk/db/drivers/odbc/select.c
grass/trunk/db/drivers/odbc/table.c
grass/trunk/db/drivers/ogr/cursor.c
grass/trunk/db/drivers/ogr/db.c
grass/trunk/db/drivers/ogr/describe.c
grass/trunk/db/drivers/ogr/error.c
grass/trunk/db/drivers/ogr/execute.c
grass/trunk/db/drivers/ogr/fetch.c
grass/trunk/db/drivers/ogr/listtab.c
grass/trunk/db/drivers/ogr/proto.h
grass/trunk/db/drivers/ogr/select.c
grass/trunk/db/drivers/postgres/create_table.c
grass/trunk/db/drivers/postgres/cursor.c
grass/trunk/db/drivers/postgres/db.c
grass/trunk/db/drivers/postgres/describe.c
grass/trunk/db/drivers/postgres/error.c
grass/trunk/db/drivers/postgres/execute.c
grass/trunk/db/drivers/postgres/fetch.c
grass/trunk/db/drivers/postgres/index.c
grass/trunk/db/drivers/postgres/listdb.c
grass/trunk/db/drivers/postgres/listtab.c
grass/trunk/db/drivers/postgres/parse.c
grass/trunk/db/drivers/postgres/priv.c
grass/trunk/db/drivers/postgres/proto.h
grass/trunk/db/drivers/postgres/select.c
grass/trunk/db/drivers/sqlite/create_table.c
grass/trunk/db/drivers/sqlite/cursor.c
grass/trunk/db/drivers/sqlite/db.c
grass/trunk/db/drivers/sqlite/describe.c
grass/trunk/db/drivers/sqlite/error.c
grass/trunk/db/drivers/sqlite/execute.c
grass/trunk/db/drivers/sqlite/fetch.c
grass/trunk/db/drivers/sqlite/index.c
grass/trunk/db/drivers/sqlite/listtab.c
grass/trunk/db/drivers/sqlite/proto.h
grass/trunk/db/drivers/sqlite/select.c
Log:
DB drivers: use db_d_report_error() instead of its own mechanism
i18n
Modified: grass/trunk/db/drivers/dbf/column.c
===================================================================
--- grass/trunk/db/drivers/dbf/column.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/dbf/column.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -20,6 +20,7 @@
#include <dirent.h>
#include <grass/dbmi.h>
#include <grass/gis.h>
+#include <grass/glocale.h>
#include "globals.h"
#include "proto.h"
@@ -45,8 +46,9 @@
/* Check if the column exists */
for (c = 0; c < db.tables[tab].ncols; c++) {
if (G_strcasecmp(db.tables[tab].cols[c].name, name) == 0) {
- append_error("Column '%s' already exists (duplicate name)\n",
- name);
+ db_d_append_error(_("Column '%s' already exists (duplicate name)"),
+ name);
+ db_d_report_error();
return DB_FAILED;
}
}
@@ -94,7 +96,8 @@
/* Check if the column exists */
c = find_column(tab, name);
if (c == -1) {
- append_error("Column '%s' does not exist\n", name);
+ db_d_append_error(_("Column '%s' does not exist"), name);
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/dbf/create_table.c
===================================================================
--- grass/trunk/db/drivers/dbf/create_table.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/dbf/create_table.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -1,4 +1,5 @@
#include <grass/dbmi.h>
+#include <grass/glocale.h>
#include "globals.h"
#include "proto.h"
@@ -18,8 +19,8 @@
ret = execute(db_get_string(&sql), NULL);
if (ret == DB_FAILED) {
- append_error("Cannot create table");
- report_error();
+ db_d_append_error(_("Unable to create table"));
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/dbf/cursor.c
===================================================================
--- grass/trunk/db/drivers/dbf/cursor.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/dbf/cursor.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -17,6 +17,7 @@
#include <stdlib.h>
#include <grass/dbmi.h>
#include <grass/gis.h>
+#include <grass/glocale.h>
#include "globals.h"
#include "proto.h"
@@ -43,7 +44,8 @@
/* allocate the cursor */
c = (cursor *) db_malloc(sizeof(cursor));
if (c == NULL) {
- append_error("cannot alloc new cursor");
+ db_d_append_error(_("Unable to allocate new cursor"));
+ db_d_report_error();
return c;
}
@@ -54,7 +56,8 @@
if (c->token < 0) {
free_cursor(c);
c = NULL;
- append_error("cannot tokenize new cursor\n");
+ db_d_append_error(_("Unable to tokenize new cursor"));
+ db_d_report_error();
}
return c;
Modified: grass/trunk/db/drivers/dbf/db.c
===================================================================
--- grass/trunk/db/drivers/dbf/db.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/dbf/db.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -22,6 +22,7 @@
#include <errno.h>
#include <grass/dbmi.h>
#include <grass/gis.h>
+#include <grass/glocale.h>
#include "globals.h"
#include "proto.h"
@@ -89,14 +90,14 @@
status = G_mkdir(db.name);
if (status != 0) { /* mkdir failed */
- append_error("Cannot create dbf database: %s\n", name);
- report_error();
+ db_d_append_error(_("Unable create DBF database: %s"), name);
+ db_d_report_error();
return DB_FAILED;
}
}
else { /* some other problem */
- append_error("Cannot open dbf database: %s\n", name);
- report_error();
+ db_d_append_error(_("Unable to open DBF database: %s"), name);
+ db_d_report_error();
return DB_FAILED;
}
}
Modified: grass/trunk/db/drivers/dbf/dbfexe.c
===================================================================
--- grass/trunk/db/drivers/dbf/dbfexe.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/dbf/dbfexe.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -22,6 +22,7 @@
#include <grass/dbmi.h>
#include <grass/shapefil.h>
#include <grass/gis.h>
+#include <grass/glocale.h>
#include "globals.h"
#include "proto.h"
@@ -67,8 +68,11 @@
if (yyparse() != 0) {
G_free(tmpsql);
- append_error("SQL parser error: %s\n", st->errmsg);
- append_error("in statement:\n%s\n", sql);
+ db_d_append_error("%s (%s) %s\n%s\n",
+ _("SQL parser error"),
+ st->errmsg,
+ _("in statement:"),
+ sql);
sqpFreeStmt(st);
return DB_FAILED;
}
@@ -81,7 +85,7 @@
/* find table */
tab = find_table(st->table);
if (tab < 0 && st->command != SQLP_CREATE) {
- append_error("Table '%s' doesn't exist.\n", st->table);
+ db_d_append_error(_("Table '%s' doesn't exist."), st->table);
return DB_FAILED;
}
@@ -89,7 +93,7 @@
if ((st->command != SQLP_CREATE)) {
ret = load_table_head(tab);
if (ret == DB_FAILED) {
- append_error("Cannot load table head.\n");
+ db_d_append_error(_("Unable to load table head."));
return DB_FAILED;
}
}
@@ -99,8 +103,8 @@
(st->command == SQLP_ADD_COLUMN) || (st->command == SQLP_DROP_COLUMN)
) {
if (db.tables[tab].write == FALSE) {
- append_error
- ("Cannot modify table, don't have write permission for DBF file.\n");
+ db_d_append_error(_("Unable to modify table, "
+ "don't have write permission for DBF file."));
return DB_FAILED;
}
}
@@ -114,7 +118,7 @@
for (i = 0; i < ncols; i++) {
cols[i] = find_column(tab, st->Col[i].s);
if (cols[i] == -1) {
- append_error("Column '%s' not found\n", st->Col[i].s);
+ db_d_append_error(_("Column '%s' not found"), st->Col[i].s);
return DB_FAILED;
}
}
@@ -138,7 +142,7 @@
if ((dtype == DBF_INT && stype != SQLP_I)
|| (dtype == DBF_DOUBLE && stype == SQLP_S)
|| (dtype == DBF_CHAR && stype != SQLP_S)) {
- append_error("Incompatible value type.\n");
+ db_d_append_error(_("Incompatible value type."));
return DB_FAILED;
}
}
@@ -154,7 +158,7 @@
get_col_def(st, 0, &dtype, &width, &decimals);
ret = add_column(tab, dtype, st->Col[0].s, width, decimals);
if (ret == DB_FAILED) {
- append_error("Cannot add column.\n");
+ db_d_append_error(_("Unable to add column."));
return DB_FAILED;
}
/* Add column to each row */
@@ -176,7 +180,7 @@
case (SQLP_DROP_COLUMN):
load_table(tab);
if (drop_column(tab, st->Col[0].s) != DB_OK) {
- append_error("Cannot delete column.\n");
+ db_d_append_error(_("Unable to delete column."));
return DB_FAILED;
}
db.tables[tab].updated = TRUE;
@@ -184,7 +188,8 @@
case (SQLP_CREATE):
if (tab >= 0) {
- append_error("Table %s already exists\n", st->table);
+ db_d_append_error(_("Table %s already exists"), st->table);
+
return DB_FAILED;
}
sprintf(name, "%s.dbf", st->table);
@@ -198,7 +203,7 @@
get_col_def(st, i, &dtype, &width, &decimals);
ret = add_column(tab, dtype, st->Col[i].s, width, decimals);
if (ret == DB_FAILED) {
- append_error("Cannot create table.\n");
+ db_d_append_error(_("Unable to create table."));
db.tables[tab].alive = FALSE;
return DB_FAILED;
}
@@ -255,7 +260,7 @@
c->ncols = ncols;
c->nrows = sel(st, tab, &(c->set));
if (c->nrows < 0) {
- append_error("Error in selecting rows\n");
+ db_d_append_error(_("Error in selecting rows"));
return DB_FAILED;
}
c->cur = -1;
@@ -265,7 +270,7 @@
case (SQLP_UPDATE):
nrows = sel(st, tab, &selset);
if (nrows < 0) {
- append_error("Error in selecting rows\n");
+ db_d_append_error(_("Error in selecting rows"));
return DB_FAILED;
}
dbrows = db.tables[tab].rows;
@@ -295,7 +300,7 @@
case (SQLP_DELETE):
nrows = sel(st, tab, &selset);
if (nrows < 0) {
- append_error("Error in selecting rows\n");
+ db_d_append_error(_("Error in selecting rows"));
return DB_FAILED;
}
dbrows = db.tables[tab].rows;
@@ -544,7 +549,7 @@
ret = load_table(tab);
if (ret == DB_FAILED) {
- append_error("Cannot load table.\n");
+ db_d_append_error(_("Cannot load table."));
return -1;
}
@@ -559,12 +564,12 @@
G_debug(4, "node result type = %d", node_type);
if (node_type == -1) {
- append_error("Incompatible types in WHERE condition.\n");
+ db_d_append_error(_("Incompatible types in WHERE condition."));
return -1;
}
else if (node_type == SQLP_S || node_type == SQLP_I ||
node_type == SQLP_D) {
- append_error("Result of WHERE condition is not of type BOOL.\n");
+ db_d_append_error(_("Result of WHERE condition is not of type BOOL."));
return -1;
}
else if (node_type == SQLP_NULL) {
@@ -580,8 +585,8 @@
G_debug(4, "condition = %d", condition);
if (condition == NODE_ERROR) { /* e.g. division by 0 */
- append_error("Error in evaluation of WHERE condition.\n");
- return (-1);
+ db_d_append_error(_("Error in evaluation of WHERE condition."));
+ return -1;
}
else if (condition == NODE_TRUE) { /* true */
if (nset == aset) {
@@ -592,15 +597,14 @@
nset++;
}
else if (condition != NODE_FALSE && condition != NODE_NULL) { /* Should not happen */
- append_error("Unknown result (%d) of WHERE evaluation.\n",
- condition);
+ db_d_append_error(_("Unknown result (%d) of WHERE evaluation"),
+ condition);
return -1;
}
}
}
else { /* Should not happen */
- append_error
- ("Unknown WHERE condition type (bug in DBF driver).\n");
+ db_d_append_error(_("Unknown WHERE condition type (bug in DBF driver)."));
return -1;
}
}
@@ -626,7 +630,7 @@
}
}
if (cur_cmp_ocol < 0) {
- append_error("Cannot find order column '%s'\n", st->orderCol);
+ db_d_append_error(_("Unable to find order column '%s'"), st->orderCol);
return -1;
}
@@ -771,7 +775,7 @@
dval = left_dval / right_dval;
}
else {
- append_error("Division by zero\n");
+ db_d_append_error(_("Division by zero"));
return NODE_ERROR;
}
break;
@@ -910,7 +914,7 @@
return NODE_TRUE;
}
else if (left == NODE_VALUE || right == NODE_VALUE) { /* Should not happen */
- append_error("Value operand for AND\n");
+ db_d_append_error(_("Value operand for AND"));
return NODE_ERROR;
}
else {
@@ -924,7 +928,7 @@
return NODE_TRUE;
}
else if (left == NODE_VALUE || right == NODE_VALUE) { /* Should not happen */
- append_error("Value operand for OR\n");
+ db_d_append_error(_("Value operand for OR"));
return NODE_ERROR;
}
else {
@@ -939,7 +943,7 @@
return NODE_FALSE;
}
else if (right == NODE_VALUE) { /* Should not happen */
- append_error("Value operand for NOT\n");
+ db_d_append_error(_("Value operand for NOT"));
return NODE_ERROR;
}
else {
@@ -947,7 +951,7 @@
}
default:
- append_error("Unknown operator %d\n", nptr->oper);
+ db_d_append_error(_("Unknown operator %d"), nptr->oper);
return NODE_FALSE;
}
}
@@ -1016,8 +1020,8 @@
case SQLP_NODE_COLUMN:
ccol = find_column(tab, nptr->column_name);
if (ccol == -1) {
- append_error("Column '%s' not found\n", nptr->column_name);
- return (-1);
+ db_d_append_error(_("Column '%s' not found"), nptr->column_name);
+ return -1;
}
col = &(db.tables[tab].cols[ccol]);
switch (col->type) {
@@ -1054,8 +1058,7 @@
case SQLP_MLTP:
case SQLP_DIV:
if (left == SQLP_S || right == SQLP_S) {
- append_error
- ("Arithmetical operation with strings is not allowed\n");
+ db_d_append_error(_("Arithmetical operation with strings is not allowed"));
return -1;
}
else if (left == SQLP_NULL || right == SQLP_NULL) {
@@ -1077,8 +1080,7 @@
case SQLP_NE:
if ((left == SQLP_S && (right == SQLP_I || right == SQLP_D)) ||
(right == SQLP_S && (left == SQLP_I || left == SQLP_D))) {
- append_error
- ("Comparison between string and number is not allowed\n");
+ db_d_append_error(_("Comparison between string and number is not allowed"));
return -1;
}
else if (left == SQLP_NULL || right == SQLP_NULL) {
@@ -1093,8 +1095,8 @@
case SQLP_GT:
case SQLP_GE:
if (left == SQLP_S || right == SQLP_S) {
- append_error("Comparison '%s' between strings not allowed\n",
- sqpOperatorName(nptr->oper));
+ db_d_append_error(_("Comparison '%s' between strings not allowed"),
+ sqpOperatorName(nptr->oper));
return -1;
}
else if (left == SQLP_NULL || right == SQLP_NULL) {
@@ -1107,7 +1109,7 @@
case SQLP_MTCH:
if (left == SQLP_I || left == SQLP_D || right == SQLP_I ||
right == SQLP_D) {
- append_error("Match (~) between numbers not allowed\n");
+ db_d_append_error(_("Match (~) between numbers not allowed"));
return -1;
}
else if (left == SQLP_NULL || right == SQLP_NULL) {
@@ -1146,7 +1148,7 @@
}
default:
- append_error("Unknown operator %d\n", nptr->oper);
+ db_d_append_error(_("Unknown operator %d"), nptr->oper);
return -1;
}
}
Modified: grass/trunk/db/drivers/dbf/describe.c
===================================================================
--- grass/trunk/db/drivers/dbf/describe.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/dbf/describe.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -18,6 +18,7 @@
#include <grass/dbmi.h>
#include <grass/datetime.h>
#include <grass/shapefil.h>
+#include <grass/glocale.h>
#include "globals.h"
#include "proto.h"
@@ -30,8 +31,9 @@
tab = find_table(name);
if (tab == -1) {
- append_error("Table '%s' doesn't exist", db_get_string(table_name));
- report_error();
+ db_d_append_error(_("Table '%s' doesn't exist"),
+ db_get_string(table_name));
+ db_d_report_error();
return DB_FAILED;
}
describe_table(tab, NULL, 0, table);
Modified: grass/trunk/db/drivers/dbf/driver.c
===================================================================
--- grass/trunk/db/drivers/dbf/driver.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/dbf/driver.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -17,9 +17,11 @@
#include <grass/dbmi.h>
#include "globals.h"
+#include "proto.h"
int db__driver_init(int argc, char *argv[])
{
+ init_error();
return DB_OK;
}
Modified: grass/trunk/db/drivers/dbf/error.c
===================================================================
--- grass/trunk/db/drivers/dbf/error.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/dbf/error.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -8,38 +8,5 @@
/* init error message */
void init_error(void)
{
- if (!errMsg) {
- errMsg = (dbString *) G_malloc(sizeof(dbString));
- db_init_string(errMsg);
- }
-
- db_set_string(errMsg, "DBMI-DBF driver error:\n");
+ db_d_init_error("DBF");
}
-
-/* append error message */
-void append_error(const char *fmt, ...)
-{
- FILE *fp = NULL;
- char *work = NULL;
- int count = 0;
- va_list ap;
-
- va_start(ap, fmt);
- if ((fp = tmpfile())) {
- count = vfprintf(fp, fmt, ap);
- if (count >= 0 && (work = G_calloc(count + 1, 1))) {
- rewind(fp);
- fread(work, 1, count, fp);
- db_append_string(errMsg, work);
- G_free(work);
- }
- fclose(fp);
- }
- va_end(ap);
-}
-
-void report_error(void)
-{
- db_append_string(errMsg, "\n");
- db_error(db_get_string(errMsg));
-}
Modified: grass/trunk/db/drivers/dbf/execute.c
===================================================================
--- grass/trunk/db/drivers/dbf/execute.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/dbf/execute.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -15,6 +15,7 @@
*
*****************************************************************************/
#include <grass/dbmi.h>
+#include <grass/glocale.h>
#include "globals.h"
#include "proto.h"
@@ -28,8 +29,8 @@
ret = execute(s, NULL);
if (ret == DB_FAILED) {
- append_error("Error in db_execute_immediate()");
- report_error();
+ db_d_append_error(_("Unable to execute statement."));
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/dbf/main.c
===================================================================
--- grass/trunk/db/drivers/dbf/main.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/dbf/main.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -30,7 +30,6 @@
char *name;
init_dbdriver();
- init_error();
/* Do not call G_getenv() nor other functions reading GISRC here! It may be that grass variables are
* not available here, but will be set in db_driver() */
Modified: grass/trunk/db/drivers/dbf/proto.h
===================================================================
--- grass/trunk/db/drivers/dbf/proto.h 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/dbf/proto.h 2012-01-25 14:06:13 UTC (rev 50443)
@@ -1,7 +1,5 @@
/* error.c */
void init_error(void);
-void append_error(const char *fmt, ...);
-void report_error(void);
int save_string(VALUE *, char *);
Modified: grass/trunk/db/drivers/dbf/select.c
===================================================================
--- grass/trunk/db/drivers/dbf/select.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/dbf/select.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -17,6 +17,7 @@
#include <grass/dbmi.h>
#include <grass/shapefil.h>
+#include <grass/glocale.h>
#include "globals.h"
#include "proto.h"
@@ -40,8 +41,8 @@
ret = execute(sql, c);
if (ret == DB_FAILED) {
- append_error("Error in db_open_select_cursor()");
- report_error();
+ db_d_append_error(_("Unable to open cursor."));
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/dbf/table.c
===================================================================
--- grass/trunk/db/drivers/dbf/table.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/dbf/table.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -34,6 +34,7 @@
#include <grass/dbmi.h>
#include <grass/shapefil.h>
#include <grass/gis.h>
+#include <grass/glocale.h>
#include "globals.h"
#include "proto.h"
@@ -113,7 +114,7 @@
/* load */
dbf = DBFOpen(db.tables[t].file, "r");
if (dbf == NULL) {
- append_error("Cannot open dbf file.\n");
+ db_d_append_error(_("Unable to open DBF file."));
return DB_FAILED;
}
@@ -166,7 +167,7 @@
dbf = DBFOpen(db.tables[t].file, "r");
if (dbf == NULL) {
- append_error("Cannot open dbf file.\n");
+ db_d_append_error(_("Unable to open DBF file."));
return DB_FAILED;
}
@@ -305,7 +306,8 @@
/* Copy */
if (G_rename_file(name, db.tables[t].file)) {
- append_error("Cannot move %s\nto %s\n", name, db.tables[t].file);
+ db_d_append_error(_("Unable to move '%s' to '%s'."),
+ name, db.tables[t].file);
return DB_FAILED;
};
Modified: grass/trunk/db/drivers/mysql/create_table.c
===================================================================
--- grass/trunk/db/drivers/mysql/create_table.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/mysql/create_table.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -29,8 +29,6 @@
G_debug(3, "db__driver_create_table()");
- init_error();
-
db_init_string(&sql);
db_set_string(&sql, "CREATE TABLE ");
@@ -106,11 +104,11 @@
G_debug(3, " SQL: %s", db_get_string(&sql));
if (mysql_query(connection, db_get_string(&sql)) != 0) {
- append_error("Cannot create table:\n");
- append_error(db_get_string(&sql));
- append_error("\n");
- append_error(mysql_error(connection));
- report_error();
+ db_d_append_error("%s\n%s\%s",
+ _("Unable to create table:"),
+ db_get_string(&sql),
+ mysql_error(connection));
+ db_d_report_error();
db_free_string(&sql);
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/mysql/cursor.c
===================================================================
--- grass/trunk/db/drivers/mysql/cursor.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/mysql/cursor.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -22,8 +22,6 @@
{
cursor *c;
- init_error();
-
/* get my cursor via the dbc token */
c = (cursor *) db_find_token(db_get_cursor_token(dbc));
if (c == NULL)
@@ -43,7 +41,7 @@
/* allocate the cursor */
c = (cursor *) db_malloc(sizeof(cursor));
if (c == NULL) {
- append_error(_("Cannot allocate cursor."));
+ db_d_append_error(_("Unable allocate cursor."));
return NULL;
}
@@ -52,7 +50,7 @@
/* tokenize it */
c->token = db_new_token(c);
if (c->token < 0) {
- append_error(_("Cannot ad new token."));
+ db_d_append_error(_("Unable to add dnew token."));
return NULL;
}
Modified: grass/trunk/db/drivers/mysql/db.c
===================================================================
--- grass/trunk/db/drivers/mysql/db.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/mysql/db.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -25,7 +25,6 @@
dbConnection default_connection;
MYSQL *res;
- init_error();
db_get_connection(&default_connection);
name = db_get_handle_dbname(handle);
@@ -42,7 +41,7 @@
CONNPAR connpar;
if (parse_conn(name, &connpar) == DB_FAILED) {
- report_error();
+ db_d_report_error();
return DB_FAILED;
}
@@ -58,9 +57,10 @@
connpar.dbname, connpar.port, NULL, 0);
if (res == NULL) {
- append_error(_("Cannot connect to MySQL: "));
- append_error(mysql_error(connection));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Connection failed."),
+ mysql_error(connection));
+ db_d_report_error();
return DB_FAILED;
}
}
@@ -70,7 +70,6 @@
int db__driver_close_database(void)
{
- init_error();
mysql_close(connection); /* this will also release connection */
return DB_OK;
Modified: grass/trunk/db/drivers/mysql/dbe.c
===================================================================
--- grass/trunk/db/drivers/mysql/dbe.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/mysql/dbe.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -25,7 +25,6 @@
dbConnection default_connection;
MYSQL *res;
- init_error();
db_get_connection(&default_connection);
name = G_store(db_get_handle_dbname(handle));
@@ -43,7 +42,7 @@
char *buf;
if (!replace_variables(name, &datadir, &database)) {
- append_error(_("Cannot parse MySQL embedded database name"));
+ append_error(_("Unable parse MySQL embedded database name"));
append_error(mysql_error(connection));
report_error();
return DB_FAILED;
@@ -78,7 +77,7 @@
free(database);
if (res == NULL) {
- append_error(_("Cannot connect to MySQL embedded server: "));
+ append_error(_("Unable to connect to MySQL embedded server: "));
append_error(mysql_error(connection));
report_error();
return DB_FAILED;
@@ -90,7 +89,6 @@
int db__driver_close_database(void)
{
- init_error();
mysql_close(connection); /* this will also release connection */
mysql_server_end();
Modified: grass/trunk/db/drivers/mysql/describe.c
===================================================================
--- grass/trunk/db/drivers/mysql/describe.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/mysql/describe.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -28,26 +28,27 @@
db_append_string(&sql, " where 1 = 0");
if (mysql_query(connection, db_get_string(&sql)) != 0) {
- append_error(db_get_string(&sql));
- append_error("\n");
- append_error(mysql_error(connection));
- report_error();
+ db_d_append_error("%s\n%s\n%s",
+ _("Unable to describe table:"),
+ db_get_string(&sql),
+ mysql_error(connection));
+ db_d_report_error();
return DB_FAILED;
}
res = mysql_store_result(connection);
if (res == NULL) {
- append_error(db_get_string(&sql));
- append_error("\n");
- append_error(mysql_error(connection));
- report_error();
+ db_d_append_error("%s\n%s",
+ db_get_string(&sql),
+ mysql_error(connection));
+ db_d_report_error();
return DB_FAILED;
}
if (describe_table(res, table, NULL) == DB_FAILED) {
- append_error("Cannot describe table\n");
- report_error();
+ db_d_append_error(_("Unable to describe table"));
+ db_d_report_error();
mysql_free_result(res);
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/mysql/error.c
===================================================================
--- grass/trunk/db/drivers/mysql/error.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/mysql/error.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -13,7 +13,6 @@
#include <grass/gis.h>
#include <grass/dbmi.h>
-#include <grass/glocale.h>
#include "globals.h"
#include "proto.h"
@@ -21,22 +20,5 @@
/* init error message */
void init_error(void)
{
- if (!errMsg) {
- errMsg = (dbString *) G_malloc(sizeof(dbString));
- db_init_string(errMsg);
- }
-
- db_set_string(errMsg, _("DBMI-MySQL driver error:\n"));
+ db_d_init_error("MySQL");
}
-
-/* append error message */
-void append_error(const char *msg)
-{
- db_append_string(errMsg, (char *)msg);
-}
-
-void report_error(void)
-{
- db_append_string(errMsg, "\n");
- db_error(db_get_string(errMsg));
-}
Modified: grass/trunk/db/drivers/mysql/execute.c
===================================================================
--- grass/trunk/db/drivers/mysql/execute.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/mysql/execute.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -22,8 +22,6 @@
{
char *str;
- init_error();
-
/* In addition to standard escape character ' (apostrophe)
* MySQL supports also \ (backslash). Because this is not SQL
* standard, GRASS modules cannot escape all \ in the text
@@ -39,11 +37,11 @@
G_debug(3, "Escaped SQL: %s", str);
if (mysql_query(connection, str) != 0) {
- append_error("Cannot execute: \n");
- append_error(str);
- append_error("\n");
- append_error(mysql_error(connection));
- report_error();
+ db_d_append_error("%s\n%s\n%s",
+ _("Unable to execute:"),
+ str,
+ mysql_error(connection));
+ db_d_report_error();
if (str)
G_free(str);
return DB_FAILED;
@@ -59,12 +57,11 @@
{
G_debug(2, "mysql: START TRANSACTION");
- init_error();
-
if (mysql_query(connection, "START TRANSACTION") != 0) {
- append_error("Cannot start transaction: \n");
- append_error(mysql_error(connection));
- report_error();
+ db_d_append_error("%s %s",
+ _("Unable to start transaction:"),
+ mysql_error(connection));
+ db_d_report_error();
return DB_FAILED;
}
@@ -75,12 +72,11 @@
{
G_debug(2, "mysql: COMMIT");
- init_error();
-
if (mysql_query(connection, "COMMIT") != 0) {
- append_error("Cannot commit transaction: \n");
- append_error(mysql_error(connection));
- report_error();
+ db_d_append_error("%s %s",
+ _("Unable to commit transaction:"),
+ mysql_error(connection));
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/mysql/fetch.c
===================================================================
--- grass/trunk/db/drivers/mysql/fetch.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/mysql/fetch.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -31,8 +31,8 @@
/* get the cursor by its token */
if (!(c = (cursor *) db_find_token(token))) {
- append_error(_("Cursor not found"));
- report_error();
+ db_d_append_error(_("Cursor not found"));
+ db_d_report_error();
return DB_FAILED;
}
@@ -49,9 +49,9 @@
case DB_FIRST:
case DB_LAST:
default:
- append_error(_("Cursor position is not supported "
- "by MySQL driver"));
- report_error();
+ db_d_append_error(_("Cursor position is not supported "
+ "by MySQL driver"));
+ db_d_report_error();
return DB_FAILED;
}
@@ -187,17 +187,19 @@
&(value->t.minute), &(value->t.seconds));
if (ns != 6) {
- append_error(_("Cannot scan timestamp: "));
- append_error(val);
- report_error();
+ db_d_append_error("%s %s",
+ _("Unable to scan timestamp: "),
+ val);
+ db_d_report_error();
return DB_FAILED;
}
break;
default:
- append_error(_("Unknown timestamp format: "));
- append_error(val);
- report_error();
+ db_d_append_error("%s %s",
+ _("Unknown timestamp format: "),
+ val);
+ db_d_report_error();
return DB_FAILED;
}
}
@@ -209,9 +211,10 @@
&(value->t.month), &(value->t.day));
if (ns != 3) {
- append_error(_("Cannot scan date: "));
- append_error(val);
- report_error();
+ db_d_append_error("%s %s",
+ _("Unable to scan date: "),
+ val);
+ db_d_report_error();
return DB_FAILED;
}
break;
@@ -222,9 +225,10 @@
&(value->t.minute), &(value->t.seconds));
if (ns != 3) {
- append_error(_("Cannot scan time: "));
- append_error(val);
- report_error();
+ db_d_append_error("%s %s",
+ _("Unable to scan time: "),
+ val);
+ db_d_report_error();
return DB_FAILED;
}
break;
@@ -237,9 +241,10 @@
&(value->t.minute), &(value->t.seconds));
if (ns != 6) {
- append_error(_("Cannot scan datetime: "));
- append_error(val);
- report_error();
+ db_d_append_error("%s %s",
+ _("Unable to scan datetime:"),
+ val);
+ db_d_report_error();
return DB_FAILED;
}
break;
@@ -268,8 +273,8 @@
/* get the cursor by its token */
if (!(c = (cursor *) db_find_token(token))) {
- append_error("Cursor not found");
- report_error();
+ db_d_append_error(_("Cursor not found"));
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/mysql/index.c
===================================================================
--- grass/trunk/db/drivers/mysql/index.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/mysql/index.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -24,7 +24,6 @@
G_debug(3, "db__create_index()");
db_init_string(&sql);
- init_error();
ncols = db_get_index_number_of_columns(index);
@@ -52,11 +51,11 @@
G_debug(3, " SQL: %s", db_get_string(&sql));
if (mysql_query(connection, db_get_string(&sql)) != 0) {
- append_error("Cannot create index:\n");
- append_error(db_get_string(&sql));
- append_error("\n");
- append_error(mysql_error(connection));
- report_error();
+ db_d_append_error("%s\n%s\n%s",
+ _("Unable to create index:"),
+ db_get_string(&sql),
+ mysql_error(connection));
+ db_d_report_error();
db_free_string(&sql);
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/mysql/listtab.c
===================================================================
--- grass/trunk/db/drivers/mysql/listtab.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/mysql/listtab.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -33,9 +33,10 @@
res = mysql_list_tables(connection, NULL);
if (res == NULL) {
- append_error(_("Cannot get list of tables:\n"));
- append_error(mysql_error(connection));
- report_error();
+ db_d_append_error("%s\%s",
+ _("Unable get list of tables:"),
+ mysql_error(connection));
+ db_d_report_error();
return DB_FAILED;
}
mysql_store_result(connection);
Modified: grass/trunk/db/drivers/mysql/parse.c
===================================================================
--- grass/trunk/db/drivers/mysql/parse.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/mysql/parse.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -57,9 +57,10 @@
long port = atol(tokens[i] + 5);
if (port <= 0) {
- append_error(_("Wrong port number in MySQL database "
- "definition: "));
- append_error(tokens[i] + 5);
+ db_d_append_error("%s %s",
+ _("Wrong port number in MySQL database "
+ "definition: "),
+ tokens[i] + 5);
return DB_FAILED;
}
conn->port = (unsigned int)port;
@@ -76,9 +77,10 @@
"is not supported, use db.login"));
}
else {
- append_error(_("Unknown option in database definition for "));
- append_error("MySQL: ");
- append_error(tokens[i]);
+ db_d_append_error("%s %s",
+ _("Unknown option in database definition "
+ "for MySQL: "),
+ tokens[i]);
return DB_FAILED;
}
i++;
Modified: grass/trunk/db/drivers/mysql/proto.h
===================================================================
--- grass/trunk/db/drivers/mysql/proto.h 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/mysql/proto.h 2012-01-25 14:06:13 UTC (rev 50443)
@@ -1,7 +1,5 @@
/* error.c */
void init_error(void);
-void append_error(const char *);
-void report_error(void);
/* cursor.c */
cursor *alloc_cursor();
Modified: grass/trunk/db/drivers/mysql/select.c
===================================================================
--- grass/trunk/db/drivers/mysql/select.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/mysql/select.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -24,8 +24,6 @@
dbTable *table;
char *str;
- init_error();
-
/* allocate cursor */
c = alloc_cursor();
if (c == NULL)
@@ -40,13 +38,13 @@
G_debug(3, "Escaped SQL: %s", str);
if (mysql_query(connection, str) != 0) {
- append_error(_("Cannot select data: \n"));
- append_error(db_get_string(sel));
- append_error("\n");
- append_error(mysql_error(connection));
+ db_d_append_error("%s\n%s\n%s",
+ _("Unable to select data:"),
+ db_get_string(sel),
+ mysql_error(connection));
if (str)
G_free(str);
- report_error();
+ db_d_report_error();
return DB_FAILED;
}
@@ -55,16 +53,16 @@
c->res = mysql_store_result(connection);
if (c->res == NULL) {
- append_error(db_get_string(sel));
- append_error("\n");
- append_error(mysql_error(connection));
- report_error();
+ db_d_append_error("%s\n%s",
+ db_get_string(sel),
+ mysql_error(connection));
+ db_d_report_error();
return DB_FAILED;
}
if (describe_table(c->res, &table, c) == DB_FAILED) {
- append_error("Cannot describe table\n");
- report_error();
+ db_d_append_error(_("Unable to describe table."));
+ db_d_report_error();
mysql_free_result(c->res);
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/odbc/connect.c
===================================================================
--- grass/trunk/db/drivers/odbc/connect.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/odbc/connect.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -10,14 +10,16 @@
/* Allocate Environment handle and register version */
ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &ODenvi);
if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
- report_error("SQLAllocHandle()");
+ db_d_append_error("SQLAllocHandle()");
+ db_d_report_error();
return DB_FAILED;
}
ret =
SQLSetEnvAttr(ODenvi, SQL_ATTR_ODBC_VERSION, (void *)SQL_OV_ODBC3, 0);
if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
- report_error("SQLSetEnvAttr()");
+ db_d_append_error("SQLSetEnvAttr()");
+ db_d_report_error();
SQLFreeHandle(SQL_HANDLE_ENV, ODenvi);
return DB_FAILED;
}
@@ -25,7 +27,8 @@
/* Allocate connection handle */
ret = SQLAllocHandle(SQL_HANDLE_DBC, ODenvi, &ODconn);
if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
- report_error("SQLAllocHandle()");
+ db_d_append_error("SQLAllocHandle()");
+ db_d_report_error();
SQLFreeHandle(SQL_HANDLE_ENV, ODenvi);
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/odbc/create_table.c
===================================================================
--- grass/trunk/db/drivers/odbc/create_table.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/odbc/create_table.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -28,9 +28,9 @@
if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
SQLGetDiagRec(SQL_HANDLE_STMT, c->stmt, 1, NULL, &err, msg,
sizeof(msg), NULL);
- G_asprintf(&emsg, "SQLExecDirect():\n%s\n%s (%d)\n",
- db_get_string(&sql), msg, (int)err);
- report_error(emsg);
+ db_d_append_error("SQLExecDirect():\n%s\n%s (%d)\n",
+ db_get_string(&sql), msg, (int)err);
+ db_d_report_error();
G_free(emsg);
return DB_FAILED;
Modified: grass/trunk/db/drivers/odbc/cursor.c
===================================================================
--- grass/trunk/db/drivers/odbc/cursor.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/odbc/cursor.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -1,6 +1,7 @@
+#include <stdio.h>
#include <grass/dbmi.h>
-#include <stdio.h>
#include <grass/gis.h>
+#include <grass/glocale.h>
#include "odbc.h"
#include "globals.h"
#include "proto.h"
@@ -27,13 +28,13 @@
cursor *c;
SQLRETURN ret;
char msg[OD_MSG];
- char *emsg = NULL;
SQLINTEGER err;
/* allocate the cursor */
c = (cursor *) db_malloc(sizeof(cursor));
if (c == NULL) {
- report_error("allocate cursor");
+ db_d_append_error(_("Unable to allocate cursor"));
+ db_d_report_error();
return c;
}
@@ -41,10 +42,8 @@
if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
SQLGetDiagRec(SQL_HANDLE_DBC, ODconn, 1, NULL, &err, msg, sizeof(msg),
NULL);
- G_asprintf(&emsg, "AllocStatement()\n%s (%d)\n", msg, (int)err);
- report_error(emsg);
- G_free(emsg);
-
+ db_d_append_error( "AllocStatement()\n%s (%d)\n", msg, (int)err);
+ db_d_report_error();
return c;
}
@@ -53,7 +52,8 @@
if (c->token < 0) {
free_cursor(c);
c = NULL;
- report_error("db_new_token()");
+ db_d_append_error(_("Unable to add new token."));
+ db_d_report_error();
}
return c;
Modified: grass/trunk/db/drivers/odbc/db.c
===================================================================
--- grass/trunk/db/drivers/odbc/db.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/odbc/db.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -10,7 +10,6 @@
{
char msg[OD_MSG];
const char *name;
- char *emsg = NULL;
SQLRETURN ret;
SQLINTEGER err;
dbConnection connection;
@@ -34,10 +33,9 @@
if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
SQLGetDiagRec(SQL_HANDLE_DBC, ODconn, 1, NULL, &err, msg, sizeof(msg),
NULL);
- G_asprintf(&emsg, "SQLConnect():\n%s (%d)\n", msg, (int)err);
- report_error(emsg);
- G_free(emsg);
-
+ db_d_append_error("SQLConnect():\n%s (%d)\n", msg, (int)err);
+ db_d_report_error();
+
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/odbc/describe.c
===================================================================
--- grass/trunk/db/drivers/odbc/describe.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/odbc/describe.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -17,7 +17,6 @@
cursor *c;
char s[100];
char msg[OD_MSG];
- char *emsg;
/* allocate cursor */
c = alloc_cursor();
@@ -34,9 +33,9 @@
if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
SQLGetDiagRec(SQL_HANDLE_STMT, c->stmt, 1, NULL, &err, msg,
sizeof(msg), NULL);
- G_asprintf(&emsg, "SQLExecDirect():\n%s\n%s (%d)\n", s, msg,
- (int)err);
- report_error(emsg);
+ db_d_append_error("SQLExecDirect():\n%s\n%s (%d)\n", s, msg,
+ (int)err);
+ db_d_report_error();
return DB_FAILED;
}
@@ -75,7 +74,8 @@
/* get the number of colummns */
ret = SQLNumResultCols(stmt, &ncols);
if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
- report_error("SQLNumResultCols()");
+ db_d_append_error("SQLNumResultCols()");
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/odbc/driver.c
===================================================================
--- grass/trunk/db/drivers/odbc/driver.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/odbc/driver.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -1,10 +1,11 @@
#include <grass/dbmi.h>
#include "odbc.h"
#include "globals.h"
+#include "proto.h"
-int db__driver_init(argc, argv)
- char *argv[];
+int db__driver_init(int argc, char **argv)
{
+ init_error();
return DB_OK;
}
Modified: grass/trunk/db/drivers/odbc/error.c
===================================================================
--- grass/trunk/db/drivers/odbc/error.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/odbc/error.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -18,20 +18,8 @@
#include "odbc.h"
#include "globals.h"
-
-/**
- * \fn void report_error (char *err)
- *
- * \brief Reports database driver error.
- *
- * \param[in] err error message
- */
-
-void report_error(char *err)
+/* init error message */
+void init_error(void)
{
- char *msg = NULL;
-
- G_asprintf(&msg, "DBMI-ODBC driver error: %s", err);
- db_error(msg);
- G_free(msg);
+ db_d_init_error("ODBC");
}
Modified: grass/trunk/db/drivers/odbc/execute.c
===================================================================
--- grass/trunk/db/drivers/odbc/execute.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/odbc/execute.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -23,7 +23,6 @@
int db__driver_execute_immediate(dbString * sql)
{
char *s, msg[OD_MSG];
- char *emsg;
cursor *c;
SQLRETURN ret;
SQLINTEGER err;
@@ -39,10 +38,9 @@
if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
SQLGetDiagRec(SQL_HANDLE_STMT, c->stmt, 1, NULL, &err, msg,
sizeof(msg), NULL);
- G_asprintf(&emsg, "SQLExecDirect():\n%s\n%s (%d)\n", s, msg,
- (int)err);
- report_error(emsg);
- G_free(emsg);
+ db_d_append_error("SQLExecDirect():\n%s\n%s (%d)\n", s, msg,
+ (int)err);
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/odbc/listdb.c
===================================================================
--- grass/trunk/db/drivers/odbc/listdb.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/odbc/listdb.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -1,13 +1,10 @@
#include <grass/dbmi.h>
+#include <grass/glocale.h>
#include "odbc.h"
#include "globals.h"
#include "proto.h"
-int db__driver_list_databases(dbpath, npaths, dblist, dbcount)
- dbString *dbpath;
- int npaths;
- dbHandle **dblist;
- int *dbcount;
+int db__driver_list_databases(dbString *dbpath, int npaths, dbHandle **dblist, int *dbcount)
{
int i, count = 0;
dbHandle *list;
@@ -29,7 +26,8 @@
list = db_alloc_handle_array(count);
if (list == NULL) {
- report_error("db_alloc_handle_array()");
+ db_d_append_error(_("Unable to allocate handle."));
+ db_d_report_error();
return DB_FAILED;
}
@@ -39,7 +37,8 @@
NULL, desc, sizeof(desc), NULL) == SQL_SUCCESS) {
db_init_handle(&list[i]);
if (db_set_handle(&list[i], dsn, desc) != DB_OK) {
- report_error("db_set_handle()");
+ db_d_append_error(_("Unable to set handle"));
+ db_d_report_error();
db_free_handle_array(list, count);
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/odbc/listtab.c
===================================================================
--- grass/trunk/db/drivers/odbc/listtab.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/odbc/listtab.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -33,7 +33,8 @@
ret = SQLTables(c->stmt, NULL, 0, NULL, 0, NULL, 0, ttype, sizeof(ttype));
if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) {
- report_error("SQLTables()");
+ db_d_append_error("SQLTables()");
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/odbc/proto.h
===================================================================
--- grass/trunk/db/drivers/odbc/proto.h 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/odbc/proto.h 2012-01-25 14:06:13 UTC (rev 50443)
@@ -1,5 +1,5 @@
/* error.c */
-void report_error(char *err);
+void init_error();
/* connect.c */
int open_connection();
Modified: grass/trunk/db/drivers/odbc/select.c
===================================================================
--- grass/trunk/db/drivers/odbc/select.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/odbc/select.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -4,15 +4,12 @@
#include "proto.h"
#include <stdio.h>
-int db__driver_open_select_cursor(sel, dbc, mode)
- dbString *sel;
- dbCursor *dbc;
- int mode;
+int db__driver_open_select_cursor(dbString *sel, dbCursor *dbc, int mode)
{
cursor *c;
SQLRETURN ret;
SQLINTEGER err;
- char *sql, msg[OD_MSG], emsg[DB_MSG];
+ char *sql, msg[OD_MSG];
dbTable *table;
int nrows;
@@ -30,8 +27,8 @@
if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
SQLGetDiagRec(SQL_HANDLE_STMT, c->stmt, 1, NULL, &err, msg,
sizeof(msg), NULL);
- sprintf(emsg, "SQLExecDirect():\n%s\n%s (%d)\n", sql, msg, (int)err);
- report_error(emsg);
+ db_d_append_error("SQLExecDirect():\n%s\n%s (%d)", sql, msg, (int)err);
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/odbc/table.c
===================================================================
--- grass/trunk/db/drivers/odbc/table.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/odbc/table.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -17,6 +17,7 @@
#include <string.h>
#include <grass/dbmi.h>
#include <grass/gis.h>
+#include <grass/glocale.h>
#include "odbc.h"
#include "globals.h"
#include "proto.h"
@@ -127,7 +128,6 @@
cursor *c;
SQLRETURN ret;
char msg[OD_MSG];
- char *emsg = NULL;
SQLINTEGER err;
SQLCHAR ttype[50], *tname;
SQLINTEGER nrow = 0;
@@ -142,21 +142,23 @@
ret = SQLTables(c->stmt, NULL, 0, NULL, 0, tname, sizeof(tname), NULL, 0);
if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
- report_error("SQLTables()");
+ db_d_append_error("SQLTables()");
+ db_d_report_error();
return DB_FAILED;
}
/* Get number of rows */
ret = SQLRowCount(c->stmt, &nrow);
if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
- report_error("SQLRowCount()");
+ db_d_append_error("SQLRowCount()");
+ db_d_report_error();
return DB_FAILED;
}
if (nrow == 0) {
- G_asprintf(&emsg, "Table %s doesn't exist\n", tname);
- report_error(emsg);
- G_free(emsg);
+ db_d_append_error(_("Table %s doesn't exist"), tname);
+ db_d_report_error();
+
return DB_FAILED;
}
@@ -171,11 +173,10 @@
sprintf(cmd, "DROP VIEW %s", tname);
}
else {
- G_asprintf(&emsg, "Table %s isn't 'TABLE' or 'VIEW' but %s\n", tname,
- ttype);
- report_error(emsg);
- G_free(emsg);
-
+ db_d_append_error(_("Table %s isn't 'TABLE' or 'VIEW' but %s"),
+ tname, ttype);
+ db_d_report_error();
+
return DB_FAILED;
}
@@ -185,11 +186,10 @@
if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
SQLGetDiagRec(SQL_HANDLE_STMT, c->stmt, 1, NULL, &err, msg,
sizeof(msg), NULL);
- G_asprintf(&emsg, "SQLExecDirect():\n%s\n%s (%d)\n", cmd, msg,
- (int)err);
- report_error(emsg);
- G_free(emsg);
-
+ db_d_append_error("SQLExecDirect():\n%s\n%s (%d)", cmd, msg,
+ (int)err);
+ db_d_report_error();
+
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/ogr/cursor.c
===================================================================
--- grass/trunk/db/drivers/ogr/cursor.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/ogr/cursor.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -36,8 +36,6 @@
G_debug(3, "db_driver_close_cursor()");
- init_error();
-
/* get my cursor via the dbc token */
c = (cursor *) db_find_token(db_get_cursor_token(dbc));
if (c == NULL)
@@ -64,7 +62,7 @@
/* allocate the cursor */
c = (cursor *) db_malloc(sizeof(cursor));
if (c == NULL) {
- append_error(_("Unable to allocate cursor"));
+ db_d_append_error(_("Unable to allocate cursor"));
return NULL;
}
@@ -73,7 +71,7 @@
/* tokenize it */
c->token = db_new_token(c);
if (c->token < 0) {
- append_error(_("Unable to add new token"));
+ db_d_append_error(_("Unable to add new token"));
return NULL;
}
return c;
Modified: grass/trunk/db/drivers/ogr/db.c
===================================================================
--- grass/trunk/db/drivers/ogr/db.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/ogr/db.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -36,7 +36,6 @@
const char *name;
dbConnection connection;
- init_error();
db_get_connection(&connection);
name = db_get_handle_dbname(handle);
@@ -51,8 +50,8 @@
hDs = OGROpen(name, TRUE, NULL);
if (hDs == NULL) {
- append_error(_("Unable to open OGR data source"));
- report_error();
+ db_d_append_error(_("Unable to open OGR data source"));
+ db_d_report_error();
return DB_FAILED;
}
@@ -71,7 +70,6 @@
{
G_debug(3, "db_driver_close_database()");
- init_error();
OGR_DS_Destroy(hDs);
G_debug(3, "Database closed");
Modified: grass/trunk/db/drivers/ogr/describe.c
===================================================================
--- grass/trunk/db/drivers/ogr/describe.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/ogr/describe.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -52,16 +52,16 @@
}
if (hLayer == NULL) {
- append_error(_("OGR layer <%s> does not exist\n"),
- db_get_string(table_name));
- report_error();
+ db_d_append_error(_("OGR layer <%s> does not exist\n"),
+ db_get_string(table_name));
+ db_d_report_error();
return DB_FAILED;
}
G_debug(3, "->>");
if (describe_table(hLayer, table, NULL) == DB_FAILED) {
- append_error(_("Unable to describe table\n"));
- report_error();
+ db_d_append_error(_("Unable to describe table\n"));
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/ogr/error.c
===================================================================
--- grass/trunk/db/drivers/ogr/error.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/ogr/error.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -17,57 +17,14 @@
#include <grass/gis.h>
#include <grass/dbmi.h>
-#include <grass/glocale.h>
#include <ogr_api.h>
#include "globals.h"
#include "proto.h"
-/*!
- \brief Init error message
-*/
+/* init error message */
void init_error(void)
{
- if (!errMsg) {
- errMsg = (dbString *) G_malloc(sizeof(dbString));
- db_init_string(errMsg);
- }
-
- db_set_string(errMsg, _("DBMI-OGR driver error:\n"));
+ db_d_init_error("OGR");
}
-
-/*!
- \brief Append error message
-
- \param fmt formatted string
-*/
-void append_error(const char *fmt, ...)
-{
- FILE *fp = NULL;
- char *work = NULL;
- int count = 0;
- va_list ap;
-
- va_start(ap, fmt);
- if ((fp = tmpfile())) {
- count = vfprintf(fp, fmt, ap);
- if (count >= 0 && (work = G_calloc(count + 1, 1))) {
- rewind(fp);
- fread(work, 1, count, fp);
- db_append_string(errMsg, work);
- G_free(work);
- }
- fclose(fp);
- }
- va_end(ap);
-}
-
-/*!
- \brief Report errors
-*/
-void report_error(void)
-{
- db_append_string(errMsg, "\n");
- db_error(db_get_string(errMsg));
-}
Modified: grass/trunk/db/drivers/ogr/execute.c
===================================================================
--- grass/trunk/db/drivers/ogr/execute.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/ogr/execute.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -37,8 +37,6 @@
G_debug(1, "db__driver_execute_immediate():");
- init_error();
-
G_debug(3, "\tSQL: '%s'", db_get_string(sql));
/* try RDBMS SQL */
@@ -55,8 +53,8 @@
/* get OGR layer */
hLayer = OGR_DS_GetLayerByName(hDs, table);
if (!hLayer) {
- append_error(_("OGR layer <%s> not found"), table);
- report_error();
+ db_d_append_error(_("OGR layer <%s> not found"), table);
+ db_d_report_error();
return DB_FAILED;
}
@@ -68,9 +66,9 @@
for (i = 0; i < ncols; i++) {
cols[i].index = OGR_FD_GetFieldIndex(hFeatureDefn, cols[i].name);
if (cols[i].index < 0) {
- append_error(_("Column <%s> not found in table <%s>"),
- cols[i].name, table);
- report_error();
+ db_d_append_error(_("Column <%s> not found in table <%s>"),
+ cols[i].name, table);
+ db_d_report_error();
return DB_FAILED;
}
cols[i].qindex = OGR_FD_GetFieldIndex(hFeatureDefn, cols[i].value);
Modified: grass/trunk/db/drivers/ogr/fetch.c
===================================================================
--- grass/trunk/db/drivers/ogr/fetch.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/ogr/fetch.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -52,8 +52,8 @@
/* get the cursor by its token */
if (!(c = (cursor *) db_find_token(token))) {
- append_error(_("Cursor not found"));
- report_error();
+ db_d_append_error(_("Cursor not found"));
+ db_d_report_error();
return DB_FAILED;
}
@@ -68,8 +68,8 @@
case DB_CURRENT:
break;
case DB_PREVIOUS:
- append_error(_("DB_PREVIOUS not supported"));
- report_error();
+ db_d_append_error(_("DB_PREVIOUS not supported"));
+ db_d_report_error();
return DB_FAILED;
break;
case DB_FIRST:
@@ -79,8 +79,8 @@
c->hFeature = OGR_L_GetNextFeature(c->hLayer);
break;
case DB_LAST:
- append_error(_("DB_LAST not supported"));
- report_error();
+ db_d_append_error(_("DB_LAST not supported"));
+ db_d_report_error();
return DB_FAILED;
break;
};
@@ -185,8 +185,8 @@
/* get the cursor by its token */
if (!(c = (cursor *) db_find_token(token))) {
- append_error(_("Cursor not found"));
- report_error();
+ db_d_append_error(_("Cursor not found"));
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/ogr/listtab.c
===================================================================
--- grass/trunk/db/drivers/ogr/listtab.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/ogr/listtab.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -37,7 +37,6 @@
OGRLayerH hLayer;
OGRFeatureDefnH hFeatureDefn;
- init_error();
*tlist = NULL;
*tcount = 0;
@@ -47,8 +46,8 @@
list = db_alloc_string_array(nlayers);
if (list == NULL) {
- append_error(_("Unable to db_alloc_string_array()"));
- report_error();
+ db_d_append_error(_("Unable to db_alloc_string_array()"));
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/ogr/proto.h
===================================================================
--- grass/trunk/db/drivers/ogr/proto.h 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/ogr/proto.h 2012-01-25 14:06:13 UTC (rev 50443)
@@ -25,5 +25,3 @@
/* error.c */
void init_error(void);
-void append_error(const char *, ...);
-void report_error(void);
Modified: grass/trunk/db/drivers/ogr/select.c
===================================================================
--- grass/trunk/db/drivers/ogr/select.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/ogr/select.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -35,8 +35,6 @@
cursor *c;
dbTable *table;
- init_error();
-
/* allocate cursor */
c = alloc_cursor();
if (c == NULL)
@@ -49,16 +47,16 @@
c->hLayer = OGR_DS_ExecuteSQL(hDs, db_get_string(sel), NULL, NULL);
if (c->hLayer == NULL) {
- append_error(_("Unable to select: \n"));
- append_error(db_get_string(sel));
- append_error("\n");
- report_error();
+ db_d_append_error(_("Unable to select: \n"));
+ db_d_append_error(db_get_string(sel));
+ db_d_append_error("\n");
+ db_d_report_error();
return DB_FAILED;
}
if (describe_table(c->hLayer, &table, c) == DB_FAILED) {
- append_error(_("Unable to describe table\n"));
- report_error();
+ db_d_append_error(_("Unable to describe table\n"));
+ db_d_report_error();
OGR_DS_ReleaseResultSet(hDs, c->hLayer);
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/postgres/create_table.c
===================================================================
--- grass/trunk/db/drivers/postgres/create_table.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/postgres/create_table.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -27,8 +27,6 @@
G_debug(3, "db__driver_create_table()");
- init_error();
-
db_init_string(&sql);
/* db_table_to_sql ( table, &sql ); */
@@ -101,11 +99,11 @@
res = PQexec(pg_conn, db_get_string(&sql));
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
- append_error(_("Unable to create table:\n"));
- append_error(db_get_string(&sql));
- append_error("\n");
- append_error(PQerrorMessage(pg_conn));
- report_error();
+ db_d_append_error("%s\n%s\n%s",
+ _("Unable to create table:"),
+ db_get_string(&sql),
+ PQerrorMessage(pg_conn));
+ db_d_report_error();
PQclear(res);
db_free_string(&sql);
return DB_FAILED;
@@ -130,11 +128,11 @@
res = PQexec(pg_conn, db_get_string(&sql));
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
- append_error(_("Unable to grant select on table:\n"));
- append_error(db_get_string(&sql));
- append_error("\n");
- append_error(PQerrorMessage(pg_conn));
- report_error();
+ db_d_append_error("%s\n%s\%s",
+ _("Unable to grant select on table:"),
+ db_get_string(&sql),
+ PQerrorMessage(pg_conn));
+ db_d_report_error();
PQclear(res);
db_free_string(&sql);
return DB_FAILED;
Modified: grass/trunk/db/drivers/postgres/cursor.c
===================================================================
--- grass/trunk/db/drivers/postgres/cursor.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/postgres/cursor.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -19,8 +19,6 @@
{
cursor *c;
- init_error();
-
/* get my cursor via the dbc token */
c = (cursor *) db_find_token(db_get_cursor_token(dbc));
if (c == NULL)
@@ -40,7 +38,7 @@
/* allocate the cursor */
c = (cursor *) db_malloc(sizeof(cursor));
if (c == NULL) {
- append_error(_("Unable allocate cursor."));
+ db_d_append_error(_("Unable allocate cursor."));
return NULL;
}
@@ -49,7 +47,7 @@
/* tokenize it */
c->token = db_new_token(c);
if (c->token < 0) {
- append_error(_("Unable to add new token."));
+ db_d_append_error(_("Unable to add new token."));
return NULL;
}
Modified: grass/trunk/db/drivers/postgres/db.c
===================================================================
--- grass/trunk/db/drivers/postgres/db.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/postgres/db.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -27,7 +27,6 @@
PGresult *res;
int row;
- init_error();
db_get_connection(&connection);
name = db_get_handle_dbname(handle);
@@ -40,7 +39,7 @@
name);
if (parse_conn(name, &pgconn) == DB_FAILED) {
- report_error();
+ db_d_report_error();
return DB_FAILED;
}
@@ -57,9 +56,10 @@
pgconn.dbname, user, password);
if (PQstatus(pg_conn) == CONNECTION_BAD) {
- append_error(_("Unable to connect to Postgres: "));
- append_error(PQerrorMessage(pg_conn));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Connection failed."),
+ PQerrorMessage(pg_conn));
+ db_d_report_error();
PQfinish(pg_conn);
return DB_FAILED;
}
@@ -83,9 +83,10 @@
res = PQexec(pg_conn, buf);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
- append_error(_("Unable to set schema: "));
- append_error(schema);
- report_error();
+ db_d_append_error("%s %s",
+ _("Unable to set schema:"),
+ schema);
+ db_d_report_error();
PQclear(res);
return DB_FAILED;
}
@@ -101,8 +102,8 @@
"'bool', 'geometry' ) order by oid");
if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) {
- append_error(_("Unable to select data types"));
- report_error();
+ db_d_append_error(_("Unable to select data types"));
+ db_d_report_error();
PQclear(res);
return DB_FAILED;
}
@@ -168,7 +169,6 @@
int db__driver_close_database()
{
- init_error();
PQfinish(pg_conn);
return DB_OK;
}
Modified: grass/trunk/db/drivers/postgres/describe.c
===================================================================
--- grass/trunk/db/drivers/postgres/describe.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/postgres/describe.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -28,17 +28,17 @@
res = PQexec(pg_conn, db_get_string(&sql));
if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) {
- append_error(db_get_string(&sql));
- append_error("\n");
- append_error(PQerrorMessage(pg_conn));
- report_error();
+ db_d_append_error("%s\n%s",
+ db_get_string(&sql),
+ PQerrorMessage(pg_conn));
+ db_d_report_error();
PQclear(res);
return DB_FAILED;
}
if (describe_table(res, table, NULL) == DB_FAILED) {
- append_error(_("Unable to describe table\n"));
- report_error();
+ db_d_append_error(_("Unable to describe table."));
+ db_d_report_error();
PQclear(res);
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/postgres/error.c
===================================================================
--- grass/trunk/db/drivers/postgres/error.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/postgres/error.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -12,30 +12,12 @@
#include <stdio.h>
#include <grass/gis.h>
#include <grass/dbmi.h>
-#include <grass/glocale.h>
#include "globals.h"
+
/* init error message */
void init_error(void)
{
- if (!errMsg) {
- errMsg = (dbString *) G_malloc(sizeof(dbString));
- db_init_string(errMsg);
- }
-
- db_set_string(errMsg, _("DBMI-Postgres driver error:\n"));
+ db_d_init_error("PostgreSQL");
}
-
-/* append error message */
-void append_error(const char *msg)
-{
- db_append_string(errMsg, msg);
-}
-
-/* report error message */
-void report_error(void)
-{
- db_append_string(errMsg, "\n");
- db_error(db_get_string(errMsg));
-}
Modified: grass/trunk/db/drivers/postgres/execute.c
===================================================================
--- grass/trunk/db/drivers/postgres/execute.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/postgres/execute.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -23,8 +23,6 @@
PGresult *res;
char *str;
- init_error();
-
/* Postgres supports in addition to standard escape character '
* (apostrophe) also \ (basckslash) as this is not SQL standard,
* GRASS modules cannot work escape all \ in the text because
@@ -40,11 +38,11 @@
res = PQexec(pg_conn, str);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
- append_error(_("Unable to execute:\n"));
- append_error(str);
- append_error("\n");
- append_error(PQerrorMessage(pg_conn));
- report_error();
+ db_d_append_error("%s\n%s\n%s",
+ _("Unable to execute:"),
+ str,
+ PQerrorMessage(pg_conn));
+ db_d_report_error();
PQclear(res);
if (str)
G_free(str);
@@ -64,12 +62,11 @@
G_debug(2, "pg : BEGIN");
- init_error();
res = PQexec(pg_conn, "BEGIN");
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
- append_error(_("Unable to 'BEGIN' transaction"));
- report_error();
+ db_d_append_error(_("Unable to 'BEGIN' transaction"));
+ db_d_report_error();
PQclear(res);
return DB_FAILED;
}
@@ -85,12 +82,11 @@
G_debug(2, "pg : COMMIT");
- init_error();
res = PQexec(pg_conn, "COMMIT");
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
- append_error(_("Unable to 'COMMIT' transaction"));
- report_error();
+ db_d_append_error(_("Unable to 'COMMIT' transaction"));
+ db_d_report_error();
PQclear(res);
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/postgres/fetch.c
===================================================================
--- grass/trunk/db/drivers/postgres/fetch.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/postgres/fetch.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -30,8 +30,8 @@
/* get the cursor by its token */
if (!(c = (cursor *) db_find_token(token))) {
- append_error(_("Cursor not found"));
- report_error();
+ db_d_append_error(_("Cursor not found"));
+ db_d_report_error();
return DB_FAILED;
}
@@ -125,9 +125,10 @@
&(value->t.year), &(value->t.month), &(value->t.day));
if (ns != 3) {
- append_error(_("Unable to scan date:"));
- append_error(PQgetvalue(c->res, c->row, col));
- report_error();
+ db_d_append_error("%s %s",
+ _("Unable to scan date:"),
+ PQgetvalue(c->res, c->row, col));
+ db_d_report_error();
return DB_FAILED;
}
value->t.hour = 0;
@@ -142,9 +143,10 @@
&(value->t.seconds));
if (ns != 3) {
- append_error(_("Unable to scan time:"));
- append_error(PQgetvalue(c->res, c->row, col));
- report_error();
+ db_d_append_error("%s %s",
+ _("Unable to scan time:"),
+ PQgetvalue(c->res, c->row, col));
+ db_d_report_error();
return DB_FAILED;
}
value->t.year = 0;
@@ -160,15 +162,19 @@
&(value->t.minute), &(value->t.seconds), &tz);
if (ns == 7) {
- append_error(_("Unable to scan timestamp (no idea how to process time zone):"));
- append_error(PQgetvalue(c->res, c->row, col));
- report_error();
+ db_d_append_error("%s %s",
+ _("Unable to scan timestamp "
+ "(no idea how to process time zone):"),
+ PQgetvalue(c->res, c->row, col));
+ db_d_report_error();
return DB_FAILED;
}
else if (ns < 6) {
- append_error(_("Unable to scan timestamp (not enough arguments):"));
- append_error(PQgetvalue(c->res, c->row, col));
- report_error();
+ db_d_append_error("%s %s",
+ _("Unable to scan timestamp "
+ "(not enough arguments):"),
+ PQgetvalue(c->res, c->row, col));
+ db_d_report_error();
return DB_FAILED;
}
break;
@@ -197,8 +203,8 @@
/* get the cursor by its token */
if (!(c = (cursor *) db_find_token(token))) {
- append_error(_("Taken not found"));
- report_error();
+ db_d_append_error(_("Taken not found"));
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/postgres/index.c
===================================================================
--- grass/trunk/db/drivers/postgres/index.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/postgres/index.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -26,7 +26,6 @@
G_debug(3, "db__create_index()");
db_init_string(&sql);
- init_error();
ncols = db_get_index_number_of_columns(index);
@@ -56,11 +55,11 @@
res = PQexec(pg_conn, db_get_string(&sql));
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
- append_error(_("Unable to create index:\n"));
- append_error(db_get_string(&sql));
- append_error("\n");
- append_error(PQerrorMessage(pg_conn));
- report_error();
+ db_d_append_error("%s\n%s\%s",
+ _("Unable to create index:\n"),
+ db_get_string(&sql),
+ PQerrorMessage(pg_conn));
+ db_d_report_error();
PQclear(res);
db_free_string(&sql);
return DB_FAILED;
Modified: grass/trunk/db/drivers/postgres/listdb.c
===================================================================
--- grass/trunk/db/drivers/postgres/listdb.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/postgres/listdb.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -22,20 +22,18 @@
int rec_num = 0;
dbHandle *list;
- init_error();
*dblist = NULL;
*dbcount = 0;
/* TODO: the solution below is not good as user usually does not have permissions for "template1" */
- append_error
- (_("db_driver_list_databases() is not implemented in pg driver"));
- report_error();
+ db_d_append_error(_("db_driver_list_databases() is not implemented"));
+ db_d_report_error();
return DB_FAILED;
if (npaths > 0) {
G_debug(3, "location: %s", db_get_string(dbpath));
if (parse_conn(db_get_string(dbpath), &pgconn) == DB_FAILED) {
- report_error();
+ db_d_report_error();
return DB_FAILED;
}
}
@@ -48,9 +46,10 @@
"template1");
if (PQstatus(pg_conn) == CONNECTION_BAD) {
- append_error(_("Unable to connect to Postgres:\n"));
- append_error(PQerrorMessage(pg_conn));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Unable to connect to Postgres:"),
+ PQerrorMessage(pg_conn));
+ db_d_report_error();
PQfinish(pg_conn);
return DB_FAILED;
}
@@ -58,9 +57,10 @@
res = PQexec(pg_conn, "select datname from pg_database");
if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) {
- append_error(_("Unable to select from Postgres:\n"));
- append_error(PQerrorMessage(pg_conn));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Unable to select from Postgres:"),
+ PQerrorMessage(pg_conn));
+ db_d_report_error();
PQclear(res);
PQfinish(pg_conn);
return DB_FAILED;
@@ -70,16 +70,16 @@
list = db_alloc_handle_array(rec_num);
if (list == NULL) {
- append_error(_("Out of memory"));
- report_error();
+ db_d_append_error(_("Out of memory"));
+ db_d_report_error();
return DB_FAILED;
}
for (i = 0; i < rec_num; i++) {
db_init_handle(&list[i]);
if (db_set_handle(&list[i], PQgetvalue(res, i, 0), NULL) != DB_OK) {
- append_error("db_set_handle()");
- report_error();
+ db_d_append_error(_("Unable to set handle"));
+ db_d_report_error();
db_free_handle_array(list, rec_num);
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/postgres/listtab.c
===================================================================
--- grass/trunk/db/drivers/postgres/listtab.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/postgres/listtab.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -23,7 +23,6 @@
PGresult *rest, *resv;
char buf[1000];
- init_error();
*tlist = NULL;
*tcount = 0;
@@ -34,9 +33,10 @@
"select * from pg_tables where tablename !~ 'pg_*' order by tablename");
if (!rest || PQresultStatus(rest) != PGRES_TUPLES_OK) {
- append_error(_("Unable to select table names\n"));
- append_error(PQerrorMessage(pg_conn));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Unable to select table names."),
+ PQerrorMessage(pg_conn));
+ db_d_report_error();
PQclear(rest);
return DB_FAILED;
}
@@ -59,9 +59,10 @@
"SELECT * FROM pg_views WHERE schemaname NOT IN ('pg_catalog','information_schema') AND viewname !~ '^pg_'");
if (!resv || PQresultStatus(resv) != PGRES_TUPLES_OK) {
- append_error(_("Unable to select view names\n"));
- append_error(PQerrorMessage(pg_conn));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Unable to select view names."),
+ PQerrorMessage(pg_conn));
+ db_d_report_error();
PQclear(resv);
return DB_FAILED;
}
@@ -86,8 +87,8 @@
list = db_alloc_string_array(nrows);
if (list == NULL) {
- append_error(_("db_alloc_string_array() failed"));
- report_error();
+ db_d_append_error(_("Out of memory"));
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/postgres/parse.c
===================================================================
--- grass/trunk/db/drivers/postgres/parse.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/postgres/parse.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -64,8 +64,10 @@
else if (strncmp(tokens[i], "schema", 6) == 0)
pgconn->schema = G_store(tokens[i] + 7);
else {
- append_error(_("Unknown option in database definition for PostgreSQL: "));
- append_error(tokens[i]);
+ db_d_append_error("%s %s",
+ _("Unknown option in database definition "
+ "for PostgreSQL: "),
+ tokens[i]);
return DB_FAILED;
}
i++;
Modified: grass/trunk/db/drivers/postgres/priv.c
===================================================================
--- grass/trunk/db/drivers/postgres/priv.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/postgres/priv.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -23,7 +23,6 @@
db_get_connection(&connection);
db_init_string(&sql);
- init_error();
db_set_string(&sql, "grant ");
if (priv | DB_PRIV_SELECT)
@@ -50,11 +49,11 @@
res = PQexec(pg_conn, db_get_string(&sql));
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
- append_error(_("Unable grant on table:\n"));
- append_error(db_get_string(&sql));
- append_error("\n");
- append_error(PQerrorMessage(pg_conn));
- report_error();
+ db_d_append_error("%s\n%s\n%s",
+ _("Unable grant on table:"),
+ db_get_string(&sql),
+ PQerrorMessage(pg_conn));
+ db_d_report_error();
PQclear(res);
db_free_string(&sql);
return DB_FAILED;
Modified: grass/trunk/db/drivers/postgres/proto.h
===================================================================
--- grass/trunk/db/drivers/postgres/proto.h 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/postgres/proto.h 2012-01-25 14:06:13 UTC (rev 50443)
@@ -1,7 +1,5 @@
/* error.c */
void init_error(void);
-void append_error(const char *);
-void report_error(void);
/* cursor.c */
cursor *alloc_cursor(void);
Modified: grass/trunk/db/drivers/postgres/select.c
===================================================================
--- grass/trunk/db/drivers/postgres/select.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/postgres/select.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -24,14 +24,12 @@
dbTable *table;
char *str;
- init_error();
-
/* Set datetime style */
res = PQexec(pg_conn, "SET DATESTYLE TO ISO");
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
- append_error(_("Unable set DATESTYLE"));
- report_error();
+ db_d_append_error(_("Unable set DATESTYLE"));
+ db_d_report_error();
PQclear(res);
return DB_FAILED;
}
@@ -53,11 +51,11 @@
c->res = PQexec(pg_conn, str);
if (!c->res || PQresultStatus(c->res) != PGRES_TUPLES_OK) {
- append_error(_("Unable to select:\n'"));
- append_error(db_get_string(sel));
- append_error("'");
- append_error(PQerrorMessage(pg_conn));
- report_error();
+ db_d_append_error("%s\n%s\n%s",
+ _("Unable to select:"),
+ db_get_string(sel),
+ PQerrorMessage(pg_conn));
+ db_d_report_error();
PQclear(c->res);
if (str)
G_free(str);
@@ -68,8 +66,8 @@
G_free(str);
if (describe_table(c->res, &table, c) == DB_FAILED) {
- append_error(_("Unable to describe table"));
- report_error();
+ db_d_append_error(_("Unable to describe table"));
+ db_d_report_error();
PQclear(res);
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/sqlite/create_table.c
===================================================================
--- grass/trunk/db/drivers/sqlite/create_table.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/sqlite/create_table.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -14,6 +14,7 @@
*/
#include <grass/dbmi.h>
+#include <grass/glocale.h>
#include "globals.h"
#include "proto.h"
@@ -36,9 +37,7 @@
int ret;
G_debug(3, "db__driver_create_table()");
-
- init_error();
-
+
db_init_string(&sql);
/* db_table_to_sql ( table, &sql ); */
@@ -119,11 +118,11 @@
ret = sqlite3_prepare(sqlite, db_get_string(&sql), -1, &statement, &rest);
if (ret != SQLITE_OK) {
- append_error("Cannot create table:\n");
- append_error(db_get_string(&sql));
- append_error("\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s\n%s",
+ _("Unable to create table:"),
+ db_get_string(&sql),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
sqlite3_finalize(statement);
db_free_string(&sql);
return DB_FAILED;
@@ -138,9 +137,10 @@
/* try again */
}
else if (ret != SQLITE_OK) {
- append_error("Error in sqlite3_step():\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Error in sqlite3_step():"),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
sqlite3_finalize(statement);
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/sqlite/cursor.c
===================================================================
--- grass/trunk/db/drivers/sqlite/cursor.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/sqlite/cursor.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -15,6 +15,7 @@
#include <stdio.h>
#include <grass/gis.h>
#include <grass/dbmi.h>
+#include <grass/glocale.h>
#include "globals.h"
#include "proto.h"
@@ -22,8 +23,6 @@
{
cursor *c;
- init_error();
-
/* get my cursor via the dbc token */
c = (cursor *) db_find_token(db_get_cursor_token(dbc));
if (c == NULL)
@@ -45,7 +44,7 @@
/* allocate the cursor */
c = (cursor *) db_malloc(sizeof(cursor));
if (c == NULL) {
- append_error("Cannot allocate cursor.");
+ db_d_append_error(_("Unable to allocate cursor."));
return NULL;
}
@@ -54,7 +53,7 @@
/* tokenize it */
c->token = db_new_token(c);
if (c->token < 0) {
- append_error("Cannot ad new token.");
+ db_d_append_error(_("Unable to add new token."));
return NULL;
}
Modified: grass/trunk/db/drivers/sqlite/db.c
===================================================================
--- grass/trunk/db/drivers/sqlite/db.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/sqlite/db.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -36,7 +36,6 @@
G_debug(3, "\ndb_driver_open_database()");
- init_error();
name = db_get_handle_dbname(handle);
/* if name is empty use connection.databaseName */
@@ -82,9 +81,10 @@
G_debug(2, "name2 = '%s'", name2);
if (sqlite3_open(name2, &sqlite) != SQLITE_OK) {
- append_error(_("Unable to open database: "));
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s %s",
+ _("Unable to open database: "),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
return DB_FAILED;
}
@@ -105,7 +105,6 @@
{
G_debug(3, "db_close_database()");
- init_error();
if (sqlite3_close(sqlite) == SQLITE_BUSY)
G_fatal_error(_("SQLite database connection is still busy"));
Modified: grass/trunk/db/drivers/sqlite/describe.c
===================================================================
--- grass/trunk/db/drivers/sqlite/describe.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/sqlite/describe.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -56,11 +56,11 @@
ret = sqlite3_prepare(sqlite, db_get_string(&sql), -1, &statement, &rest);
if (ret != SQLITE_OK) {
- append_error("Error in sqlite3_prepare():");
- append_error(db_get_string(&sql));
- append_error("\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s %s\n%s",
+ _("Error in sqlite3_prepare():"),
+ db_get_string(&sql),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
db_free_string(&sql);
return DB_FAILED;
}
@@ -74,9 +74,10 @@
/* try again */
}
else if (ret != SQLITE_OK) {
- append_error("Error in sqlite3_step():\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Error in sqlite3_step():"),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
sqlite3_finalize(statement);
return DB_FAILED;
}
@@ -87,9 +88,10 @@
db_free_string(&sql);
if (describe_table(statement, table, NULL) == DB_FAILED) {
- append_error("Cannot describe table:\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Unable to describe table:"),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
sqlite3_finalize(statement);
return DB_FAILED;
}
@@ -126,9 +128,10 @@
if (ret != SQLITE_DONE && ret != SQLITE_ROW) {
/* get real result code */
ret = sqlite3_reset(statement);
- append_error("Error in sqlite3_step():\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Error in sqlite3_step():"),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/sqlite/error.c
===================================================================
--- grass/trunk/db/drivers/sqlite/error.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/sqlite/error.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -18,28 +18,8 @@
#include "proto.h"
#include "globals.h"
-static dbString *errMsg = NULL; /* error message */
-
/* init error message */
void init_error(void)
{
- if (!errMsg) {
- errMsg = (dbString *) G_malloc(sizeof(dbString));
- db_init_string(errMsg);
- }
-
- db_set_string(errMsg, "DBMI-SQLite driver error:\n");
+ db_d_init_error("SQLite");
}
-
-/* append error message */
-void append_error(const char *msg)
-{
- db_append_string(errMsg, msg);
-}
-
-
-void report_error(void)
-{
- db_append_string(errMsg, "\n");
- db_error(db_get_string(errMsg));
-}
Modified: grass/trunk/db/drivers/sqlite/execute.c
===================================================================
--- grass/trunk/db/drivers/sqlite/execute.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/sqlite/execute.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -17,6 +17,7 @@
#include <stdlib.h>
#include <grass/gis.h>
#include <grass/dbmi.h>
+#include <grass/glocale.h>
#include "globals.h"
#include "proto.h"
@@ -48,9 +49,10 @@
ret = sqlite3_prepare(sqlite, s, -1, &stmt, &rest);
if (ret != SQLITE_OK) {
- append_error("Error in sqlite3_prepare():\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Error in sqlite3_prepare():"),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
return DB_FAILED;
}
@@ -63,9 +65,10 @@
/* try again */
}
else if (ret != SQLITE_OK) {
- append_error("Error in sqlite3_step():\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Error in sqlite3_step():"),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
sqlite3_finalize(stmt);
return DB_FAILED;
}
@@ -76,9 +79,10 @@
ret = sqlite3_finalize(stmt);
if (ret != SQLITE_OK) {
- append_error("Error in sqlite3_finalize():\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Error in sqlite3_finalize():"),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
return DB_FAILED;
}
@@ -103,9 +107,10 @@
ret = sqlite3_exec(sqlite, "BEGIN", NULL, NULL, NULL);
if (ret != SQLITE_OK) {
- append_error("Cannot 'BEGIN' transaction:\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("'BEGIN' transaction failed:"),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
return DB_FAILED;
}
@@ -130,9 +135,10 @@
ret = sqlite3_exec(sqlite, "COMMIT", NULL, NULL, NULL);
if (ret != SQLITE_OK) {
- append_error("Cannot 'COMMIT' transaction:\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("'COMMIT' transaction failed:"),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/sqlite/fetch.c
===================================================================
--- grass/trunk/db/drivers/sqlite/fetch.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/sqlite/fetch.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -48,8 +48,8 @@
/* get the cursor by its token */
if (!(c = (cursor *) db_find_token(token))) {
- append_error("Cursor not found");
- report_error();
+ db_d_append_error(("Cursor not found"));
+ db_d_report_error();
return DB_FAILED;
}
@@ -68,9 +68,10 @@
/* get real result code */
ret = sqlite3_reset(c->statement);
if (ret != SQLITE_OK) {
- append_error("Cannot fetch:\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Unable to fetch:"),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
return DB_FAILED;
}
*more = 0;
@@ -83,14 +84,14 @@
break;
case DB_PREVIOUS:
- append_error("DB_PREVIOUS is not supported");
- report_error();
+ db_d_append_error(_("DB_PREVIOUS is not supported"));
+ db_d_report_error();
return DB_FAILED;
break;
case DB_LAST:
- append_error("DB_LAST is not supported");
- report_error();
+ db_d_append_error(_("DB_LAST is not supported"));
+ db_d_report_error();
return DB_FAILED;
break;
};
@@ -166,9 +167,10 @@
G_debug(3, "sqlite fetched date: %s", text);
ns = sscanf(text, "%4d-%2d-%2d", &dt->year, &dt->month, &dt->day);
if (ns != 3) {
- append_error("Cannot scan date:");
- append_error(text);
- report_error();
+ db_d_append_error("%s %s",
+ _("Unable to scan date:"),
+ text);
+ db_d_report_error();
return DB_FAILED;
}
break;
@@ -182,9 +184,10 @@
ns = sscanf(text, "%2d:%2d:%lf",
&dt->hour, &dt->minute, &dt->seconds);
if (ns != 3) {
- append_error("Cannot scan time:");
- append_error(text);
- report_error();
+ db_d_append_error("%s %s",
+ _("Unable to scan time:"),
+ text);
+ db_d_report_error();
return DB_FAILED;
}
break;
@@ -196,9 +199,10 @@
&dt->year, &dt->month, &dt->day,
&dt->hour, &dt->minute, &dt->seconds);
if (ns != 6) {
- append_error("Cannot scan timestamp:");
- append_error(text);
- report_error();
+ db_d_append_error("%s %s",
+ _("Unable to scan timestamp:"),
+ text);
+ db_d_report_error();
return DB_FAILED;
}
break;
@@ -211,13 +215,14 @@
dt->hour = 0;
dt->minute = 0;
G_debug(3, "sqlite fetched interval: %s", text);
- G_warning
- ("SQLite driver: parsing of interval values not implemented; assuming seconds");
+ G_warning(_("SQLite driver: parsing of interval values "
+ "not implemented; assuming seconds"));
ns = sscanf(text, "%lf", &dt->seconds);
if (ns != 1) {
- append_error("Cannot scan interval:");
- append_error(text);
- report_error();
+ db_d_append_error("%s %s",
+ _("Unable to scan interval:"),
+ text);
+ db_d_report_error();
return DB_FAILED;
}
break;
@@ -257,8 +262,8 @@
/* get the cursor by its token */
if (!(c = (cursor *) db_find_token(token))) {
- append_error("Cursor not found");
- report_error();
+ db_d_append_error(_("Cursor not found"));
+ db_d_report_error();
return DB_FAILED;
}
@@ -277,9 +282,10 @@
ret = sqlite3_reset(c->statement);
if (ret != SQLITE_OK) {
- append_error("Cannot get number of rows\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Unable to get number of rows:"),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/sqlite/index.c
===================================================================
--- grass/trunk/db/drivers/sqlite/index.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/sqlite/index.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -14,6 +14,7 @@
*/
#include <grass/dbmi.h>
+#include <grass/glocale.h>
#include "globals.h"
#include "proto.h"
@@ -38,7 +39,6 @@
G_debug(3, "db__create_index()");
db_init_string(&sql);
- init_error();
ncols = db_get_index_number_of_columns(index);
@@ -72,11 +72,11 @@
ret = sqlite3_prepare(sqlite, db_get_string(&sql), -1, &statement, &rest);
if (ret != SQLITE_OK) {
- append_error("Cannot create index:\n");
- append_error(db_get_string(&sql));
- append_error("\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s\n%s",
+ _("Unable to create index:"),
+ db_get_string(&sql),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
sqlite3_finalize(statement);
db_free_string(&sql);
return DB_FAILED;
@@ -91,9 +91,10 @@
/* try again */
}
else if (ret != SQLITE_OK) {
- append_error("Error in sqlite3_step():\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Error in sqlite3_step():"),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
sqlite3_finalize(statement);
db_free_string(&sql);
return DB_FAILED;
Modified: grass/trunk/db/drivers/sqlite/listtab.c
===================================================================
--- grass/trunk/db/drivers/sqlite/listtab.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/sqlite/listtab.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -16,6 +16,7 @@
#include <stdlib.h>
#include <string.h>
#include <grass/dbmi.h>
+#include <grass/glocale.h>
#include "globals.h"
#include "proto.h"
@@ -39,16 +40,16 @@
const char *rest;
int ret;
- init_error();
-
+ G_debug(3, "db__driver_list_tables(): system = %d", system);
ret = sqlite3_prepare(sqlite,
"select name from sqlite_master where type = 'table' or type = 'view'",
-1, &statement, &rest);
if (ret != SQLITE_OK) {
- append_error("Cannot list tables\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Unable to list tables:"),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
sqlite3_finalize(statement);
return DB_FAILED;
}
@@ -61,9 +62,10 @@
ret = sqlite3_reset(statement);
if (ret != SQLITE_OK) {
- append_error("Cannot list tables\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Unable to list tables:"),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
sqlite3_finalize(statement);
return DB_FAILED;
}
@@ -73,8 +75,8 @@
list = db_alloc_string_array(nrows);
if (list == NULL) {
- append_error("Cannot db_alloc_string_array()");
- report_error();
+ db_d_append_error(_("Unable to db_alloc_string_array()"));
+ db_d_report_error();
sqlite3_finalize(statement);
return DB_FAILED;
}
Modified: grass/trunk/db/drivers/sqlite/proto.h
===================================================================
--- grass/trunk/db/drivers/sqlite/proto.h 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/sqlite/proto.h 2012-01-25 14:06:13 UTC (rev 50443)
@@ -5,8 +5,6 @@
/* error.c */
void init_error(void);
-void append_error(const char *);
-void report_error(void);
/* cursor.c */
cursor *alloc_cursor();
Modified: grass/trunk/db/drivers/sqlite/select.c
===================================================================
--- grass/trunk/db/drivers/sqlite/select.c 2012-01-25 14:04:51 UTC (rev 50442)
+++ grass/trunk/db/drivers/sqlite/select.c 2012-01-25 14:06:13 UTC (rev 50443)
@@ -16,6 +16,7 @@
#include <stdlib.h>
#include <grass/dbmi.h>
#include <grass/gis.h>
+#include <grass/glocale.h>
#include "globals.h"
#include "proto.h"
@@ -39,8 +40,6 @@
const char *rest;
int ret;
- init_error();
-
/* allocate cursor */
c = alloc_cursor();
if (c == NULL)
@@ -60,11 +59,11 @@
ret = sqlite3_prepare(sqlite, str, -1, &(c->statement), &rest);
if (ret != SQLITE_OK) {
- append_error("Error in sqlite3_prepare():");
- append_error(db_get_string(sel));
- append_error("\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s\n%s",
+ _("Error in sqlite3_prepare():"),
+ db_get_string(sel),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
return DB_FAILED;
}
@@ -77,9 +76,10 @@
/* try again */
}
else if (ret != SQLITE_OK) {
- append_error("Error in sqlite3_step():\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Error in sqlite3_step():"),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
sqlite3_finalize(c->statement);
return DB_FAILED;
}
@@ -91,9 +91,10 @@
G_free(str);
if (describe_table(c->statement, &table, c) == DB_FAILED) {
- append_error("Cannot describe table\n");
- append_error((char *)sqlite3_errmsg(sqlite));
- report_error();
+ db_d_append_error("%s\n%s",
+ _("Unable to describe table:"),
+ (char *)sqlite3_errmsg(sqlite));
+ db_d_report_error();
return DB_FAILED;
}
More information about the grass-commit
mailing list