From 356643d50914eaf694a4326d85bf9973f9276a96 Mon Sep 17 00:00:00 2001 From: Massimo Date: Thu, 24 Jan 2013 10:51:44 -0600 Subject: [PATCH] check whether pgsql supports json fields, thanks Alan --- VERSION | 2 +- gluon/dal.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index fb34ff20..312f3df5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.4.1-alpha.2+timestamp.2013.01.23.08.48.16 +Version 2.4.1-alpha.2+timestamp.2013.01.24.10.51.01 diff --git a/gluon/dal.py b/gluon/dal.py index 4d4daa48..69c0af9e 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -2569,11 +2569,25 @@ class PostgreSQLAdapter(BaseAdapter): def after_connection(self): self.connection.set_client_encoding('UTF8') self.execute("SET standard_conforming_strings=on;") + self.try_json() def lastrowid(self,table): self.execute("select currval('%s')" % table._sequence_name) return int(self.cursor.fetchone()[0]) + def try_json(self): + # check JSON data type support + # (to be added to after_connection) + if self.driver_name == "pg8000": + supports_json = self.connection.server_version >= "9.2.0" + elif (self.driver_name == "psycopg2") and \ + (self.driver.__version__ >= "2.0.12"): + supports_json = self.connection.server_version >= 90200 + elif self.driver_name == "zxJDBC": + supports_json = self.connection.dbversion >= "9.2.0" + else: supports_json = None + if supports_json: self.types["json"] = "JSON" + else: LOGGER.debug("Your database version does not support the JSON data type (using TEXT instead)") def LIKE(self,first,second): args = (self.expand(first), self.expand(second,'string')) @@ -2797,6 +2811,7 @@ class JDBCPostgreSQLAdapter(PostgreSQLAdapter): self.connection.set_client_encoding('UTF8') self.execute('BEGIN;') self.execute("SET CLIENT_ENCODING TO 'UNICODE';") + self.try_json() class OracleAdapter(BaseAdapter):