Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Kirill Smelkov
neo
Commits
5ce3ad70
Commit
5ce3ad70
authored
11 years ago
by
Julien Muchembled
Browse files
Options
Download
Email Patches
Plain Diff
storage: add support for recent version of sqlite
parent
d4ed0828
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
2 deletions
+12
-2
neo/storage/database/sqlite.py
neo/storage/database/sqlite.py
+12
-2
No files found.
neo/storage/database/sqlite.py
View file @
5ce3ad70
...
...
@@ -25,6 +25,15 @@ from neo.lib import logging, util
from
neo.lib.exception
import
DatabaseFailure
from
neo.lib.protocol
import
CellStates
,
ZERO_OID
,
ZERO_TID
,
ZERO_HASH
def
unique_constraint_message
(
table
,
column
):
c
=
sqlite3
.
connect
(
":memory:"
)
c
.
execute
(
"CREATE TABLE %s (%s UNIQUE)"
%
(
table
,
column
))
try
:
c
.
executemany
(
"INSERT INTO %s VALUES(?)"
%
table
,
'xx'
)
except
sqlite3
.
IntegrityError
,
e
:
return
e
.
args
[
0
]
assert
False
def
splitOIDField
(
tid
,
oids
):
if
(
len
(
oids
)
%
8
)
!=
0
or
len
(
oids
)
==
0
:
raise
DatabaseFailure
(
'invalid oids length for tid %d: %d'
%
(
tid
,
...
...
@@ -360,13 +369,14 @@ class SQLiteDatabaseManager(DatabaseManager):
q
(
"DELETE FROM data WHERE id IN (%s)"
%
","
.
join
(
map
(
str
,
data_id_list
)))
def
_storeData
(
self
,
checksum
,
data
,
compression
):
def
_storeData
(
self
,
checksum
,
data
,
compression
,
_dup_hash
=
unique_constraint_message
(
"data"
,
"hash"
)):
H
=
buffer
(
checksum
)
try
:
return
self
.
query
(
"INSERT INTO data VALUES (NULL,?,?,?)"
,
(
H
,
compression
,
buffer
(
data
))).
lastrowid
except
sqlite3
.
IntegrityError
,
e
:
if
e
.
args
[
0
]
==
'column hash is not unique'
:
if
e
.
args
[
0
]
==
_dup_hash
:
(
r
,
c
,
d
),
=
self
.
query
(
"SELECT id, compression, value"
" FROM data WHERE hash=?"
,
(
H
,))
if
c
==
compression
and
str
(
d
)
==
data
:
...
...
This diff is collapsed.
Click to expand it.
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