[patch] Charset interaction between Gnucash and PostgreSQL

Andreas Bogk andreas@andreas.org
08 Apr 2002 21:04:41 +0000


--=-=-=

Hi!

It seems that handling of different character sets is still a little
flaky here and there.  The patch below is a workaround, so a
newly-created database will use the character encoding matching the
current locale, in case the PostgreSQL default charset does not equal
the charset of the current locale as it was the case for me.

The patch does not solve the problem of users with different encodings
accessing a common database.  For that, one would have to convert
between charsets on the database interface using iconv or something
alike.  This can probably be done quite easily by hacking the m4 file,
but nor for me at the moment due to lack of m4 skills.

Andreas


--=-=-=
Content-Disposition: attachment; filename=postgresql-encoding.diff

Index: src/backend/postgres/PostgresBackend.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/backend/postgres/PostgresBackend.c,v
retrieving revision 1.27
diff -u -r1.27 PostgresBackend.c
--- src/backend/postgres/PostgresBackend.c	8 Jan 2002 09:29:52 -0000	1.27
+++ src/backend/postgres/PostgresBackend.c	8 Apr 2002 20:45:33 -0000
@@ -33,6 +33,7 @@
 #include <string.h>  
 #include <sys/types.h>  
 #include <unistd.h>  
+#include <langinfo.h>
 
 #include <libpq-fe.h>  
 
@@ -1929,7 +1930,9 @@
          p = be->buff; *p =0;
          p = stpcpy (p, "CREATE DATABASE ");
          p = stpcpy (p, be->dbName);
-         p = stpcpy (p, ";");
+         p = stpcpy (p, " WITH ENCODING = '");
+	 p = stpcpy (p, nl_langinfo(CODESET));
+         p = stpcpy (p, "';");
          SEND_QUERY (be,be->buff, );
          FINISH_QUERY(be->connection);
          PQfinish (be->connection);

--=-=-=



-- 
"In my eyes it is never a crime to steal knowledge. It is a good
theft. The pirate of knowledge is a good pirate."
                                                       (Michel Serres)

--=-=-=--