comparison roundup/backends/rdbms_common.py @ 5067:e424987d294a

Add support for an integer type to join the existing number type. Commit patch supplied for issue2550886. This can be used for properties used for ordering, counts etc. where a decimal point isn't needed. Developed by Anthony (antmail). Doc updates written by John Rouillard.
author John Rouillard <rouilj@ieee.org>
date Sun, 05 Jun 2016 00:17:26 -0400
parents 5251e97b1de0
children 2b551b6b0830
comparison
equal deleted inserted replaced
5066:d2256fcfd81f 5067:e424987d294a
55 import sys, os, time, re, errno, weakref, copy, logging, datetime 55 import sys, os, time, re, errno, weakref, copy, logging, datetime
56 56
57 # roundup modules 57 # roundup modules
58 from roundup import hyperdb, date, password, roundupdb, security, support 58 from roundup import hyperdb, date, password, roundupdb, security, support
59 from roundup.hyperdb import String, Password, Date, Interval, Link, \ 59 from roundup.hyperdb import String, Password, Date, Interval, Link, \
60 Multilink, DatabaseError, Boolean, Number, Node 60 Multilink, DatabaseError, Boolean, Number, Integer, Node
61 from roundup.backends import locking 61 from roundup.backends import locking
62 from roundup.i18n import _ 62 from roundup.i18n import _
63 63
64 64
65 # support 65 # support
462 hyperdb.Link : 'INTEGER', 462 hyperdb.Link : 'INTEGER',
463 hyperdb.Interval : 'VARCHAR(255)', 463 hyperdb.Interval : 'VARCHAR(255)',
464 hyperdb.Password : 'VARCHAR(255)', 464 hyperdb.Password : 'VARCHAR(255)',
465 hyperdb.Boolean : 'BOOLEAN', 465 hyperdb.Boolean : 'BOOLEAN',
466 hyperdb.Number : 'REAL', 466 hyperdb.Number : 'REAL',
467 hyperdb.Integer : 'INTEGER',
467 } 468 }
468 469
469 def hyperdb_to_sql_datatype(self, propclass): 470 def hyperdb_to_sql_datatype(self, propclass):
470 471
471 datatype = self.hyperdb_to_sql_datatypes.get(propclass) 472 datatype = self.hyperdb_to_sql_datatypes.get(propclass)
869 hyperdb.Link : int, 870 hyperdb.Link : int,
870 hyperdb.Interval : str, 871 hyperdb.Interval : str,
871 hyperdb.Password : str, 872 hyperdb.Password : str,
872 hyperdb.Boolean : lambda x: x and 'TRUE' or 'FALSE', 873 hyperdb.Boolean : lambda x: x and 'TRUE' or 'FALSE',
873 hyperdb.Number : lambda x: x, 874 hyperdb.Number : lambda x: x,
875 hyperdb.Integer : lambda x: x,
874 hyperdb.Multilink : lambda x: x, # used in journal marshalling 876 hyperdb.Multilink : lambda x: x, # used in journal marshalling
875 } 877 }
876 878
877 def to_sql_value(self, propklass): 879 def to_sql_value(self, propklass):
878 880
1082 hyperdb.Link : str, 1084 hyperdb.Link : str,
1083 hyperdb.Interval : date.Interval, 1085 hyperdb.Interval : date.Interval,
1084 hyperdb.Password : lambda x: password.Password(encrypted=x), 1086 hyperdb.Password : lambda x: password.Password(encrypted=x),
1085 hyperdb.Boolean : _bool_cvt, 1087 hyperdb.Boolean : _bool_cvt,
1086 hyperdb.Number : _num_cvt, 1088 hyperdb.Number : _num_cvt,
1089 hyperdb.Integer : int,
1087 hyperdb.Multilink : lambda x: x, # used in journal marshalling 1090 hyperdb.Multilink : lambda x: x, # used in journal marshalling
1088 } 1091 }
1089 1092
1090 def to_hyperdb_value(self, propklass): 1093 def to_hyperdb_value(self, propklass):
1091 1094
1630 try: 1633 try:
1631 float(value) 1634 float(value)
1632 except ValueError: 1635 except ValueError:
1633 raise TypeError('new property "%s" not numeric'%key) 1636 raise TypeError('new property "%s" not numeric'%key)
1634 1637
1638 elif value is not None and isinstance(prop, Integer):
1639 try:
1640 int(value)
1641 except ValueError:
1642 raise TypeError('new property "%s" not integer'%key)
1643
1635 elif value is not None and isinstance(prop, Boolean): 1644 elif value is not None and isinstance(prop, Boolean):
1636 try: 1645 try:
1637 int(value) 1646 int(value)
1638 except ValueError: 1647 except ValueError:
1639 raise TypeError('new property "%s" not boolean'%key) 1648 raise TypeError('new property "%s" not boolean'%key)
1928 elif value is not None and isinstance(prop, Number): 1937 elif value is not None and isinstance(prop, Number):
1929 try: 1938 try:
1930 float(value) 1939 float(value)
1931 except ValueError: 1940 except ValueError:
1932 raise TypeError('new property "%s" not numeric'%propname) 1941 raise TypeError('new property "%s" not numeric'%propname)
1942
1943 elif value is not None and isinstance(prop, Integer):
1944 try:
1945 int(value)
1946 except ValueError:
1947 raise TypeError('new property "%s" not integer'%propname)
1933 1948
1934 elif value is not None and isinstance(prop, Boolean): 1949 elif value is not None and isinstance(prop, Boolean):
1935 try: 1950 try:
1936 int(value) 1951 int(value)
1937 except ValueError: 1952 except ValueError:

Roundup Issue Tracker: http://roundup-tracker.org/