From: Eric Bollengier Date: Sun, 15 Feb 2009 16:59:06 +0000 (+0000) Subject: ebl Check postgresql database encoding that should be SQL_ASCII X-Git-Tag: Release-3.0.0~233 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=eced9e7036fc4c41a3618698c80003a6fd6b7339;p=bacula%2Fbacula ebl Check postgresql database encoding that should be SQL_ASCII and print a warning if it's something else. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8454 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/cats/postgresql.c b/bacula/src/cats/postgresql.c index 295d8190b3..828cfb84a6 100644 --- a/bacula/src/cats/postgresql.c +++ b/bacula/src/cats/postgresql.c @@ -132,6 +132,32 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char return mdb; } +/* Check that the database correspond to the encoding we want */ +static bool check_database_encoding(JCR *jcr, B_DB *mdb) +{ + SQL_ROW row; + int ret=false; + + if (!db_sql_query(mdb, "SELECT getdatabaseencoding()", NULL, NULL)) { + Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg); + return false; + } + + if ((row = sql_fetch_row(mdb)) == NULL) { + Mmsg1(mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb)); + Jmsg(jcr, M_ERROR, 0, "Can't check database encoding %s", mdb->errmsg); + } else { + ret = bstrcmp(row[0], "SQL_ASCII"); + if (!ret) { + Mmsg(mdb->errmsg, + _("Encoding error for database \"%s\". Wanted SQL_ASCII, got %s\n"), + mdb->db_name, row[0]); + Jmsg(jcr, M_WARNING, 0, "%s", mdb->errmsg); + } + } + return ret; +} + /* * Now actually open the database. This can generate errors, * which are returned in the errmsg @@ -147,7 +173,7 @@ db_open_database(JCR *jcr, B_DB *mdb) #ifdef xxx if (!PQisthreadsafe()) { Jmsg(jcr, M_ABORT, 0, _("PostgreSQL configuration problem. " - "PostgreSQL library is not thread safe. Connot continue.\n")); + "PostgreSQL library is not thread safe. Cannot continue.\n")); } #endif P(mutex); @@ -219,6 +245,9 @@ db_open_database(JCR *jcr, B_DB *mdb) */ sql_query(mdb, "set standard_conforming_strings=on"); + /* check that encoding is SQL_ASCII */ + check_database_encoding(jcr, mdb); + V(mutex); return 1; } diff --git a/bacula/technotes-2.5 b/bacula/technotes-2.5 index 05252544fc..36115c5090 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -25,6 +25,9 @@ filepattern (restore with regex in bsr) mixed priorities General: +15Feb09 +ebl Check postgresql database encoding that should be SQL_ASCII + and print a warning if it's something else. 08Feb09 kes Free name item in guid_to_name.c when already in list. kes Add more info to error message in ua_tree.c