sqlobject 3.13.1__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sqlobject/__init__.py +15 -0
- sqlobject/__version__.py +8 -0
- sqlobject/boundattributes.py +124 -0
- sqlobject/cache.py +376 -0
- sqlobject/classregistry.py +138 -0
- sqlobject/col.py +2187 -0
- sqlobject/compat.py +59 -0
- sqlobject/conftest.py +64 -0
- sqlobject/constraints.py +77 -0
- sqlobject/converters.py +278 -0
- sqlobject/dbconnection.py +1137 -0
- sqlobject/dberrors.py +54 -0
- sqlobject/declarative.py +211 -0
- sqlobject/events.py +365 -0
- sqlobject/firebird/__init__.py +8 -0
- sqlobject/firebird/firebirdconnection.py +463 -0
- sqlobject/include/__init__.py +1 -0
- sqlobject/include/hashcol.py +109 -0
- sqlobject/include/tests/__init__.py +1 -0
- sqlobject/include/tests/test_hashcol.py +84 -0
- sqlobject/index.py +189 -0
- sqlobject/inheritance/__init__.py +551 -0
- sqlobject/inheritance/iteration.py +106 -0
- sqlobject/inheritance/tests/__init__.py +1 -0
- sqlobject/inheritance/tests/test_aggregates.py +23 -0
- sqlobject/inheritance/tests/test_asdict.py +48 -0
- sqlobject/inheritance/tests/test_deep_inheritance.py +114 -0
- sqlobject/inheritance/tests/test_destroy_cascade.py +23 -0
- sqlobject/inheritance/tests/test_foreignKey.py +94 -0
- sqlobject/inheritance/tests/test_indexes.py +42 -0
- sqlobject/inheritance/tests/test_inheritance.py +164 -0
- sqlobject/inheritance/tests/test_inheritance_tree.py +50 -0
- sqlobject/joins.py +656 -0
- sqlobject/main.py +1880 -0
- sqlobject/manager/__init__.py +1 -0
- sqlobject/manager/command.py +1309 -0
- sqlobject/maxdb/__init__.py +8 -0
- sqlobject/maxdb/maxdbconnection.py +320 -0
- sqlobject/maxdb/readme.txt +27 -0
- sqlobject/mssql/__init__.py +8 -0
- sqlobject/mssql/mssqlconnection.py +417 -0
- sqlobject/mysql/__init__.py +8 -0
- sqlobject/mysql/mysqlconnection.py +562 -0
- sqlobject/postgres/__init__.py +8 -0
- sqlobject/postgres/pgconnection.py +619 -0
- sqlobject/sqlbuilder.py +1655 -0
- sqlobject/sqlite/__init__.py +8 -0
- sqlobject/sqlite/sqliteconnection.py +418 -0
- sqlobject/sresults.py +377 -0
- sqlobject/styles.py +174 -0
- sqlobject/sybase/__init__.py +8 -0
- sqlobject/sybase/sybaseconnection.py +183 -0
- sqlobject/tests/__init__.py +1 -0
- sqlobject/tests/dbtest.py +363 -0
- sqlobject/tests/test_ForeignKey.py +133 -0
- sqlobject/tests/test_ForeignKey_cascade.py +150 -0
- sqlobject/tests/test_NoneValuedResultItem.py +33 -0
- sqlobject/tests/test_SQLMultipleJoin.py +65 -0
- sqlobject/tests/test_SQLRelatedJoin.py +114 -0
- sqlobject/tests/test_SingleJoin.py +30 -0
- sqlobject/tests/test_aggregates.py +75 -0
- sqlobject/tests/test_aliases.py +49 -0
- sqlobject/tests/test_asdict.py +18 -0
- sqlobject/tests/test_auto.py +218 -0
- sqlobject/tests/test_basic.py +359 -0
- sqlobject/tests/test_blob.py +34 -0
- sqlobject/tests/test_boundattributes.py +67 -0
- sqlobject/tests/test_cache.py +57 -0
- sqlobject/tests/test_class_hash.py +22 -0
- sqlobject/tests/test_columns_order.py +18 -0
- sqlobject/tests/test_combining_joins.py +47 -0
- sqlobject/tests/test_comparison.py +24 -0
- sqlobject/tests/test_compat.py +10 -0
- sqlobject/tests/test_complex_sorting.py +77 -0
- sqlobject/tests/test_constraints.py +43 -0
- sqlobject/tests/test_converters.py +276 -0
- sqlobject/tests/test_create_drop.py +29 -0
- sqlobject/tests/test_csvexport.py +101 -0
- sqlobject/tests/test_csvimport.py +21 -0
- sqlobject/tests/test_cyclic_reference.py +55 -0
- sqlobject/tests/test_datetime.py +171 -0
- sqlobject/tests/test_dbconnection.py +17 -0
- sqlobject/tests/test_decimal.py +63 -0
- sqlobject/tests/test_declarative.py +83 -0
- sqlobject/tests/test_default_style.py +65 -0
- sqlobject/tests/test_delete.py +74 -0
- sqlobject/tests/test_distinct.py +36 -0
- sqlobject/tests/test_empty.py +22 -0
- sqlobject/tests/test_enum.py +75 -0
- sqlobject/tests/test_events.py +142 -0
- sqlobject/tests/test_exceptions.py +40 -0
- sqlobject/tests/test_expire.py +29 -0
- sqlobject/tests/test_groupBy.py +45 -0
- sqlobject/tests/test_identity.py +29 -0
- sqlobject/tests/test_indexes.py +100 -0
- sqlobject/tests/test_inheritance.py +35 -0
- sqlobject/tests/test_joins.py +160 -0
- sqlobject/tests/test_joins_conditional.py +143 -0
- sqlobject/tests/test_jsonbcol.py +53 -0
- sqlobject/tests/test_jsoncol.py +56 -0
- sqlobject/tests/test_lazy.py +165 -0
- sqlobject/tests/test_md5.py +13 -0
- sqlobject/tests/test_mysql.py +50 -0
- sqlobject/tests/test_new_joins.py +165 -0
- sqlobject/tests/test_parse_uri.py +147 -0
- sqlobject/tests/test_paste.py +92 -0
- sqlobject/tests/test_perConnection.py +20 -0
- sqlobject/tests/test_pickle.py +42 -0
- sqlobject/tests/test_picklecol.py +44 -0
- sqlobject/tests/test_postgres.py +82 -0
- sqlobject/tests/test_reparent_sqlmeta.py +33 -0
- sqlobject/tests/test_schema.py +30 -0
- sqlobject/tests/test_select.py +218 -0
- sqlobject/tests/test_select_through.py +63 -0
- sqlobject/tests/test_setters.py +23 -0
- sqlobject/tests/test_slice.py +59 -0
- sqlobject/tests/test_sorting.py +80 -0
- sqlobject/tests/test_sqlbuilder.py +134 -0
- sqlobject/tests/test_sqlbuilder_dbspecific.py +66 -0
- sqlobject/tests/test_sqlbuilder_importproxy.py +55 -0
- sqlobject/tests/test_sqlbuilder_joins_instances.py +90 -0
- sqlobject/tests/test_sqlite.py +160 -0
- sqlobject/tests/test_sqlmeta_idName.py +52 -0
- sqlobject/tests/test_sqlobject_admin.py +38 -0
- sqlobject/tests/test_string_id.py +79 -0
- sqlobject/tests/test_style.py +36 -0
- sqlobject/tests/test_subqueries.py +142 -0
- sqlobject/tests/test_transactions.py +122 -0
- sqlobject/tests/test_unicode.py +84 -0
- sqlobject/tests/test_uuidcol.py +40 -0
- sqlobject/tests/test_validation.py +125 -0
- sqlobject/tests/test_views.py +159 -0
- sqlobject/util/__init__.py +1 -0
- sqlobject/util/csvexport.py +210 -0
- sqlobject/util/csvimport.py +366 -0
- sqlobject/util/moduleloader.py +35 -0
- sqlobject/util/threadinglocal.py +6 -0
- sqlobject/versioning/__init__.py +120 -0
- sqlobject/versioning/test/__init__.py +0 -0
- sqlobject/versioning/test/test_version.py +183 -0
- sqlobject/views.py +151 -0
- sqlobject/wsgi_middleware.py +109 -0
- sqlobject-3.13.1.data/scripts/sqlobject-admin +36 -0
- sqlobject-3.13.1.data/scripts/sqlobject-convertOldURI +19 -0
- sqlobject-3.13.1.dist-info/METADATA +177 -0
- sqlobject-3.13.1.dist-info/RECORD +149 -0
- sqlobject-3.13.1.dist-info/WHEEL +6 -0
- sqlobject-3.13.1.dist-info/entry_points.txt +4 -0
- sqlobject-3.13.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
from sqlobject import SQLObject, StringCol
|
|
2
|
+
from sqlobject.cache import CacheSet
|
|
3
|
+
from .dbtest import setupClass
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Something(object):
|
|
7
|
+
pass
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_purge1():
|
|
11
|
+
x = CacheSet()
|
|
12
|
+
y = Something()
|
|
13
|
+
obj = x.get(1, y.__class__)
|
|
14
|
+
assert obj is None
|
|
15
|
+
x.put(1, y.__class__, y)
|
|
16
|
+
x.finishPut(y.__class__)
|
|
17
|
+
j = x.get(1, y.__class__)
|
|
18
|
+
assert j == y
|
|
19
|
+
x.expire(1, y.__class__)
|
|
20
|
+
j = x.get(1, y.__class__)
|
|
21
|
+
assert j is None
|
|
22
|
+
x.finishPut(y.__class__)
|
|
23
|
+
j = x.get(1, y.__class__)
|
|
24
|
+
assert j is None
|
|
25
|
+
x.finishPut(y.__class__)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class CacheTest(SQLObject):
|
|
29
|
+
name = StringCol(alternateID=True, length=100)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_cache():
|
|
33
|
+
setupClass(CacheTest)
|
|
34
|
+
s = CacheTest(name='foo')
|
|
35
|
+
obj_id = id(s)
|
|
36
|
+
s_id = s.id
|
|
37
|
+
assert CacheTest.get(s_id) is s
|
|
38
|
+
assert not s.sqlmeta.expired
|
|
39
|
+
CacheTest.sqlmeta.expireAll()
|
|
40
|
+
assert s.sqlmeta.expired
|
|
41
|
+
CacheTest.sqlmeta.expireAll()
|
|
42
|
+
s1 = CacheTest.get(s_id)
|
|
43
|
+
# We should have a new object:
|
|
44
|
+
assert id(s1) != obj_id
|
|
45
|
+
obj_id2 = id(s1)
|
|
46
|
+
CacheTest._connection.expireAll()
|
|
47
|
+
s2 = CacheTest.get(s_id)
|
|
48
|
+
assert id(s2) != obj_id and id(s2) != obj_id2
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_cache_cull():
|
|
52
|
+
setupClass(CacheTest)
|
|
53
|
+
s = CacheTest(name='test_cache_create')
|
|
54
|
+
for count in range(s._connection.cache.caches['CacheTest'].cullFrequency):
|
|
55
|
+
CacheTest(name='test_cache_create %d' % count)
|
|
56
|
+
assert len(s._connection.cache.caches['CacheTest'].cache) < \
|
|
57
|
+
s._connection.cache.caches['CacheTest'].cullFrequency
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from sqlobject import SQLObject, StringCol
|
|
2
|
+
from sqlobject.tests.dbtest import setupClass
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
########################################
|
|
6
|
+
# Test hashing a column instance
|
|
7
|
+
########################################
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ClassHashTest(SQLObject):
|
|
11
|
+
name = StringCol(length=50, alternateID=True, dbName='name_col')
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_class_hash():
|
|
15
|
+
setupClass(ClassHashTest)
|
|
16
|
+
ClassHashTest(name='bob')
|
|
17
|
+
|
|
18
|
+
b = ClassHashTest.byName('bob')
|
|
19
|
+
hashed = hash(b)
|
|
20
|
+
b.expire()
|
|
21
|
+
b = ClassHashTest.byName('bob')
|
|
22
|
+
assert hash(b) == hashed
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from sqlobject import IntCol, SQLObject, StringCol
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
########################################
|
|
5
|
+
# Columns order
|
|
6
|
+
########################################
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SOColumnsOrder(SQLObject):
|
|
10
|
+
name = StringCol()
|
|
11
|
+
surname = StringCol()
|
|
12
|
+
parname = StringCol()
|
|
13
|
+
age = IntCol()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_columns_order():
|
|
17
|
+
column_names = [c.name for c in SOColumnsOrder.sqlmeta.columnList]
|
|
18
|
+
assert column_names == ['name', 'surname', 'parname', 'age']
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from sqlobject import ForeignKey, ManyToMany, OneToMany, SQLObject, StringCol
|
|
2
|
+
from .dbtest import setupClass
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class ComplexGroup(SQLObject):
|
|
6
|
+
name = StringCol()
|
|
7
|
+
complexes = OneToMany('Complex')
|
|
8
|
+
|
|
9
|
+
def _get_unit_models(self):
|
|
10
|
+
q = self.complexes.clause & Complex.unit_models.clause
|
|
11
|
+
return UnitModel.select(q)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Complex(SQLObject):
|
|
15
|
+
name = StringCol()
|
|
16
|
+
unit_models = ManyToMany('UnitModel')
|
|
17
|
+
complex_group = ForeignKey('ComplexGroup')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class UnitModel(SQLObject):
|
|
21
|
+
class sqlmeta:
|
|
22
|
+
defaultOrderBy = 'name'
|
|
23
|
+
name = StringCol()
|
|
24
|
+
complexes = ManyToMany('Complex')
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_join_sqlrepr():
|
|
28
|
+
setupClass([ComplexGroup, UnitModel, Complex])
|
|
29
|
+
cg1 = ComplexGroup(name='cg1')
|
|
30
|
+
cg2 = ComplexGroup(name='cg2')
|
|
31
|
+
c1 = Complex(name='c1', complex_group=cg1)
|
|
32
|
+
c2 = Complex(name='c2', complex_group=cg2)
|
|
33
|
+
c3 = Complex(name='c3', complex_group=cg2)
|
|
34
|
+
u1 = UnitModel(name='u1')
|
|
35
|
+
u2 = UnitModel(name='u2')
|
|
36
|
+
u1.complexes.add(c1)
|
|
37
|
+
u1.complexes.add(c2)
|
|
38
|
+
u2.complexes.add(c2)
|
|
39
|
+
u2.complexes.add(c3)
|
|
40
|
+
assert list(Complex.selectBy(name='c1')) == [c1]
|
|
41
|
+
|
|
42
|
+
assert list(cg1.unit_models) == [u1]
|
|
43
|
+
assert list(cg2.unit_models) == [u1, u2, u2]
|
|
44
|
+
assert list(cg2.unit_models.distinct()) == [u1, u2]
|
|
45
|
+
|
|
46
|
+
assert list(
|
|
47
|
+
cg2.unit_models.filter(UnitModel.q.name == 'u1')) == [u1]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from sqlobject import SQLObject
|
|
2
|
+
from sqlobject.tests.dbtest import setupClass
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SOTestComparison(SQLObject):
|
|
6
|
+
pass
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_eq():
|
|
10
|
+
setupClass(SOTestComparison, force=True)
|
|
11
|
+
t1 = SOTestComparison()
|
|
12
|
+
t2 = SOTestComparison()
|
|
13
|
+
|
|
14
|
+
SOTestComparison._connection.cache.clear()
|
|
15
|
+
t3 = SOTestComparison.get(1)
|
|
16
|
+
t4 = SOTestComparison.get(2)
|
|
17
|
+
|
|
18
|
+
assert t1.id == t3.id
|
|
19
|
+
assert t2.id == t4.id
|
|
20
|
+
assert t1 is not t3
|
|
21
|
+
assert t2 is not t4
|
|
22
|
+
assert t1 == t3
|
|
23
|
+
assert t2 == t4
|
|
24
|
+
assert t1 != t2
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from sqlobject.compat import load_module_from_file
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_load_module_from_path():
|
|
5
|
+
module = load_module_from_file(
|
|
6
|
+
'test_compat', 'sqlobject.tests.test_compat', __file__
|
|
7
|
+
)
|
|
8
|
+
assert module.__file__ == __file__
|
|
9
|
+
assert module.__name__ == 'sqlobject.tests.test_compat'
|
|
10
|
+
assert module.__package__ == 'sqlobject.tests'
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from sqlobject import IntCol, SQLObject, StringCol, sqlmeta
|
|
2
|
+
from sqlobject.tests.dbtest import inserts, setupClass
|
|
3
|
+
|
|
4
|
+
# Test more complex orderBy clauses
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ComplexNames(SQLObject):
|
|
8
|
+
|
|
9
|
+
class sqlmeta(sqlmeta):
|
|
10
|
+
table = 'names_table'
|
|
11
|
+
defaultOrder = ['lastName', 'firstName', 'phone', 'age']
|
|
12
|
+
|
|
13
|
+
firstName = StringCol(length=30)
|
|
14
|
+
lastName = StringCol(length=30)
|
|
15
|
+
phone = StringCol(length=11)
|
|
16
|
+
age = IntCol()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def setupComplexNames():
|
|
20
|
+
setupClass(ComplexNames)
|
|
21
|
+
inserts(ComplexNames, [('aj', 'baker', '555-444-333', 34),
|
|
22
|
+
('joe', 'robbins', '444-555-333', 34),
|
|
23
|
+
('tim', 'jackson', '555-444-222', 32),
|
|
24
|
+
('joe', 'baker', '222-111-000', 24),
|
|
25
|
+
('zoe', 'robbins', '444-555-333', 46)],
|
|
26
|
+
schema='firstName lastName phone age')
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def nameList(names):
|
|
30
|
+
result = []
|
|
31
|
+
for name in names:
|
|
32
|
+
result.append('%s %s' % (name.firstName, name.lastName))
|
|
33
|
+
return result
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def firstList(names):
|
|
37
|
+
return [n.firstName for n in names]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_defaultComplexOrder():
|
|
41
|
+
setupComplexNames()
|
|
42
|
+
assert nameList(ComplexNames.select()) == \
|
|
43
|
+
['aj baker', 'joe baker',
|
|
44
|
+
'tim jackson', 'joe robbins',
|
|
45
|
+
'zoe robbins']
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_complexOrders():
|
|
49
|
+
setupComplexNames()
|
|
50
|
+
assert nameList(ComplexNames.select().orderBy(['age', 'phone',
|
|
51
|
+
'firstName',
|
|
52
|
+
'lastName'])) == \
|
|
53
|
+
['joe baker', 'tim jackson',
|
|
54
|
+
'joe robbins', 'aj baker',
|
|
55
|
+
'zoe robbins']
|
|
56
|
+
assert nameList(ComplexNames.select().orderBy(['-age', 'phone',
|
|
57
|
+
'firstName',
|
|
58
|
+
'lastName'])) == \
|
|
59
|
+
['zoe robbins', 'joe robbins',
|
|
60
|
+
'aj baker', 'tim jackson',
|
|
61
|
+
'joe baker']
|
|
62
|
+
assert nameList(ComplexNames.select().orderBy(['age', '-phone',
|
|
63
|
+
'firstName',
|
|
64
|
+
'lastName'])) == \
|
|
65
|
+
['joe baker', 'tim jackson',
|
|
66
|
+
'aj baker', 'joe robbins',
|
|
67
|
+
'zoe robbins']
|
|
68
|
+
assert nameList(ComplexNames.select().orderBy(['-firstName', 'phone',
|
|
69
|
+
'lastName', 'age'])) == \
|
|
70
|
+
['zoe robbins', 'tim jackson',
|
|
71
|
+
'joe baker', 'joe robbins',
|
|
72
|
+
'aj baker']
|
|
73
|
+
assert nameList(ComplexNames.select().orderBy(['-firstName', '-phone',
|
|
74
|
+
'lastName', 'age'])) == \
|
|
75
|
+
['zoe robbins', 'tim jackson',
|
|
76
|
+
'joe robbins', 'joe baker',
|
|
77
|
+
'aj baker']
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from sqlobject.compat import PY2
|
|
2
|
+
from sqlobject.constraints import BadValue, InList, MaxLength, \
|
|
3
|
+
isFloat, isInt, isString, notNull
|
|
4
|
+
from sqlobject.tests.dbtest import Dummy, raises
|
|
5
|
+
|
|
6
|
+
if not PY2:
|
|
7
|
+
# alias for python 3 compatability
|
|
8
|
+
long = int
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_constraints():
|
|
12
|
+
obj = 'Test object'
|
|
13
|
+
col = Dummy(name='col')
|
|
14
|
+
isString(obj, col, 'blah')
|
|
15
|
+
raises(BadValue, isString, obj, col, 1)
|
|
16
|
+
if PY2:
|
|
17
|
+
# @@: Should this really be an error?
|
|
18
|
+
raises(BadValue, isString, obj, col, u'test!')
|
|
19
|
+
else:
|
|
20
|
+
raises(BadValue, isString, obj, col, b'test!')
|
|
21
|
+
# isString(obj, col, u'test!')
|
|
22
|
+
|
|
23
|
+
raises(BadValue, notNull, obj, col, None)
|
|
24
|
+
raises(BadValue, isInt, obj, col, 1.1)
|
|
25
|
+
isInt(obj, col, 1)
|
|
26
|
+
isInt(obj, col, long(1))
|
|
27
|
+
isFloat(obj, col, 1)
|
|
28
|
+
isFloat(obj, col, long(1))
|
|
29
|
+
isFloat(obj, col, 1.2)
|
|
30
|
+
raises(BadValue, isFloat, obj, col, '1.0')
|
|
31
|
+
|
|
32
|
+
# @@: Should test isBool, but I don't think isBool is right
|
|
33
|
+
|
|
34
|
+
lst = InList(('a', 'b', 'c'))
|
|
35
|
+
lst(obj, col, 'a')
|
|
36
|
+
raises(BadValue, lst, obj, col, ('a', 'b', 'c'))
|
|
37
|
+
raises(BadValue, lst, obj, col, 'A')
|
|
38
|
+
|
|
39
|
+
maxlen = MaxLength(2)
|
|
40
|
+
raises(BadValue, maxlen, obj, col, '123')
|
|
41
|
+
maxlen(obj, col, '12')
|
|
42
|
+
maxlen(obj, col, (1,))
|
|
43
|
+
raises(BadValue, maxlen, obj, col, 1)
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
from datetime import timedelta
|
|
2
|
+
|
|
3
|
+
from sqlobject.col import SODateTimeCol, SOTimeCol
|
|
4
|
+
from sqlobject.converters import registerConverter, sqlrepr, \
|
|
5
|
+
quote_str, unquote_str
|
|
6
|
+
from sqlobject.sqlbuilder import SQLExpression, SQLObjectField, \
|
|
7
|
+
Select, Insert, Update, Delete, Replace, \
|
|
8
|
+
SQLTrueClauseClass, SQLConstant, SQLPrefix, SQLCall, SQLOp, \
|
|
9
|
+
_LikeQuoted
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SOTestClass:
|
|
13
|
+
|
|
14
|
+
def __repr__(self):
|
|
15
|
+
return '<SOTestClass>'
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def SOTestClassConverter(value, db):
|
|
19
|
+
return repr(value)
|
|
20
|
+
|
|
21
|
+
registerConverter(SOTestClass, SOTestClassConverter)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class NewSOTestClass:
|
|
25
|
+
|
|
26
|
+
__metaclass__ = type
|
|
27
|
+
|
|
28
|
+
def __repr__(self):
|
|
29
|
+
return '<NewSOTestClass>'
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def NewSOTestClassConverter(value, db):
|
|
33
|
+
return repr(value)
|
|
34
|
+
|
|
35
|
+
registerConverter(NewSOTestClass, NewSOTestClassConverter)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _sqlrepr(self, db):
|
|
39
|
+
return '<%s>' % self.__class__.__name__
|
|
40
|
+
|
|
41
|
+
SQLExpression.__sqlrepr__ = _sqlrepr
|
|
42
|
+
|
|
43
|
+
############################################################
|
|
44
|
+
# Tests
|
|
45
|
+
############################################################
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_simple_string():
|
|
49
|
+
assert sqlrepr('A String', 'firebird') == "'A String'"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_string_newline():
|
|
53
|
+
assert sqlrepr('A String\nAnother', 'postgres') == "E'A String\\nAnother'"
|
|
54
|
+
assert sqlrepr('A String\nAnother', 'sqlite') == "'A String\nAnother'"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_string_tab():
|
|
58
|
+
assert sqlrepr('A String\tAnother', 'postgres') == "E'A String\\tAnother'"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_string_r():
|
|
62
|
+
assert sqlrepr('A String\rAnother', 'postgres') == "E'A String\\rAnother'"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_string_b():
|
|
66
|
+
assert sqlrepr('A String\bAnother', 'postgres') == "E'A String\\bAnother'"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_string_000():
|
|
70
|
+
assert sqlrepr('A String\000Another', 'postgres') == \
|
|
71
|
+
"E'A String\\0Another'"
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_string_():
|
|
75
|
+
assert sqlrepr('A String\tAnother', 'postgres') == "E'A String\\tAnother'"
|
|
76
|
+
assert sqlrepr('A String\'Another', 'firebird') == "'A String''Another'"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_simple_unicode():
|
|
80
|
+
assert sqlrepr(u'A String', 'postgres') == "'A String'"
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_integer():
|
|
84
|
+
assert sqlrepr(10) == "10"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_float():
|
|
88
|
+
assert sqlrepr(10.01) == "10.01"
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_none():
|
|
92
|
+
assert sqlrepr(None) == "NULL"
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_list():
|
|
96
|
+
assert sqlrepr(['one', 'two', 'three'], 'postgres') == \
|
|
97
|
+
"('one', 'two', 'three')"
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_tuple():
|
|
101
|
+
assert sqlrepr(('one', 'two', 'three'), 'postgres') == \
|
|
102
|
+
"('one', 'two', 'three')"
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def test_bool():
|
|
106
|
+
assert sqlrepr(True, 'postgres') == "'t'"
|
|
107
|
+
assert sqlrepr(False, 'postgres') == "'f'"
|
|
108
|
+
assert sqlrepr(True, 'mysql') == "1"
|
|
109
|
+
assert sqlrepr(False, 'mysql') == "0"
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def test_datetime():
|
|
113
|
+
from datetime import datetime, date, time
|
|
114
|
+
if SODateTimeCol.datetimeFormat.find('.%f') > 0:
|
|
115
|
+
assert sqlrepr(datetime(2005, 7, 14, 13, 31, 2)) == \
|
|
116
|
+
"'2005-07-14 13:31:02.000000'"
|
|
117
|
+
else:
|
|
118
|
+
assert sqlrepr(datetime(2005, 7, 14, 13, 31, 2)) == \
|
|
119
|
+
"'2005-07-14 13:31:02'"
|
|
120
|
+
assert sqlrepr(date(2005, 7, 14)) == "'2005-07-14'"
|
|
121
|
+
if SOTimeCol.timeFormat.find('.%f') > 0:
|
|
122
|
+
assert sqlrepr(time(13, 31, 2)) == "'13:31:02.000000'"
|
|
123
|
+
else:
|
|
124
|
+
assert sqlrepr(time(13, 31, 2)) == "'13:31:02'"
|
|
125
|
+
# now dates before 1900
|
|
126
|
+
if SODateTimeCol.datetimeFormat.find('.%f') > 0:
|
|
127
|
+
assert sqlrepr(datetime(1428, 7, 14, 13, 31, 2)) == \
|
|
128
|
+
"'1428-07-14 13:31:02.000000'"
|
|
129
|
+
else:
|
|
130
|
+
assert sqlrepr(datetime(1428, 7, 14, 13, 31, 2)) == \
|
|
131
|
+
"'1428-07-14 13:31:02'"
|
|
132
|
+
assert sqlrepr(date(1428, 7, 14)) == "'1428-07-14'"
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def test_instance():
|
|
136
|
+
instance = SOTestClass()
|
|
137
|
+
assert sqlrepr(instance) == repr(instance)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def test_newstyle():
|
|
141
|
+
instance = NewSOTestClass()
|
|
142
|
+
assert sqlrepr(instance) == repr(instance)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def test_sqlexpr():
|
|
146
|
+
instance = SQLExpression()
|
|
147
|
+
assert sqlrepr(instance) == repr(instance)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def test_sqlobjectfield():
|
|
151
|
+
instance = SQLObjectField('test', 'test', 'test', None, None)
|
|
152
|
+
assert sqlrepr(instance) == repr(instance)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def test_select():
|
|
156
|
+
instance = Select('test')
|
|
157
|
+
assert sqlrepr(instance, 'mysql') == "SELECT test"
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def test_insert():
|
|
161
|
+
# Single column, no keyword arguments.
|
|
162
|
+
instance = Insert('test', [('test',)])
|
|
163
|
+
assert sqlrepr(instance, 'mysql') == "INSERT INTO test VALUES ('test')"
|
|
164
|
+
|
|
165
|
+
# Multiple columns, no keyword arguments.
|
|
166
|
+
instance2 = Insert('test', [('1st', '2nd', '3th', '4th')])
|
|
167
|
+
assert sqlrepr(instance2, 'postgres') == \
|
|
168
|
+
"INSERT INTO test VALUES ('1st', '2nd', '3th', '4th')"
|
|
169
|
+
|
|
170
|
+
# Multiple rows, multiple columns, "valueList" keyword argument.
|
|
171
|
+
instance3 = Insert('test',
|
|
172
|
+
valueList=[('a1', 'b1'), ('a2', 'b2'), ('a3', 'b3')])
|
|
173
|
+
assert sqlrepr(instance3, 'sqlite') == \
|
|
174
|
+
"INSERT INTO test VALUES ('a1', 'b1'), ('a2', 'b2'), ('a3', 'b3')"
|
|
175
|
+
|
|
176
|
+
# Multiple columns, "values" keyword argument.
|
|
177
|
+
instance4 = Insert('test', values=('v1', 'v2', 'v3'))
|
|
178
|
+
assert sqlrepr(instance4, 'mysql') == \
|
|
179
|
+
"INSERT INTO test VALUES ('v1', 'v2', 'v3')"
|
|
180
|
+
|
|
181
|
+
# Single column, "valueList" keyword argument.
|
|
182
|
+
instance5 = Insert('test', valueList=[('v1',)])
|
|
183
|
+
assert sqlrepr(instance5, 'mysql') == "INSERT INTO test VALUES ('v1')"
|
|
184
|
+
|
|
185
|
+
# Multiple rows, Multiple columns, template.
|
|
186
|
+
instance6 = Insert('test',
|
|
187
|
+
valueList=[('a1', 'b1'), ('a2', 'b2')],
|
|
188
|
+
template=['col1', 'col2'])
|
|
189
|
+
assert sqlrepr(instance6, 'mysql') == \
|
|
190
|
+
"INSERT INTO test (col1, col2) VALUES ('a1', 'b1'), ('a2', 'b2')"
|
|
191
|
+
|
|
192
|
+
# Multiple columns, implicit template (dictionary value).
|
|
193
|
+
instance7 = Insert('test', valueList=[{'col1': 'a1', 'col2': 'b1'}])
|
|
194
|
+
assert sqlrepr(instance7, 'mysql') == \
|
|
195
|
+
"INSERT INTO test (col1, col2) VALUES ('a1', 'b1')"
|
|
196
|
+
|
|
197
|
+
# Multiple rows, Multiple columns, implicit template.
|
|
198
|
+
instance8 = Insert('test', valueList=[{'col1': 'a1', 'col2': 'b1'},
|
|
199
|
+
{'col1': 'a2', 'col2': 'b2'}])
|
|
200
|
+
assert sqlrepr(instance8, 'mysql') == \
|
|
201
|
+
"INSERT INTO test (col1, col2) VALUES ('a1', 'b1'), ('a2', 'b2')"
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def test_update():
|
|
205
|
+
instance = Update('test', {'test': 'test'})
|
|
206
|
+
assert sqlrepr(instance, 'mysql') == "UPDATE test SET test='test'"
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def test_delete():
|
|
210
|
+
instance = Delete('test', None)
|
|
211
|
+
assert sqlrepr(instance, 'mysql') == "DELETE FROM test"
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def test_replace():
|
|
215
|
+
instance = Replace('test', {'test': 'test'})
|
|
216
|
+
assert sqlrepr(instance, 'mysql') == "REPLACE test SET test='test'"
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def test_trueclause():
|
|
220
|
+
instance = SQLTrueClauseClass()
|
|
221
|
+
assert sqlrepr(instance) == repr(instance)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def test_op():
|
|
225
|
+
instance = SQLOp('and', 'this', 'that')
|
|
226
|
+
assert sqlrepr(instance, 'mysql') == "(('this') AND ('that'))"
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def test_call():
|
|
230
|
+
instance = SQLCall('test', ('test',))
|
|
231
|
+
assert sqlrepr(instance, 'mysql') == "'test'('test')"
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def test_constant():
|
|
235
|
+
instance = SQLConstant('test')
|
|
236
|
+
assert sqlrepr(instance) == repr(instance)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def test_prefix():
|
|
240
|
+
instance = SQLPrefix('test', 'test')
|
|
241
|
+
assert sqlrepr(instance, 'mysql') == "test 'test'"
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def test_dict():
|
|
245
|
+
assert sqlrepr({"key": "value"}, "sqlite") == "('key')"
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def test_sets():
|
|
249
|
+
try:
|
|
250
|
+
set
|
|
251
|
+
except NameError:
|
|
252
|
+
pass
|
|
253
|
+
else:
|
|
254
|
+
assert sqlrepr(set([1])) == "(1)"
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def test_timedelta():
|
|
258
|
+
assert sqlrepr(timedelta(seconds=30 * 60)) == \
|
|
259
|
+
"INTERVAL '0 days 1800 seconds'"
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def test_quote_unquote_str():
|
|
263
|
+
assert quote_str('test%', 'postgres') == "'test%'"
|
|
264
|
+
assert quote_str('test%', 'sqlite') == "'test%'"
|
|
265
|
+
assert quote_str('test\\%', 'postgres') == "E'test\\%'"
|
|
266
|
+
assert quote_str('test\\%', 'sqlite') == "'test\\%'"
|
|
267
|
+
assert unquote_str("'test%'") == 'test%'
|
|
268
|
+
assert unquote_str("'test\\%'") == 'test\\%'
|
|
269
|
+
assert unquote_str("E'test\\%'") == 'test\\%'
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def test_like_quoted():
|
|
273
|
+
assert sqlrepr(_LikeQuoted('test'), 'postgres') == "'test'"
|
|
274
|
+
assert sqlrepr(_LikeQuoted('test'), 'sqlite') == "'test'"
|
|
275
|
+
assert sqlrepr(_LikeQuoted('test%'), 'postgres') == r"E'test\\%'"
|
|
276
|
+
assert sqlrepr(_LikeQuoted('test%'), 'sqlite') == r"'test\%'"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from sqlobject import BLOBCol, DateTimeCol, IntCol, SQLObject, StringCol, \
|
|
2
|
+
sqlmeta
|
|
3
|
+
from sqlobject.tests.dbtest import getConnection
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SOTestCreateDrop(SQLObject):
|
|
7
|
+
class sqlmeta(sqlmeta):
|
|
8
|
+
idName = 'test_id_here'
|
|
9
|
+
table = 'test_create_drop_table'
|
|
10
|
+
name = StringCol()
|
|
11
|
+
number = IntCol()
|
|
12
|
+
so_time = DateTimeCol()
|
|
13
|
+
short = StringCol(length=10)
|
|
14
|
+
blobcol = BLOBCol()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_create_drop():
|
|
18
|
+
conn = getConnection()
|
|
19
|
+
SOTestCreateDrop.setConnection(conn)
|
|
20
|
+
SOTestCreateDrop.dropTable(ifExists=True)
|
|
21
|
+
assert not conn.tableExists(SOTestCreateDrop.sqlmeta.table)
|
|
22
|
+
SOTestCreateDrop.createTable(ifNotExists=True)
|
|
23
|
+
assert conn.tableExists(SOTestCreateDrop.sqlmeta.table)
|
|
24
|
+
SOTestCreateDrop.createTable(ifNotExists=True)
|
|
25
|
+
assert conn.tableExists(SOTestCreateDrop.sqlmeta.table)
|
|
26
|
+
SOTestCreateDrop.dropTable(ifExists=True)
|
|
27
|
+
assert not conn.tableExists(SOTestCreateDrop.sqlmeta.table)
|
|
28
|
+
SOTestCreateDrop.dropTable(ifExists=True)
|
|
29
|
+
assert not conn.tableExists(SOTestCreateDrop.sqlmeta.table)
|