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
af0628e0
Kaydet (Commit)
af0628e0
authored
Eyl 01, 2016
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #27881: Fixed possible bugs when setting sqlite3.Connection.isolation_level.
Based on patch by Xiang Zhang.
üst
5c071c1f
2891492d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
46 deletions
+65
-46
regression.py
Lib/sqlite3/test/regression.py
+27
-4
NEWS
Misc/NEWS
+3
-0
connection.c
Modules/_sqlite/connection.c
+33
-39
connection.h
Modules/_sqlite/connection.h
+2
-3
No files found.
Lib/sqlite3/test/regression.py
Dosyayı görüntüle @
af0628e0
...
@@ -146,11 +146,34 @@ class RegressionTests(unittest.TestCase):
...
@@ -146,11 +146,34 @@ class RegressionTests(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
sqlite
.
register_adapter
,
{},
None
)
self
.
assertRaises
(
TypeError
,
sqlite
.
register_adapter
,
{},
None
)
def
CheckSetIsolationLevel
(
self
):
def
CheckSetIsolationLevel
(
self
):
"""
# See issue 27881.
See issue 3312.
class
CustomStr
(
str
):
"""
def
upper
(
self
):
return
None
def
__del__
(
self
):
con
.
isolation_level
=
""
con
=
sqlite
.
connect
(
":memory:"
)
con
=
sqlite
.
connect
(
":memory:"
)
setattr
(
con
,
"isolation_level"
,
"
\xe9
"
)
con
.
isolation_level
=
None
for
level
in
""
,
"DEFERRED"
,
"IMMEDIATE"
,
"EXCLUSIVE"
:
with
self
.
subTest
(
level
=
level
):
con
.
isolation_level
=
level
con
.
isolation_level
=
level
.
lower
()
con
.
isolation_level
=
level
.
capitalize
()
con
.
isolation_level
=
CustomStr
(
level
)
# setting isolation_level failure should not alter previous state
con
.
isolation_level
=
None
con
.
isolation_level
=
"DEFERRED"
pairs
=
[
(
1
,
TypeError
),
(
b
''
,
TypeError
),
(
"abc"
,
ValueError
),
(
"IMMEDIATE
\0
EXCLUSIVE"
,
ValueError
),
(
"
\xe9
"
,
ValueError
),
]
for
value
,
exc
in
pairs
:
with
self
.
subTest
(
level
=
value
):
with
self
.
assertRaises
(
exc
):
con
.
isolation_level
=
value
self
.
assertEqual
(
con
.
isolation_level
,
"DEFERRED"
)
def
CheckCursorConstructorCallCheck
(
self
):
def
CheckCursorConstructorCallCheck
(
self
):
"""
"""
...
...
Misc/NEWS
Dosyayı görüntüle @
af0628e0
...
@@ -70,6 +70,9 @@ Library
...
@@ -70,6 +70,9 @@ Library
- Issue #27842: The csv.DictReader now returns rows of type OrderedDict.
- Issue #27842: The csv.DictReader now returns rows of type OrderedDict.
(Contributed by Steve Holden.)
(Contributed by Steve Holden.)
- Issue #27881: Fixed possible bugs when setting sqlite3.Connection.isolation_level.
Based on patch by Xiang Zhang.
- Issue #27861: Fixed a crash in sqlite3.Connection.cursor() when a factory
- Issue #27861: Fixed a crash in sqlite3.Connection.cursor() when a factory
creates not a cursor. Patch by Xiang Zhang.
creates not a cursor. Patch by Xiang Zhang.
...
...
Modules/_sqlite/connection.c
Dosyayı görüntüle @
af0628e0
...
@@ -43,6 +43,14 @@
...
@@ -43,6 +43,14 @@
_Py_IDENTIFIER
(
cursor
);
_Py_IDENTIFIER
(
cursor
);
static
const
char
*
const
begin_statements
[]
=
{
"BEGIN "
,
"BEGIN DEFERRED"
,
"BEGIN IMMEDIATE"
,
"BEGIN EXCLUSIVE"
,
NULL
};
static
int
pysqlite_connection_set_isolation_level
(
pysqlite_Connection
*
self
,
PyObject
*
isolation_level
);
static
int
pysqlite_connection_set_isolation_level
(
pysqlite_Connection
*
self
,
PyObject
*
isolation_level
);
static
void
_pysqlite_drop_unused_cursor_references
(
pysqlite_Connection
*
self
);
static
void
_pysqlite_drop_unused_cursor_references
(
pysqlite_Connection
*
self
);
...
@@ -258,9 +266,6 @@ void pysqlite_connection_dealloc(pysqlite_Connection* self)
...
@@ -258,9 +266,6 @@ void pysqlite_connection_dealloc(pysqlite_Connection* self)
Py_END_ALLOW_THREADS
Py_END_ALLOW_THREADS
}
}
if
(
self
->
begin_statement
)
{
PyMem_Free
(
self
->
begin_statement
);
}
Py_XDECREF
(
self
->
isolation_level
);
Py_XDECREF
(
self
->
isolation_level
);
Py_XDECREF
(
self
->
function_pinboard
);
Py_XDECREF
(
self
->
function_pinboard
);
Py_XDECREF
(
self
->
row_factory
);
Py_XDECREF
(
self
->
row_factory
);
...
@@ -1175,59 +1180,48 @@ static PyObject* pysqlite_connection_get_total_changes(pysqlite_Connection* self
...
@@ -1175,59 +1180,48 @@ static PyObject* pysqlite_connection_get_total_changes(pysqlite_Connection* self
static
int
pysqlite_connection_set_isolation_level
(
pysqlite_Connection
*
self
,
PyObject
*
isolation_level
)
static
int
pysqlite_connection_set_isolation_level
(
pysqlite_Connection
*
self
,
PyObject
*
isolation_level
)
{
{
PyObject
*
res
;
PyObject
*
begin_statement
;
static
PyObject
*
begin_word
;
Py_XDECREF
(
self
->
isolation_level
);
if
(
self
->
begin_statement
)
{
PyMem_Free
(
self
->
begin_statement
);
self
->
begin_statement
=
NULL
;
}
if
(
isolation_level
==
Py_None
)
{
if
(
isolation_level
==
Py_None
)
{
Py_INCREF
(
Py_None
);
PyObject
*
res
=
pysqlite_connection_commit
(
self
,
NULL
);
self
->
isolation_level
=
Py_None
;
res
=
pysqlite_connection_commit
(
self
,
NULL
);
if
(
!
res
)
{
if
(
!
res
)
{
return
-
1
;
return
-
1
;
}
}
Py_DECREF
(
res
);
Py_DECREF
(
res
);
self
->
begin_statement
=
NULL
;
self
->
inTransaction
=
0
;
self
->
inTransaction
=
0
;
}
else
{
}
else
{
const
char
*
statement
;
const
char
*
const
*
candidate
;
Py_ssize_t
size
;
PyObject
*
uppercase_level
;
_Py_IDENTIFIER
(
upper
);
Py_INCREF
(
isolation_level
);
self
->
isolation_level
=
isolation_level
;
if
(
!
PyUnicode_Check
(
isolation_level
))
{
PyErr_Format
(
PyExc_TypeError
,
if
(
!
begin_word
)
{
"isolation_level must be a string or None, not %.100s"
,
begin_word
=
PyUnicode_FromString
(
"BEGIN "
);
Py_TYPE
(
isolation_level
)
->
tp_name
);
if
(
!
begin_word
)
return
-
1
;
}
begin_statement
=
PyUnicode_Concat
(
begin_word
,
isolation_level
);
if
(
!
begin_statement
)
{
return
-
1
;
return
-
1
;
}
}
statement
=
_PyUnicode_AsStringAndSize
(
begin_statement
,
&
size
);
uppercase_level
=
_PyObject_CallMethodIdObjArgs
(
if
(
!
statement
)
{
(
PyObject
*
)
&
PyUnicode_Type
,
&
PyId_upper
,
Py_DECREF
(
begin_statement
);
isolation_level
,
NULL
);
if
(
!
uppercase_level
)
{
return
-
1
;
return
-
1
;
}
}
self
->
begin_statement
=
PyMem_Malloc
(
size
+
2
);
for
(
candidate
=
begin_statements
;
*
candidate
;
candidate
++
)
{
if
(
!
self
->
begin_statement
)
{
if
(
!
PyUnicode_CompareWithASCIIString
(
uppercase_level
,
*
candidate
+
6
))
Py_DECREF
(
begin_statement
);
break
;
}
Py_DECREF
(
uppercase_level
);
if
(
!*
candidate
)
{
PyErr_SetString
(
PyExc_ValueError
,
"invalid value for isolation_level"
);
return
-
1
;
return
-
1
;
}
}
self
->
begin_statement
=
*
candidate
;
strcpy
(
self
->
begin_statement
,
statement
);
Py_DECREF
(
begin_statement
);
}
}
Py_INCREF
(
isolation_level
);
Py_XSETREF
(
self
->
isolation_level
,
isolation_level
);
return
0
;
return
0
;
}
}
...
...
Modules/_sqlite/connection.h
Dosyayı görüntüle @
af0628e0
...
@@ -55,9 +55,8 @@ typedef struct
...
@@ -55,9 +55,8 @@ typedef struct
/* None for autocommit, otherwise a PyUnicode with the isolation level */
/* None for autocommit, otherwise a PyUnicode with the isolation level */
PyObject
*
isolation_level
;
PyObject
*
isolation_level
;
/* NULL for autocommit, otherwise a string with the BEGIN statement; will be
/* NULL for autocommit, otherwise a string with the BEGIN statement */
* freed in connection destructor */
const
char
*
begin_statement
;
char
*
begin_statement
;
/* 1 if a check should be performed for each API call if the connection is
/* 1 if a check should be performed for each API call if the connection is
* used from the same thread it was created in */
* used from the same thread it was created in */
...
...
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