Hi,
I'm working on legacy databases where boolean are defined as smallint.
The following adapter doesn't work anymore. Could you give me some hint on
how can I write a new one for the "new" pydal.
Thank you
The adapter that was working till now:
# -*- coding: utf-8 -*-
from pydal.adapters import ADAPTERS, PostgreSQLAdapter
class BoolAsIntPostgreSQLAdapter(PostgreSQLAdapter):
# specify a diver to use
drivers = ('psycopg2','pg8000')
TRUE = -1
FALSE = 0
types = {
'boolean': 'smallint',
'string': 'VARCHAR(%(length)s)',
'text': 'TEXT',
'json': 'TEXT',
'password': 'VARCHAR(%(length)s)',
'blob': 'BYTEA',
'upload': 'VARCHAR(%(length)s)',
'integer': 'INTEGER',
'bigint': 'BIGINT',
'float': 'FLOAT',
'double': 'FLOAT8',
'decimal': 'NUMERIC(%(precision)s,%(scale)s)',
'date': 'DATE',
'time': 'TIME',
'datetime': 'TIMESTAMP',
'id': 'SERIAL PRIMARY KEY',
'reference': 'INTEGER REFERENCES %(foreign_key)s ON DELETE
%(on_delete_action)s',
'list:integer': 'TEXT',
'list:string': 'TEXT',
'list:reference': 'TEXT',
'geometry': 'GEOMETRY',
'geography': 'GEOGRAPHY',
'big-id': 'BIGSERIAL PRIMARY KEY',
'big-reference': 'BIGINT REFERENCES %(foreign_key)s ON DELETE
%(on_delete_action)s',
'reference FK': ', CONSTRAINT "FK_%(constraint_name)s" FOREIGN KEY
(%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s',
'reference TFK': ' CONSTRAINT "FK_%(foreign_table)s_PK" FOREIGN
KEY (%(field_name)s) REFERENCES %(foreign_table)s (%(foreign_key)s) ON
DELETE %(on_delete_action)s',
}
def parse_boolean(self, value, field_type):
return value == self.TRUE or False
ADAPTERS.update( {
'pgsql': BoolAsIntPostgreSQLAdapter
})
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.