Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
3580b033
Kaydet (Commit)
3580b033
authored
Eyl 06, 2016
tarafından
Berker Peksag
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #21250: Merge from 3.5
üst
2784c5bb
4bf580d6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
1 deletion
+100
-1
dbapi.py
Lib/sqlite3/test/dbapi.py
+100
-1
No files found.
Lib/sqlite3/test/dbapi.py
Dosyayı görüntüle @
3580b033
...
...
@@ -820,6 +820,100 @@ class ClosedCurTests(unittest.TestCase):
method
=
getattr
(
cur
,
method_name
)
method
(
*
params
)
class
SqliteOnConflictTests
(
unittest
.
TestCase
):
"""
Tests for SQLite's "insert on conflict" feature.
See https://www.sqlite.org/lang_conflict.html for details.
"""
def
setUp
(
self
):
self
.
cx
=
sqlite
.
connect
(
":memory:"
)
self
.
cu
=
self
.
cx
.
cursor
()
self
.
cu
.
execute
(
"""
CREATE TABLE test(
id INTEGER PRIMARY KEY, name TEXT, unique_name TEXT UNIQUE
);
"""
)
def
tearDown
(
self
):
self
.
cu
.
close
()
self
.
cx
.
close
()
def
CheckOnConflictRollbackWithExplicitTransaction
(
self
):
self
.
cx
.
isolation_level
=
None
# autocommit mode
self
.
cu
=
self
.
cx
.
cursor
()
# Start an explicit transaction.
self
.
cu
.
execute
(
"BEGIN"
)
self
.
cu
.
execute
(
"INSERT INTO test(name) VALUES ('abort_test')"
)
self
.
cu
.
execute
(
"INSERT OR ROLLBACK INTO test(unique_name) VALUES ('foo')"
)
with
self
.
assertRaises
(
sqlite
.
IntegrityError
):
self
.
cu
.
execute
(
"INSERT OR ROLLBACK INTO test(unique_name) VALUES ('foo')"
)
# Use connection to commit.
self
.
cx
.
commit
()
self
.
cu
.
execute
(
"SELECT name, unique_name from test"
)
# Transaction should have rolled back and nothing should be in table.
self
.
assertEqual
(
self
.
cu
.
fetchall
(),
[])
def
CheckOnConflictAbortRaisesWithExplicitTransactions
(
self
):
# Abort cancels the current sql statement but doesn't change anything
# about the current transaction.
self
.
cx
.
isolation_level
=
None
# autocommit mode
self
.
cu
=
self
.
cx
.
cursor
()
# Start an explicit transaction.
self
.
cu
.
execute
(
"BEGIN"
)
self
.
cu
.
execute
(
"INSERT INTO test(name) VALUES ('abort_test')"
)
self
.
cu
.
execute
(
"INSERT OR ABORT INTO test(unique_name) VALUES ('foo')"
)
with
self
.
assertRaises
(
sqlite
.
IntegrityError
):
self
.
cu
.
execute
(
"INSERT OR ABORT INTO test(unique_name) VALUES ('foo')"
)
self
.
cx
.
commit
()
self
.
cu
.
execute
(
"SELECT name, unique_name FROM test"
)
# Expect the first two inserts to work, third to do nothing.
self
.
assertEqual
(
self
.
cu
.
fetchall
(),
[(
'abort_test'
,
None
),
(
None
,
'foo'
,)])
def
CheckOnConflictRollbackWithoutTransaction
(
self
):
# Start of implicit transaction
self
.
cu
.
execute
(
"INSERT INTO test(name) VALUES ('abort_test')"
)
self
.
cu
.
execute
(
"INSERT OR ROLLBACK INTO test(unique_name) VALUES ('foo')"
)
with
self
.
assertRaises
(
sqlite
.
IntegrityError
):
self
.
cu
.
execute
(
"INSERT OR ROLLBACK INTO test(unique_name) VALUES ('foo')"
)
self
.
cu
.
execute
(
"SELECT name, unique_name FROM test"
)
# Implicit transaction is rolled back on error.
self
.
assertEqual
(
self
.
cu
.
fetchall
(),
[])
def
CheckOnConflictAbortRaisesWithoutTransactions
(
self
):
# Abort cancels the current sql statement but doesn't change anything
# about the current transaction.
self
.
cu
.
execute
(
"INSERT INTO test(name) VALUES ('abort_test')"
)
self
.
cu
.
execute
(
"INSERT OR ABORT INTO test(unique_name) VALUES ('foo')"
)
with
self
.
assertRaises
(
sqlite
.
IntegrityError
):
self
.
cu
.
execute
(
"INSERT OR ABORT INTO test(unique_name) VALUES ('foo')"
)
# Make sure all other values were inserted.
self
.
cu
.
execute
(
"SELECT name, unique_name FROM test"
)
self
.
assertEqual
(
self
.
cu
.
fetchall
(),
[(
'abort_test'
,
None
),
(
None
,
'foo'
,)])
def
CheckOnConflictFail
(
self
):
self
.
cu
.
execute
(
"INSERT OR FAIL INTO test(unique_name) VALUES ('foo')"
)
with
self
.
assertRaises
(
sqlite
.
IntegrityError
):
self
.
cu
.
execute
(
"INSERT OR FAIL INTO test(unique_name) VALUES ('foo')"
)
self
.
assertEqual
(
self
.
cu
.
fetchall
(),
[])
def
CheckOnConflictIgnore
(
self
):
self
.
cu
.
execute
(
"INSERT OR IGNORE INTO test(unique_name) VALUES ('foo')"
)
# Nothing should happen.
self
.
cu
.
execute
(
"INSERT OR IGNORE INTO test(unique_name) VALUES ('foo')"
)
self
.
cu
.
execute
(
"SELECT unique_name FROM test"
)
self
.
assertEqual
(
self
.
cu
.
fetchall
(),
[(
'foo'
,)])
def
CheckOnConflictReplace
(
self
):
self
.
cu
.
execute
(
"INSERT OR REPLACE INTO test(name, unique_name) VALUES ('Data!', 'foo')"
)
# There shouldn't be an IntegrityError exception.
self
.
cu
.
execute
(
"INSERT OR REPLACE INTO test(name, unique_name) VALUES ('Very different data!', 'foo')"
)
self
.
cu
.
execute
(
"SELECT name, unique_name FROM test"
)
self
.
assertEqual
(
self
.
cu
.
fetchall
(),
[(
'Very different data!'
,
'foo'
)])
def
suite
():
module_suite
=
unittest
.
makeSuite
(
ModuleTests
,
"Check"
)
connection_suite
=
unittest
.
makeSuite
(
ConnectionTests
,
"Check"
)
...
...
@@ -829,7 +923,12 @@ def suite():
ext_suite
=
unittest
.
makeSuite
(
ExtensionTests
,
"Check"
)
closed_con_suite
=
unittest
.
makeSuite
(
ClosedConTests
,
"Check"
)
closed_cur_suite
=
unittest
.
makeSuite
(
ClosedCurTests
,
"Check"
)
return
unittest
.
TestSuite
((
module_suite
,
connection_suite
,
cursor_suite
,
thread_suite
,
constructor_suite
,
ext_suite
,
closed_con_suite
,
closed_cur_suite
))
on_conflict_suite
=
unittest
.
makeSuite
(
SqliteOnConflictTests
,
"Check"
)
return
unittest
.
TestSuite
((
module_suite
,
connection_suite
,
cursor_suite
,
thread_suite
,
constructor_suite
,
ext_suite
,
closed_con_suite
,
closed_cur_suite
,
on_conflict_suite
,
))
def
test
():
runner
=
unittest
.
TextTestRunner
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment