Holger Brunn
9 years ago
No known key found for this signature in database
GPG Key ID: 1C9760FECA3AE18
4 changed files with 41 additions and 9 deletions
-
23database_cleanup/identifier_adapter.py
-
9database_cleanup/models/purge_columns.py
-
5database_cleanup/models/purge_data.py
-
13database_cleanup/models/purge_tables.py
@ -0,0 +1,23 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2016 Therp BV <http://therp.nl> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
from psycopg2.extensions import ISQLQuote |
||||
|
|
||||
|
|
||||
|
class IdentifierAdapter(ISQLQuote): |
||||
|
def __init__(self, identifier, quote=True): |
||||
|
self.quote = quote |
||||
|
self.identifier = identifier |
||||
|
|
||||
|
def __conform__(self, protocol): |
||||
|
if protocol == ISQLQuote: |
||||
|
return self |
||||
|
|
||||
|
def getquoted(self): |
||||
|
def is_identifier_char(c): |
||||
|
return c.isalnum() or c in ['_', '$'] |
||||
|
|
||||
|
format_string = '"%s"' |
||||
|
if not self.quote: |
||||
|
format_string = '%s' |
||||
|
return format_string % filter(is_identifier_char, self.identifier) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue