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
4492be34
Kaydet (Commit)
4492be34
authored
Şub 27, 2019
tarafından
Paveł Tyślacki
Kaydeden (comit)
Tim Graham
Mar 01, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #30183 -- Moved SQLite table constraint parsing to a method.
üst
b777c067
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
42 deletions
+48
-42
introspection.py
django/db/backends/sqlite3/introspection.py
+48
-42
No files found.
django/db/backends/sqlite3/introspection.py
Dosyayı görüntüle @
4492be34
...
...
@@ -217,6 +217,52 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
}
return
constraints
def
_parse_table_constraints
(
self
,
sql
):
# Check constraint parsing is based of SQLite syntax diagram.
# https://www.sqlite.org/syntaxdiagrams.html#table-constraint
def
next_ttype
(
ttype
):
for
token
in
tokens
:
if
token
.
ttype
==
ttype
:
return
token
statement
=
sqlparse
.
parse
(
sql
)[
0
]
constraints
=
{}
tokens
=
statement
.
flatten
()
for
token
in
tokens
:
name
=
None
if
token
.
match
(
sqlparse
.
tokens
.
Keyword
,
'CONSTRAINT'
):
# Table constraint
name_token
=
next_ttype
(
sqlparse
.
tokens
.
Literal
.
String
.
Symbol
)
name
=
name_token
.
value
[
1
:
-
1
]
token
=
next_ttype
(
sqlparse
.
tokens
.
Keyword
)
if
token
.
match
(
sqlparse
.
tokens
.
Keyword
,
'UNIQUE'
):
constraints
[
name
]
=
{
'unique'
:
True
,
'columns'
:
[],
'primary_key'
:
False
,
'foreign_key'
:
None
,
'check'
:
False
,
'index'
:
False
,
}
if
token
.
match
(
sqlparse
.
tokens
.
Keyword
,
'CHECK'
):
# Column check constraint
if
name
is
None
:
column_token
=
next_ttype
(
sqlparse
.
tokens
.
Literal
.
String
.
Symbol
)
column
=
column_token
.
value
[
1
:
-
1
]
name
=
'__check__
%
s'
%
column
columns
=
[
column
]
else
:
columns
=
[]
constraints
[
name
]
=
{
'check'
:
True
,
'columns'
:
columns
,
'primary_key'
:
False
,
'unique'
:
False
,
'foreign_key'
:
None
,
'index'
:
False
,
}
return
constraints
def
get_constraints
(
self
,
cursor
,
table_name
):
"""
Retrieve any constraints or keys (unique, pk, fk, check, index) across
...
...
@@ -234,48 +280,8 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
# table_name is a view.
pass
else
:
# Check constraint parsing is based of SQLite syntax diagram.
# https://www.sqlite.org/syntaxdiagrams.html#table-constraint
def
next_ttype
(
ttype
):
for
token
in
tokens
:
if
token
.
ttype
==
ttype
:
return
token
statement
=
sqlparse
.
parse
(
table_schema
)[
0
]
tokens
=
statement
.
flatten
()
for
token
in
tokens
:
name
=
None
if
token
.
match
(
sqlparse
.
tokens
.
Keyword
,
'CONSTRAINT'
):
# Table constraint
name_token
=
next_ttype
(
sqlparse
.
tokens
.
Literal
.
String
.
Symbol
)
name
=
name_token
.
value
[
1
:
-
1
]
token
=
next_ttype
(
sqlparse
.
tokens
.
Keyword
)
if
token
.
match
(
sqlparse
.
tokens
.
Keyword
,
'UNIQUE'
):
constraints
[
name
]
=
{
'unique'
:
True
,
'columns'
:
[],
'primary_key'
:
False
,
'foreign_key'
:
None
,
'check'
:
False
,
'index'
:
False
,
}
if
token
.
match
(
sqlparse
.
tokens
.
Keyword
,
'CHECK'
):
# Column check constraint
if
name
is
None
:
column_token
=
next_ttype
(
sqlparse
.
tokens
.
Literal
.
String
.
Symbol
)
column
=
column_token
.
value
[
1
:
-
1
]
name
=
'__check__
%
s'
%
column
columns
=
[
column
]
else
:
columns
=
[]
constraints
[
name
]
=
{
'check'
:
True
,
'columns'
:
columns
,
'primary_key'
:
False
,
'unique'
:
False
,
'foreign_key'
:
None
,
'index'
:
False
,
}
constraints
.
update
(
self
.
_parse_table_constraints
(
table_schema
))
# Get the index info
cursor
.
execute
(
"PRAGMA index_list(
%
s)"
%
self
.
connection
.
ops
.
quote_name
(
table_name
))
for
row
in
cursor
.
fetchall
():
...
...
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