| 19 | | if self.connection is None: |
|---|
| 20 | | if settings.DATABASE_NAME == '': |
|---|
| 21 | | from django.core.exceptions import ImproperlyConfigured |
|---|
| 22 | | raise ImproperlyConfigured, "You need to specify DATABASE_NAME in your Django settings file." |
|---|
| 23 | | conn_string = "dbname=%s" % settings.DATABASE_NAME |
|---|
| 24 | | if settings.DATABASE_USER: |
|---|
| 25 | | conn_string = "user=%s %s" % (settings.DATABASE_USER, conn_string) |
|---|
| 26 | | if settings.DATABASE_PASSWORD: |
|---|
| 27 | | conn_string += " password='%s'" % settings.DATABASE_PASSWORD |
|---|
| 28 | | if settings.DATABASE_HOST: |
|---|
| 29 | | conn_string += " host=%s" % settings.DATABASE_HOST |
|---|
| 30 | | if settings.DATABASE_PORT: |
|---|
| 31 | | conn_string += " port=%s" % settings.DATABASE_PORT |
|---|
| 32 | | self.connection = Database.connect(conn_string) |
|---|
| 33 | | self.connection.set_isolation_level(1) # make transactions transparent to all cursors |
|---|
| | 23 | self._lock.writer_enters() |
|---|
| | 24 | try: |
|---|
| | 25 | if self.connection is None: |
|---|
| | 26 | if settings.DATABASE_NAME == '': |
|---|
| | 27 | from django.core.exceptions import ImproperlyConfigured |
|---|
| | 28 | raise ImproperlyConfigured, "You need to specify DATABASE_NAME in your Django settings file." |
|---|
| | 29 | conn_string = "dbname=%s" % settings.DATABASE_NAME |
|---|
| | 30 | if settings.DATABASE_USER: |
|---|
| | 31 | conn_string = "user=%s %s" % (settings.DATABASE_USER, conn_string) |
|---|
| | 32 | if settings.DATABASE_PASSWORD: |
|---|
| | 33 | conn_string += " password='%s'" % settings.DATABASE_PASSWORD |
|---|
| | 34 | if settings.DATABASE_HOST: |
|---|
| | 35 | conn_string += " host=%s" % settings.DATABASE_HOST |
|---|
| | 36 | if settings.DATABASE_PORT: |
|---|
| | 37 | conn_string += " port=%s" % settings.DATABASE_PORT |
|---|
| | 38 | self.connection = Database.connect(conn_string) |
|---|
| | 39 | self.connection.set_isolation_level(1) # make transactions transparent to all cursors |
|---|
| | 40 | if not currentThread() in self._active_threads: |
|---|
| | 41 | self._active_threads.append(currentThread()) |
|---|
| | 42 | finally: |
|---|
| | 43 | self._lock.writer_leaves() |
|---|