Files
tryton/trytond/model/fields/integer.py
T

44 lines
1.2 KiB
Python
Raw Normal View History

2009-02-03 18:58:25 +01:00
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
2013-09-06 22:32:37 +02:00
from sql import Query, Expression
2009-02-03 18:58:25 +01:00
2013-09-06 22:32:37 +02:00
from ...config import CONFIG
from .field import Field, SQLType
2009-02-03 18:58:25 +01:00
class Integer(Field):
2009-03-01 13:37:31 +01:00
'''
2009-09-13 15:37:11 +02:00
Define an integer field (``int``).
2009-03-01 13:37:31 +01:00
'''
2009-02-03 18:58:25 +01:00
_type = 'integer'
2013-09-06 22:32:37 +02:00
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)
2009-02-03 18:58:25 +01:00
class BigInteger(Integer):
2009-03-01 13:37:31 +01:00
'''
2009-09-13 15:37:11 +02:00
Define an integer field (``long``).
2009-03-01 13:37:31 +01:00
'''
2009-02-03 18:58:25 +01:00
_type = 'biginteger'
2013-09-06 22:32:37 +02:00
def sql_type(self):
db_type = CONFIG['db_type']
if db_type == 'postgresql':
return SQLType('INT8', 'INT8')
return super(BigInteger, self).sql_type()