Files
tryton/trytond/model/fields/integer.py
T
Cédric Krier fc6c6cfdda Migration to python-sql
* Use python-sql
* Add convert_domain method on Fields
* Add sql_format and sql_type methods on Fields
* Allow to return a full domain for Function.searcher
* Replace static backend by dynamic get method
* Replace order_field by order_<field name> method

review1001002
2013-09-06 22:32:37 +02:00

44 lines
1.2 KiB
Python

#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
from sql import Query, Expression
from ...config import CONFIG
from .field import Field, SQLType
class Integer(Field):
'''
Define an integer field (``int``).
'''
_type = 'integer'
def sql_type(self):
db_type = CONFIG['db_type']
if db_type == 'postgresql':
return SQLType('INT4', 'INT4')
elif db_type == 'mysql':
return SQLType('SIGNED INTEGER', 'BIGINT')
else:
return SQLType('INTEGER', 'INTEGER')
def sql_format(self, value):
db_type = CONFIG['db_type']
if (db_type == 'sqlite'
and value is not None
and not isinstance(value, (Query, Expression))):
value = int(value)
return super(Integer, self).sql_format(value)
class BigInteger(Integer):
'''
Define an integer field (``long``).
'''
_type = 'biginteger'
def sql_type(self):
db_type = CONFIG['db_type']
if db_type == 'postgresql':
return SQLType('INT8', 'INT8')
return super(BigInteger, self).sql_type()