Ticket #952: encoding.2.diff

File encoding.2.diff, 3.1 KB (added by me@…, 10 years ago)

necessary changes

  • django/conf/project_template/settings.py

     
    1515DATABASE_PASSWORD = ''         # Not used with sqlite3.
    1616DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
    1717DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
     18DATABASE_ENCODING = ''         # Set to encoding name used by your database
     19                               # (i.e. 'utf8' for MySQL or 'unicode' for Postgres). Not used with sqlite3.
    1820
    1921# Local time zone for this installation. All choices can be found here:
    2022# http://www.postgresql.org/docs/current/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
  • django/core/db/backends/postgresql.py

     
    1515        self.queries = []
    1616
    1717    def cursor(self):
    18         from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_PORT, DATABASE_PASSWORD, DEBUG, TIME_ZONE
     18        from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_PORT, DATABASE_PASSWORD, DATABASE_ENCODING, DEBUG, TIME_ZONE
    1919        if self.connection is None:
    2020            if DATABASE_NAME == '':
    2121                from django.core.exceptions import ImproperlyConfigured
     
    3131                conn_string += " port=%s" % DATABASE_PORT
    3232            self.connection = Database.connect(conn_string)
    3333            self.connection.set_isolation_level(1) # make transactions transparent to all cursors
     34           
     35            if DATABASE_ENCODING:
     36              self.connection.cursor().execute("SET CLIENT_ENCODING TO "+DATABASE_ENCODING)
     37
    3438        cursor = self.connection.cursor()
    3539        cursor.execute("SET TIME ZONE %s", [TIME_ZONE])
    3640        if DEBUG:
  • django/core/db/backends/mysql.py

     
    5353        self.queries = []
    5454
    5555    def cursor(self):
    56         from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_PORT, DATABASE_PASSWORD, DEBUG
     56        from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_PORT, DATABASE_PASSWORD, DATABASE_ENCODING, DEBUG
    5757        if self.connection is None:
    5858            kwargs = {
    5959                'user': DATABASE_USER,
     
    6565            if DATABASE_PORT:
    6666                kwargs['port'] = DATABASE_PORT
    6767            self.connection = Database.connect(**kwargs)
     68
     69        if DATABASE_ENCODING:
     70          self.connection.cursor().execute("SET NAMES "+DATABASE_ENCODING)
     71 
    6872        if DEBUG:
    6973            return base.CursorDebugWrapper(MysqlDebugWrapper(self.connection.cursor()), self)
    7074        return self.connection.cursor()
Back to Top