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,90 @@
|
|
|
1
|
+
from sqlobject import AND, ForeignKey, SQLMultipleJoin, SQLObject, \
|
|
2
|
+
SQLRelatedJoin, StringCol
|
|
3
|
+
from sqlobject.tests.dbtest import inserts, setupClass
|
|
4
|
+
|
|
5
|
+
# Testing for expressing join, foreign keys,
|
|
6
|
+
# and instance identity in SQLBuilder expressions.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SBPerson(SQLObject):
|
|
10
|
+
name = StringCol()
|
|
11
|
+
addresses = SQLMultipleJoin('SBAddress', joinColumn='personID')
|
|
12
|
+
sharedAddresses = SQLRelatedJoin('SBAddress',
|
|
13
|
+
addRemoveName='SharedAddress')
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class SBAddress(SQLObject):
|
|
17
|
+
city = StringCol()
|
|
18
|
+
person = ForeignKey('SBPerson')
|
|
19
|
+
sharedPeople = SQLRelatedJoin('SBPerson')
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def setup_module(mod):
|
|
23
|
+
global ppl
|
|
24
|
+
setupClass([SBPerson, SBAddress])
|
|
25
|
+
ppl = inserts(SBPerson, [('James',), ('Julia',)], 'name')
|
|
26
|
+
adds = inserts(SBAddress, [('London', ppl[0].id),
|
|
27
|
+
('Chicago', ppl[1].id),
|
|
28
|
+
('Abu Dhabi', ppl[1].id)],
|
|
29
|
+
'city personID')
|
|
30
|
+
ppl[0].addSharedAddress(adds[0])
|
|
31
|
+
ppl[0].addSharedAddress(adds[1])
|
|
32
|
+
ppl[1].addSharedAddress(adds[0])
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def testJoin():
|
|
36
|
+
assert list(SBPerson.select(
|
|
37
|
+
AND(SBPerson.q.id == SBAddress.q.personID,
|
|
38
|
+
SBAddress.q.city == 'London'))) == \
|
|
39
|
+
list(SBAddress.selectBy(city='London').throughTo.person)
|
|
40
|
+
|
|
41
|
+
assert list(SBAddress.select(
|
|
42
|
+
AND(SBPerson.q.id == SBAddress.q.personID,
|
|
43
|
+
SBPerson.q.name == 'Julia')).orderBy(SBAddress.q.city)) == \
|
|
44
|
+
list(SBPerson.selectBy(name='Julia').
|
|
45
|
+
throughTo.addresses.orderBy(SBAddress.q.city))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def testRelatedJoin():
|
|
49
|
+
assert list(SBPerson.selectBy(name='Julia').throughTo.sharedAddresses) == \
|
|
50
|
+
list(ppl[1].sharedAddresses)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def testInstance():
|
|
54
|
+
assert list(SBAddress.select(
|
|
55
|
+
AND(SBPerson.q.id == SBAddress.q.personID, SBPerson.q.id == ppl[0].id)
|
|
56
|
+
)) == list(ppl[0].addresses)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def testFK():
|
|
60
|
+
assert list(SBPerson.select(
|
|
61
|
+
AND(SBAddress.j.person, SBAddress.q.city == 'London'))) == \
|
|
62
|
+
list(SBPerson.select(
|
|
63
|
+
AND(SBPerson.q.id == SBAddress.q.personID,
|
|
64
|
+
SBAddress.q.city == 'London')))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def testRelatedJoin2():
|
|
68
|
+
assert list(SBAddress.select(
|
|
69
|
+
AND(SBAddress.j.sharedPeople, SBPerson.q.name == 'Julia'))) == \
|
|
70
|
+
list(SBPerson.select(
|
|
71
|
+
SBPerson.q.name == 'Julia').throughTo.sharedAddresses)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def testJoin2():
|
|
75
|
+
assert list(SBAddress.select(
|
|
76
|
+
AND(SBPerson.j.addresses,
|
|
77
|
+
SBPerson.q.name == 'Julia')).orderBy(SBAddress.q.city)) == \
|
|
78
|
+
list(SBAddress.select(
|
|
79
|
+
AND(SBPerson.q.id == SBAddress.q.personID,
|
|
80
|
+
SBPerson.q.name == 'Julia')).orderBy(SBAddress.q.city)) == \
|
|
81
|
+
list(SBPerson.selectBy(name='Julia').throughTo.
|
|
82
|
+
addresses.orderBy(SBAddress.q.city))
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def testFK2():
|
|
86
|
+
assert list(SBAddress.select(
|
|
87
|
+
AND(SBAddress.j.person, SBPerson.q.name == 'Julia'))) == \
|
|
88
|
+
list(SBAddress.select(
|
|
89
|
+
AND(SBPerson.q.id == SBAddress.q.personID,
|
|
90
|
+
SBPerson.q.name == 'Julia')))
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import threading
|
|
3
|
+
import pytest
|
|
4
|
+
from sqlobject import SQLObject, StringCol, FloatCol
|
|
5
|
+
from sqlobject.compat import string_type
|
|
6
|
+
from sqlobject.sqlbuilder import Select
|
|
7
|
+
from sqlobject.tests.dbtest import getConnection, setupClass, supports
|
|
8
|
+
from sqlobject.tests.dbtest import setSQLiteConnectionFactory
|
|
9
|
+
from .test_basic import SOTestSO1
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
connection = getConnection()
|
|
14
|
+
except (AttributeError, NameError):
|
|
15
|
+
# The module was imported during documentation building
|
|
16
|
+
pass
|
|
17
|
+
else:
|
|
18
|
+
if connection.dbName != "sqlite":
|
|
19
|
+
pytestmark = pytest.mark.skip("These tests require SQLite")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class SQLiteFactoryTest(SQLObject):
|
|
23
|
+
name = StringCol()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_sqlite_factory():
|
|
27
|
+
setupClass(SQLiteFactoryTest)
|
|
28
|
+
factory = [None]
|
|
29
|
+
|
|
30
|
+
def SQLiteConnectionFactory(sqlite):
|
|
31
|
+
class MyConnection(sqlite.Connection):
|
|
32
|
+
pass
|
|
33
|
+
factory[0] = MyConnection
|
|
34
|
+
return MyConnection
|
|
35
|
+
|
|
36
|
+
setSQLiteConnectionFactory(SQLiteFactoryTest, SQLiteConnectionFactory)
|
|
37
|
+
|
|
38
|
+
conn = SQLiteFactoryTest._connection.makeConnection()
|
|
39
|
+
assert factory[0]
|
|
40
|
+
assert isinstance(conn, factory[0])
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_sqlite_factory_str():
|
|
44
|
+
setupClass(SQLiteFactoryTest)
|
|
45
|
+
factory = [None]
|
|
46
|
+
|
|
47
|
+
def SQLiteConnectionFactory(sqlite):
|
|
48
|
+
class MyConnection(sqlite.Connection):
|
|
49
|
+
pass
|
|
50
|
+
factory[0] = MyConnection
|
|
51
|
+
return MyConnection
|
|
52
|
+
|
|
53
|
+
from sqlobject.sqlite import sqliteconnection
|
|
54
|
+
sqliteconnection.SQLiteConnectionFactory = SQLiteConnectionFactory
|
|
55
|
+
|
|
56
|
+
setSQLiteConnectionFactory(SQLiteFactoryTest, "SQLiteConnectionFactory")
|
|
57
|
+
|
|
58
|
+
conn = SQLiteFactoryTest._connection.makeConnection()
|
|
59
|
+
assert factory[0]
|
|
60
|
+
assert isinstance(conn, factory[0])
|
|
61
|
+
del sqliteconnection.SQLiteConnectionFactory
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_sqlite_aggregate():
|
|
65
|
+
setupClass(SQLiteFactoryTest)
|
|
66
|
+
|
|
67
|
+
def SQLiteConnectionFactory(sqlite):
|
|
68
|
+
class MyConnection(sqlite.Connection):
|
|
69
|
+
def __init__(self, *args, **kwargs):
|
|
70
|
+
super(MyConnection, self).__init__(*args, **kwargs)
|
|
71
|
+
self.create_aggregate("group_concat", 1, self.group_concat)
|
|
72
|
+
|
|
73
|
+
class group_concat:
|
|
74
|
+
def __init__(self):
|
|
75
|
+
self.acc = []
|
|
76
|
+
|
|
77
|
+
def step(self, value):
|
|
78
|
+
if isinstance(value, string_type):
|
|
79
|
+
self.acc.append(value)
|
|
80
|
+
else:
|
|
81
|
+
self.acc.append(str(value))
|
|
82
|
+
|
|
83
|
+
def finalize(self):
|
|
84
|
+
self.acc.sort()
|
|
85
|
+
return ", ".join(self.acc)
|
|
86
|
+
|
|
87
|
+
return MyConnection
|
|
88
|
+
|
|
89
|
+
setSQLiteConnectionFactory(SQLiteFactoryTest, SQLiteConnectionFactory)
|
|
90
|
+
|
|
91
|
+
SQLiteFactoryTest(name='sqlobject')
|
|
92
|
+
SQLiteFactoryTest(name='sqlbuilder')
|
|
93
|
+
assert SQLiteFactoryTest.select(orderBy="name").\
|
|
94
|
+
accumulateOne("group_concat", "name") == \
|
|
95
|
+
"sqlbuilder, sqlobject"
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def do_select():
|
|
99
|
+
list(SOTestSO1.select())
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def test_sqlite_threaded():
|
|
103
|
+
setupClass(SOTestSO1)
|
|
104
|
+
t = threading.Thread(target=do_select)
|
|
105
|
+
t.start()
|
|
106
|
+
t.join()
|
|
107
|
+
# This should reuse the same connection as the connection
|
|
108
|
+
# made above (at least will with most database drivers, but
|
|
109
|
+
# this will cause an error in SQLite):
|
|
110
|
+
do_select()
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def test_empty_string():
|
|
114
|
+
setupClass(SOTestSO1)
|
|
115
|
+
test = SOTestSO1(name=None, passwd='')
|
|
116
|
+
assert test.name is None
|
|
117
|
+
assert test.passwd == ''
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def test_memorydb():
|
|
121
|
+
if not supports("memorydb"):
|
|
122
|
+
pytest.skip("memorydb isn't supported")
|
|
123
|
+
if not connection._memory:
|
|
124
|
+
pytest.skip("The connection isn't memorydb")
|
|
125
|
+
setupClass(SOTestSO1)
|
|
126
|
+
connection.close() # create a new connection to an in-memory database
|
|
127
|
+
SOTestSO1.setConnection(connection)
|
|
128
|
+
SOTestSO1.createTable()
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def test_list_databases():
|
|
132
|
+
assert 'main' in connection.listDatabases()
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def test_list_tables():
|
|
136
|
+
setupClass(SOTestSO1)
|
|
137
|
+
assert SOTestSO1.sqlmeta.table in connection.listTables()
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class SQLiteTruedivTest(SQLObject):
|
|
141
|
+
value = FloatCol()
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def test_truediv():
|
|
145
|
+
setupClass(SQLiteTruedivTest)
|
|
146
|
+
|
|
147
|
+
if SQLiteTruedivTest._connection.dbName == "sqlite":
|
|
148
|
+
def SQLiteConnectionFactory(sqlite):
|
|
149
|
+
class MyConnection(sqlite.Connection):
|
|
150
|
+
def __init__(self, *args, **kwargs):
|
|
151
|
+
super(MyConnection, self).__init__(*args, **kwargs)
|
|
152
|
+
self.create_function("floor", 1, math.floor)
|
|
153
|
+
return MyConnection
|
|
154
|
+
|
|
155
|
+
setSQLiteConnectionFactory(SQLiteTruedivTest, SQLiteConnectionFactory)
|
|
156
|
+
|
|
157
|
+
SQLiteTruedivTest(value=-5.0)
|
|
158
|
+
assert SQLiteTruedivTest._connection.queryAll(
|
|
159
|
+
SQLiteTruedivTest._connection.sqlrepr(
|
|
160
|
+
Select(SQLiteTruedivTest.q.value // 4)))[0][0] == -2
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from sqlobject import MixedCaseStyle, SQLObject, sqlmeta
|
|
2
|
+
from sqlobject.tests.dbtest import setupClass
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class myid_sqlmeta(sqlmeta):
|
|
6
|
+
idName = "my_id"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SOTestSqlmeta1(SQLObject):
|
|
10
|
+
class sqlmeta(myid_sqlmeta):
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SOTestSqlmeta2(SQLObject):
|
|
15
|
+
class sqlmeta(sqlmeta):
|
|
16
|
+
style = MixedCaseStyle(longID=True)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class SOTestSqlmeta3(SQLObject):
|
|
20
|
+
class sqlmeta(myid_sqlmeta):
|
|
21
|
+
style = MixedCaseStyle(longID=True)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class SOTestSqlmeta4(SQLObject):
|
|
25
|
+
class sqlmeta(myid_sqlmeta):
|
|
26
|
+
idName = None
|
|
27
|
+
style = MixedCaseStyle(longID=True)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class longid_sqlmeta(sqlmeta):
|
|
31
|
+
idName = "my_id"
|
|
32
|
+
style = MixedCaseStyle(longID=True)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class SOTestSqlmeta5(SQLObject):
|
|
36
|
+
class sqlmeta(longid_sqlmeta):
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class SOTestSqlmeta6(SQLObject):
|
|
41
|
+
class sqlmeta(longid_sqlmeta):
|
|
42
|
+
idName = None
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_sqlmeta_inherited_idName():
|
|
46
|
+
setupClass([SOTestSqlmeta1, SOTestSqlmeta2])
|
|
47
|
+
assert SOTestSqlmeta1.sqlmeta.idName == "my_id"
|
|
48
|
+
assert SOTestSqlmeta2.sqlmeta.idName == "SOTestSqlmeta2ID"
|
|
49
|
+
assert SOTestSqlmeta3.sqlmeta.idName == "my_id"
|
|
50
|
+
assert SOTestSqlmeta4.sqlmeta.idName == "SOTestSqlmeta4ID"
|
|
51
|
+
assert SOTestSqlmeta5.sqlmeta.idName == "my_id"
|
|
52
|
+
assert SOTestSqlmeta6.sqlmeta.idName == "SOTestSqlmeta6ID"
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# These tests are not enabled yet, but here are some working examples
|
|
2
|
+
# of using createSQL so far.
|
|
3
|
+
|
|
4
|
+
from sqlobject import SQLObject, StringCol
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class SOTest1(SQLObject):
|
|
8
|
+
class sqlmeta:
|
|
9
|
+
createSQL = "CREATE SEQUENCE db_test1_seq;"
|
|
10
|
+
test1 = StringCol()
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class SOTest2(SQLObject):
|
|
14
|
+
class sqlmeta:
|
|
15
|
+
createSQL = ["CREATE SEQUENCE db_test2_seq;",
|
|
16
|
+
"ALTER TABLE test2 ADD CHECK(test2 != '');"]
|
|
17
|
+
test2 = StringCol()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SOTest3(SQLObject):
|
|
21
|
+
class sqlmeta:
|
|
22
|
+
createSQL = {'postgres': 'CREATE SEQUENCE db_test3_seq;',
|
|
23
|
+
'mysql': 'CREATE SEQUENCE db_test3_seq;'}
|
|
24
|
+
test3 = StringCol()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class SOTest4(SQLObject):
|
|
28
|
+
class sqlmeta:
|
|
29
|
+
createSQL = {'postgres': ['CREATE SEQUENCE db_test4_seq;',
|
|
30
|
+
"ALTER TABLE test4 ADD CHECK(test4 != '');"],
|
|
31
|
+
'mysql': 'CREATE SEQUENCE db_test4_seq;'}
|
|
32
|
+
test4 = StringCol()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class SOTest5(SQLObject):
|
|
36
|
+
class sqlmeta:
|
|
37
|
+
createSQL = {'mysql': 'CREATE SEQUENCE db_test5_seq;'}
|
|
38
|
+
test5 = StringCol()
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from sqlobject import SQLObject, StringCol, sqlmeta
|
|
2
|
+
from sqlobject.tests.dbtest import setupClass
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
########################################
|
|
6
|
+
# String ID test
|
|
7
|
+
########################################
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SOStringID(SQLObject):
|
|
11
|
+
|
|
12
|
+
class sqlmeta(sqlmeta):
|
|
13
|
+
table = 'so_string_id'
|
|
14
|
+
idType = str
|
|
15
|
+
val = StringCol(alternateID=True)
|
|
16
|
+
|
|
17
|
+
mysqlCreate = """
|
|
18
|
+
CREATE TABLE IF NOT EXISTS so_string_id (
|
|
19
|
+
id VARCHAR(50) PRIMARY KEY,
|
|
20
|
+
val TEXT
|
|
21
|
+
)
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
postgresCreate = """
|
|
25
|
+
CREATE TABLE so_string_id (
|
|
26
|
+
id VARCHAR(50) PRIMARY KEY,
|
|
27
|
+
val TEXT
|
|
28
|
+
)
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
sybaseCreate = """
|
|
32
|
+
CREATE TABLE so_string_id (
|
|
33
|
+
id VARCHAR(50) UNIQUE,
|
|
34
|
+
val VARCHAR(50) NULL
|
|
35
|
+
)
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
firebirdCreate = """
|
|
39
|
+
CREATE TABLE so_string_id (
|
|
40
|
+
id VARCHAR(50) NOT NULL PRIMARY KEY,
|
|
41
|
+
val BLOB SUB_TYPE TEXT
|
|
42
|
+
)
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
mssqlCreate = """
|
|
46
|
+
CREATE TABLE so_string_id (
|
|
47
|
+
id VARCHAR(50) PRIMARY KEY,
|
|
48
|
+
val varchar(4000)
|
|
49
|
+
)
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
sqliteCreate = postgresCreate
|
|
53
|
+
|
|
54
|
+
mysqlDrop = """
|
|
55
|
+
DROP TABLE IF EXISTS so_string_id
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
postgresDrop = """
|
|
59
|
+
DROP TABLE so_string_id
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
sqliteDrop = postgresDrop
|
|
63
|
+
firebirdDrop = postgresDrop
|
|
64
|
+
mssqlDrop = postgresDrop
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_stringID():
|
|
68
|
+
setupClass(SOStringID)
|
|
69
|
+
t1 = SOStringID(id='hey', val='whatever')
|
|
70
|
+
t2 = SOStringID.byVal('whatever')
|
|
71
|
+
assert t1 == t2
|
|
72
|
+
assert t1.val == t2.val
|
|
73
|
+
assert t1.val == 'whatever'
|
|
74
|
+
|
|
75
|
+
t1 = SOStringID(id='you', val='nowhere')
|
|
76
|
+
t2 = SOStringID.get('you')
|
|
77
|
+
assert t1 == t2
|
|
78
|
+
assert t1.val == t2.val
|
|
79
|
+
assert t1.val == 'nowhere'
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from sqlobject import ForeignKey, SQLObject, StringCol, sqlmeta, styles
|
|
2
|
+
from sqlobject.tests.dbtest import setupClass
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class AnotherStyle(styles.MixedCaseUnderscoreStyle):
|
|
6
|
+
def pythonAttrToDBColumn(self, attr):
|
|
7
|
+
if attr.lower().endswith('id'):
|
|
8
|
+
return 'id' + styles.MixedCaseUnderscoreStyle.\
|
|
9
|
+
pythonAttrToDBColumn(self, attr[:-2])
|
|
10
|
+
else:
|
|
11
|
+
return styles.MixedCaseUnderscoreStyle.\
|
|
12
|
+
pythonAttrToDBColumn(self, attr)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class SOStyleTest1(SQLObject):
|
|
16
|
+
a = StringCol()
|
|
17
|
+
st2 = ForeignKey('SOStyleTest2')
|
|
18
|
+
|
|
19
|
+
class sqlmeta(sqlmeta):
|
|
20
|
+
style = AnotherStyle()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class SOStyleTest2(SQLObject):
|
|
24
|
+
b = StringCol()
|
|
25
|
+
|
|
26
|
+
class sqlmeta(sqlmeta):
|
|
27
|
+
style = AnotherStyle()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_style():
|
|
31
|
+
setupClass([SOStyleTest2, SOStyleTest1])
|
|
32
|
+
st1 = SOStyleTest1(a='something', st2=None)
|
|
33
|
+
st2 = SOStyleTest2(b='whatever')
|
|
34
|
+
st1.st2 = st2
|
|
35
|
+
assert st1.sqlmeta.columns['st2ID'].dbName == 'idst2'
|
|
36
|
+
assert st1.st2 == st2
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
from sqlobject import ForeignKey, SQLObject, StringCol
|
|
2
|
+
from sqlobject.sqlbuilder import EXISTS, IN, LEFTOUTERJOINOn, NOTEXISTS, \
|
|
3
|
+
Outer, Select
|
|
4
|
+
from sqlobject.tests.dbtest import setupClass
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
########################################
|
|
8
|
+
# Subqueries (subselects)
|
|
9
|
+
########################################
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SOTestIn1(SQLObject):
|
|
13
|
+
col1 = StringCol()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class SOTestIn2(SQLObject):
|
|
17
|
+
col2 = StringCol()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SOTestOuter(SQLObject):
|
|
21
|
+
fk = ForeignKey('SOTestIn1')
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def setup():
|
|
25
|
+
setupClass(SOTestIn1)
|
|
26
|
+
setupClass(SOTestIn2)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def insert():
|
|
30
|
+
setup()
|
|
31
|
+
SOTestIn1(col1=None)
|
|
32
|
+
SOTestIn1(col1='')
|
|
33
|
+
SOTestIn1(col1="test")
|
|
34
|
+
SOTestIn2(col2=None)
|
|
35
|
+
SOTestIn2(col2='')
|
|
36
|
+
SOTestIn2(col2="test")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_1syntax_in():
|
|
40
|
+
setup()
|
|
41
|
+
select = SOTestIn1.select(IN(SOTestIn1.q.col1, Select(SOTestIn2.q.col2)))
|
|
42
|
+
assert str(select) == \
|
|
43
|
+
"SELECT so_test_in1.id, so_test_in1.col1 " \
|
|
44
|
+
"FROM so_test_in1 WHERE so_test_in1.col1 IN " \
|
|
45
|
+
"(SELECT so_test_in2.col2 FROM so_test_in2)"
|
|
46
|
+
|
|
47
|
+
select = SOTestIn1.select(IN(SOTestIn1.q.col1, SOTestIn2.select()))
|
|
48
|
+
assert str(select) == \
|
|
49
|
+
"SELECT so_test_in1.id, so_test_in1.col1 " \
|
|
50
|
+
"FROM so_test_in1 WHERE so_test_in1.col1 IN " \
|
|
51
|
+
"(SELECT so_test_in2.id FROM so_test_in2 WHERE 1 = 1)"
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_2perform_in():
|
|
55
|
+
insert()
|
|
56
|
+
select = SOTestIn1.select(IN(SOTestIn1.q.col1, Select(SOTestIn2.q.col2)))
|
|
57
|
+
assert select.count() == 2
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_3syntax_exists():
|
|
61
|
+
setup()
|
|
62
|
+
select = SOTestIn1.select(NOTEXISTS(
|
|
63
|
+
Select(SOTestIn2.q.col2,
|
|
64
|
+
where=(Outer(SOTestIn1).q.col1 == SOTestIn2.q.col2))))
|
|
65
|
+
assert str(select) == \
|
|
66
|
+
"SELECT so_test_in1.id, so_test_in1.col1 " \
|
|
67
|
+
"FROM so_test_in1 WHERE NOT EXISTS " \
|
|
68
|
+
"(SELECT so_test_in2.col2 FROM so_test_in2 " \
|
|
69
|
+
"WHERE ((so_test_in1.col1) = (so_test_in2.col2)))"
|
|
70
|
+
|
|
71
|
+
setupClass(SOTestOuter)
|
|
72
|
+
select = SOTestOuter.select(NOTEXISTS(
|
|
73
|
+
Select(SOTestIn1.q.col1,
|
|
74
|
+
where=(Outer(SOTestOuter).q.fk == SOTestIn1.q.id))))
|
|
75
|
+
assert str(select) == \
|
|
76
|
+
"SELECT so_test_outer.id, so_test_outer.fk_id " \
|
|
77
|
+
"FROM so_test_outer WHERE NOT EXISTS " \
|
|
78
|
+
"(SELECT so_test_in1.col1 FROM so_test_in1 " \
|
|
79
|
+
"WHERE ((so_test_outer.fk_id) = (so_test_in1.id)))"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_4perform_exists():
|
|
83
|
+
insert()
|
|
84
|
+
select = SOTestIn1.select(EXISTS(
|
|
85
|
+
Select(SOTestIn2.q.col2,
|
|
86
|
+
where=(Outer(SOTestIn1).q.col1 == SOTestIn2.q.col2))))
|
|
87
|
+
assert len(list(select)) == 2
|
|
88
|
+
|
|
89
|
+
setupClass(SOTestOuter)
|
|
90
|
+
select = SOTestOuter.select(NOTEXISTS(
|
|
91
|
+
Select(SOTestIn1.q.col1,
|
|
92
|
+
where=(Outer(SOTestOuter).q.fkID == SOTestIn1.q.id))))
|
|
93
|
+
assert len(list(select)) == 0
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_4syntax_direct():
|
|
97
|
+
setup()
|
|
98
|
+
select = SOTestIn1.select(SOTestIn1.q.col1 == Select(SOTestIn2.q.col2,
|
|
99
|
+
where=(SOTestIn2.q.col2 == "test")))
|
|
100
|
+
assert str(select) == \
|
|
101
|
+
"SELECT so_test_in1.id, so_test_in1.col1 " \
|
|
102
|
+
"FROM so_test_in1 WHERE ((so_test_in1.col1) = " \
|
|
103
|
+
"(SELECT so_test_in2.col2 FROM so_test_in2 " \
|
|
104
|
+
"WHERE ((so_test_in2.col2) = ('test'))))"
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def test_4perform_direct():
|
|
108
|
+
insert()
|
|
109
|
+
select = SOTestIn1.select(SOTestIn1.q.col1 == Select(SOTestIn2.q.col2,
|
|
110
|
+
where=(SOTestIn2.q.col2 == "test")))
|
|
111
|
+
assert select.count() == 1
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_5perform_direct():
|
|
115
|
+
insert()
|
|
116
|
+
select = SOTestIn1.select(SOTestIn1.q.col1 == Select(SOTestIn2.q.col2,
|
|
117
|
+
where=(SOTestIn2.q.col2 == "test")))
|
|
118
|
+
assert select.count() == 1
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def test_6syntax_join():
|
|
122
|
+
insert()
|
|
123
|
+
j = LEFTOUTERJOINOn(SOTestIn2, SOTestIn1,
|
|
124
|
+
SOTestIn1.q.col1 == SOTestIn2.q.col2)
|
|
125
|
+
select = SOTestIn1.select(SOTestIn1.q.col1 == Select(SOTestIn2.q.col2,
|
|
126
|
+
where=(SOTestIn2.q.col2 == "test"), join=j))
|
|
127
|
+
assert str(select) == \
|
|
128
|
+
"SELECT so_test_in1.id, so_test_in1.col1 " \
|
|
129
|
+
"FROM so_test_in1 WHERE ((so_test_in1.col1) = " \
|
|
130
|
+
"(SELECT so_test_in2.col2 FROM so_test_in2 " \
|
|
131
|
+
"LEFT OUTER JOIN so_test_in1 ON " \
|
|
132
|
+
"((so_test_in1.col1) = (so_test_in2.col2)) " \
|
|
133
|
+
"WHERE ((so_test_in2.col2) = ('test'))))"
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def test_6perform_join():
|
|
137
|
+
insert()
|
|
138
|
+
j = LEFTOUTERJOINOn(SOTestIn2, SOTestIn1,
|
|
139
|
+
SOTestIn1.q.col1 == SOTestIn2.q.col2)
|
|
140
|
+
select = SOTestIn1.select(SOTestIn1.q.col1 == Select(SOTestIn2.q.col2,
|
|
141
|
+
where=(SOTestIn2.q.col2 == "test"), join=j))
|
|
142
|
+
assert select.count() == 1
|