Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
re6stnet
Commits
c231062f
Commit
c231062f
authored
Apr 22, 2013
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ON DELETE CASCADE does not work with attached databases
parent
4eb574a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
re6st/db.py
re6st/db.py
+8
-6
No files found.
re6st/db.py
View file @
c231062f
...
@@ -25,11 +25,10 @@ class PeerDB(object):
...
@@ -25,11 +25,10 @@ class PeerDB(object):
value text)"""
)
value text)"""
)
q
(
'ATTACH DATABASE ":memory:" AS volatile'
)
q
(
'ATTACH DATABASE ":memory:" AS volatile'
)
q
(
"""CREATE TABLE volatile.stat (
q
(
"""CREATE TABLE volatile.stat (
peer TEXT PRIMARY KEY
REFERENCES peer(prefix) ON DELETE CASCADE
,
peer TEXT PRIMARY KEY,
try INTEGER NOT NULL DEFAULT 0)"""
)
try INTEGER NOT NULL DEFAULT 0)"""
)
q
(
"CREATE INDEX volatile.stat_try ON stat(try)"
)
q
(
"CREATE INDEX volatile.stat_try ON stat(try)"
)
q
(
"INSERT INTO volatile.stat (peer) SELECT prefix FROM peer"
)
q
(
"INSERT INTO volatile.stat (peer) SELECT prefix FROM peer"
)
q
(
"PRAGMA foreign_keys = ON"
)
try
:
try
:
a
=
q
(
"SELECT value FROM config WHERE name='registry'"
).
next
()[
0
]
a
=
q
(
"SELECT value FROM config WHERE name='registry'"
).
next
()[
0
]
except
StopIteration
:
except
StopIteration
:
...
@@ -114,10 +113,13 @@ class PeerDB(object):
...
@@ -114,10 +113,13 @@ class PeerDB(object):
return
len
(
preferred
)
return
len
(
preferred
)
address
=
';'
.
join
(
sorted
(
address
.
split
(
';'
),
key
=
key
))
address
=
';'
.
join
(
sorted
(
address
.
split
(
';'
),
key
=
key
))
except
ValueError
:
except
ValueError
:
q
(
"DELETE FROM peer WHERE prefix IN (SELECT peer"
a
=
q
(
"SELECT peer FROM volatile.stat ORDER BY try, RANDOM()"
" FROM volatile.stat ORDER BY try, RANDOM() LIMIT ?,-1)"
,
" LIMIT ?,-1"
,
(
self
.
_db_size
,)).
fetchall
()
(
self
.
_db_size
,))
if
a
:
a
=
None
qq
=
self
.
_db
.
executemany
qq
(
"DELETE FROM peer WHERE prefix IN (?)"
,
a
)
qq
(
"DELETE FROM volatile.stat WHERE peer IN (?)"
,
a
)
# 'a != address' will evaluate to True because types differs
if
a
!=
address
:
if
a
!=
address
:
q
(
"INSERT OR REPLACE INTO peer VALUES (?,?)"
,
(
prefix
,
address
))
q
(
"INSERT OR REPLACE INTO peer VALUES (?,?)"
,
(
prefix
,
address
))
q
(
"INSERT OR REPLACE INTO volatile.stat VALUES (?,0)"
,
(
prefix
,))
q
(
"INSERT OR REPLACE INTO volatile.stat VALUES (?,0)"
,
(
prefix
,))
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