Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
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
django
Commits
30f8642f
Kaydet (Commit)
30f8642f
authored
Nis 28, 2018
tarafından
Zackary Troop
Kaydeden (comit)
Claude Paroz
Nis 28, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29350 -- Fix get_primary_key_column() method in sqlite3 backend
Thanks Tim Graham and Mariusz Felisiak for the reviews.
üst
6b3d2920
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
introspection.py
django/db/backends/sqlite3/introspection.py
+2
-2
test_introspection.py
tests/backends/sqlite/test_introspection.py
+27
-0
No files found.
django/db/backends/sqlite3/introspection.py
Dosyayı görüntüle @
30f8642f
...
@@ -192,9 +192,9 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
...
@@ -192,9 +192,9 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
fields_sql
=
create_sql
[
create_sql
.
index
(
'('
)
+
1
:
create_sql
.
rindex
(
')'
)]
fields_sql
=
create_sql
[
create_sql
.
index
(
'('
)
+
1
:
create_sql
.
rindex
(
')'
)]
for
field_desc
in
fields_sql
.
split
(
','
):
for
field_desc
in
fields_sql
.
split
(
','
):
field_desc
=
field_desc
.
strip
()
field_desc
=
field_desc
.
strip
()
m
=
re
.
search
(
'"(.*)".*PRIMARY KEY( AUTOINCREMENT)?
'
,
field_desc
)
m
=
re
.
match
(
'(?:(?:["`
\
[])(.*)(?:["`
\
]])|(
\
w+)).*PRIMARY KEY.*
'
,
field_desc
)
if
m
:
if
m
:
return
m
.
group
s
()[
0
]
return
m
.
group
(
1
)
if
m
.
group
(
1
)
else
m
.
group
(
2
)
return
None
return
None
def
_table_info
(
self
,
cursor
,
name
):
def
_table_info
(
self
,
cursor
,
name
):
...
...
tests/backends/sqlite/test_introspection.py
0 → 100644
Dosyayı görüntüle @
30f8642f
import
unittest
from
django.db
import
connection
from
django.test
import
TestCase
@unittest.skipUnless
(
connection
.
vendor
==
'sqlite'
,
'SQLite tests'
)
class
IntrospectionTests
(
TestCase
):
def
test_get_primary_key_column
(
self
):
"""
Get the primary key column regardless of whether or not it has
quotation.
"""
testable_column_strings
=
(
(
'id'
,
'id'
),
(
'[id]'
,
'id'
),
(
'`id`'
,
'id'
),
(
'"id"'
,
'id'
),
(
'[id col]'
,
'id col'
),
(
'`id col`'
,
'id col'
),
(
'"id col"'
,
'id col'
)
)
with
connection
.
cursor
()
as
cursor
:
for
column
,
expected_string
in
testable_column_strings
:
sql
=
'CREATE TABLE test_primary (
%
s int PRIMARY KEY NOT NULL)'
%
column
with
self
.
subTest
(
column
=
column
):
try
:
cursor
.
execute
(
sql
)
field
=
connection
.
introspection
.
get_primary_key_column
(
cursor
,
'test_primary'
)
self
.
assertEqual
(
field
,
expected_string
)
finally
:
cursor
.
execute
(
'DROP TABLE test_primary'
)
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