Thank you for example,
sure it works for most cases, but what could be done with id of rows?
They are not defined explicity, and changes in sql.by were enought for
defining table i need.
Let me explain my idea.
Let see sql.py from 1.76.1 release at position of
SQL_DIALECTS = {
.....skipped...
'postgres': {
'boolean': 'CHAR(1)',
'string': 'VARCHAR(%(length)s)',
'text': 'TEXT',
'password': 'VARCHAR(%(length)s)',
'blob': 'BYTEA',
'upload': 'VARCHAR(%(length)s)',
'integer': 'INTEGER',
'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',
'lower': 'LOWER(%(field)s)',
'upper': 'UPPER(%(field)s)',
'is null': 'IS NULL',
'is not null': 'IS NOT NULL',
'extract': 'EXTRACT(%(name)s FROM %(field)s)',
'left join': 'LEFT JOIN',
'random': 'RANDOM()',
'notnull': 'NOT NULL DEFAULT %(default)s',
'substring': 'SUBSTR(%(field)s,%(pos)s,%(length)s)',
},
--------------
How ugly will be aproach where are at db.py top the code
SQL_DIALECTS = {
'postgres': {
'boolean': 'CHAR(1)',
'string': 'VARCHAR(%(length)s)',
'text': 'TEXT',
'password': 'VARCHAR(%(length)s)',
'blob': 'BYTEA',
'upload': 'VARCHAR(%(length)s)',
'integer': 'BIGINT',
'double': 'FLOAT8',
'decimal': 'NUMERIC(%(precision)s,%(scale)s)',
'date': 'DATE',
'time': 'TIME',
'datetime': 'TIMESTAMP WITH TIME ZONE',
'id': 'BIGSERIAL PRIMARY KEY',
'reference': 'BIGINT REFERENCES %(foreign_key)s ON DELETE %
(on_delete_action)s',
'lower': 'LOWER(%(field)s)',
'upper': 'UPPER(%(field)s)',
'is null': 'IS NULL',
'is not null': 'IS NOT NULL',
'extract': 'EXTRACT(%(name)s FROM %(field)s)',
'left join': 'LEFT JOIN',
'random': 'RANDOM()',
'notnull': 'NOT NULL DEFAULT %(default)s',
'substring': 'SUBSTR(%(field)s,%(pos)s,%(length)s)',
},
}
-----------------------end of code----------------
This does not work, web2py use code from sql.py anyway...
QUESTION:
So, is it possible to redefine SQL_DIALECTS before tables defined and
in db.py ?
I guess here required knowledge of internal process - how it works.
I am sorry if question like sphere-horse model in vacuum.
On 2 мар, 18:27, mdipierro <[email protected]> wrote:
> You can do for example:
>
> mydt =
> SQLCustomType(
> type
> =datetime',
> native ='TIMESTAMP WITH TIME
> ZONE',
> encoder = ... ,
> decoder = ... )
> )
>
> db.define_table(
>
> 'example',
> Field('value',
> type=mydt)
> )
>
> type =datetime' is the web2py
> representation
> native ='TIMESTAMP WITH TIME ZONE' is the SQL
> representation
> encoder is a function that that gives you the SQL representation (must
> escape ' into '' for strings)
> decoder does the oppotsite.
>
> On Mar 2, 1:07 am, KMax <[email protected]> wrote:
>
> > Hello
> > I create db schema at postgres db and then start to move it to db.py
> > definition.
> > But get the issue with data types. For example: I use bigserial while
> > web2py use simple serial type.
> > I use TIMESTAMP WITH TIME ZONE (to support winter and summer time)
> > while web2py use TIMESTAMP (and postgres treat it as TIMESTAMP WITHOUT
> > TIME ZONE).
> > I solve this issue by editing sql.py and dal.py and all gets fine,
> > but it make me force to apply this changes every web2py release.
> > THE QUESTION:
> > Could I redefine something in my db.py for avoid edition sql.py ?
> > Please provide short example of it (I guess there difference in
> > sql.py and dal.py)
>
> > Thank you.
> > Maxim
--
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en.