comparison roundup/backends/back_sqlite.py @ 6932:ff7f6c0bbdae

flake8 fixes.
author John Rouillard <rouilj@ieee.org>
date Thu, 08 Sep 2022 01:23:27 -0400
parents a96a239db0d9
children e138f5cf432a
comparison
equal deleted inserted replaced
6931:83fa81f084bc 6932:ff7f6c0bbdae
6 NOTE: we use the rdbms_common table creation methods which define datatypes 6 NOTE: we use the rdbms_common table creation methods which define datatypes
7 for the columns, but sqlite IGNORES these specifications. 7 for the columns, but sqlite IGNORES these specifications.
8 """ 8 """
9 __docformat__ = 'restructuredtext' 9 __docformat__ = 'restructuredtext'
10 10
11 import os, marshal, shutil, time, logging 11 import logging
12 import os
13 import shutil
14 import time
15
12 16
13 from roundup import hyperdb, date, password 17 from roundup import hyperdb, date, password
14 from roundup.backends import rdbms_common 18 from roundup.backends import rdbms_common
15 from roundup.backends import sessions_sqlite 19 from roundup.backends import sessions_sqlite
16 from roundup.backends import sessions_dbm 20 from roundup.backends import sessions_dbm
73 # is set to False here. 77 # is set to False here.
74 78
75 implements_double_precision = False 79 implements_double_precision = False
76 80
77 hyperdb_to_sql_datatypes = { 81 hyperdb_to_sql_datatypes = {
78 hyperdb.String : 'VARCHAR(255)', 82 hyperdb.String : 'VARCHAR(255)', # noqa: E203
79 hyperdb.Date : 'VARCHAR(30)', 83 hyperdb.Date : 'VARCHAR(30)', # noqa: E203
80 hyperdb.Link : 'INTEGER', 84 hyperdb.Link : 'INTEGER', # noqa: E203
81 hyperdb.Interval : 'VARCHAR(255)', 85 hyperdb.Interval : 'VARCHAR(255)', # noqa: E203
82 hyperdb.Password : 'VARCHAR(255)', 86 hyperdb.Password : 'VARCHAR(255)', # noqa: E203
83 hyperdb.Boolean : 'BOOLEAN', 87 hyperdb.Boolean : 'BOOLEAN', # noqa: E203
84 hyperdb.Number : 'REAL', 88 hyperdb.Number : 'REAL', # noqa: E203
85 hyperdb.Integer : 'INTEGER', 89 hyperdb.Integer : 'INTEGER', # noqa: E203
86 } 90 }
87 hyperdb_to_sql_value = { 91 hyperdb_to_sql_value = {
88 hyperdb.String : str, 92 hyperdb.String : str, # noqa: E203
89 hyperdb.Date : lambda x: x.serialise(), 93 hyperdb.Date : lambda x: x.serialise(), # noqa: E203
90 hyperdb.Link : int, 94 hyperdb.Link : int, # noqa: E203
91 hyperdb.Interval : str, 95 hyperdb.Interval : str, # noqa: E203
92 hyperdb.Password : str, 96 hyperdb.Password : str, # noqa: E203
93 hyperdb.Boolean : int, 97 hyperdb.Boolean : int, # noqa: E203
94 hyperdb.Integer : int, 98 hyperdb.Integer : int, # noqa: E203
95 hyperdb.Number : lambda x: x, 99 hyperdb.Number : lambda x: x, # noqa: E203
96 hyperdb.Multilink : lambda x: x, # used in journal marshalling 100 hyperdb.Multilink : lambda x: x, # used in journal marshalling, # noqa: E203
97 } 101 }
98 sql_to_hyperdb_value = { 102 sql_to_hyperdb_value = {
99 hyperdb.String : uany2s, 103 hyperdb.String : uany2s, # noqa: E203
100 hyperdb.Date : lambda x: date.Date(str(x)), 104 hyperdb.Date : lambda x: date.Date(str(x)), # noqa: E203
101 hyperdb.Link : str, # XXX numeric ids 105 hyperdb.Link : str, # XXX numeric ids # noqa: E203
102 hyperdb.Interval : date.Interval, 106 hyperdb.Interval : date.Interval, # noqa: E203
103 hyperdb.Password : lambda x: password.Password(encrypted=x), 107 hyperdb.Password : lambda x: password.Password(encrypted=x), # noqa: E203
104 hyperdb.Boolean : int, 108 hyperdb.Boolean : int, # noqa: E203
105 hyperdb.Integer : int, 109 hyperdb.Integer : int, # noqa: E203
106 hyperdb.Number : rdbms_common._num_cvt, 110 hyperdb.Number : rdbms_common._num_cvt, # noqa: E203
107 hyperdb.Multilink : lambda x: x, # used in journal marshalling 111 hyperdb.Multilink : lambda x: x, # used in journal marshalling, # noqa: E203
108 } 112 }
109 113
110 # We're using DBM for managing session info and one-time keys: 114 # We're using DBM for managing session info and one-time keys:
111 # For SQL database storage of this info we would need two concurrent 115 # For SQL database storage of this info we would need two concurrent
112 # connections to the same database which SQLite doesn't support 116 # connections to the same database which SQLite doesn't support
245 # NOOP - no restriction on column length here 249 # NOOP - no restriction on column length here
246 pass 250 pass
247 251
248 def _add_fts5_table(self): 252 def _add_fts5_table(self):
249 self.sql('CREATE virtual TABLE __fts USING fts5(_class, ' 253 self.sql('CREATE virtual TABLE __fts USING fts5(_class, '
250 '_itemid, _prop, _textblob)' 254 '_itemid, _prop, _textblob)')
251 )
252 255
253 def fix_version_6_tables(self): 256 def fix_version_6_tables(self):
254 # note sqlite has no limit on column size so v6 fixes 257 # note sqlite has no limit on column size so v6 fixes
255 # to __words._word length are not needed. 258 # to __words._word length are not needed.
256 # Add native full-text indexing table 259 # Add native full-text indexing table
384 v = entry[name] 387 v = entry[name]
385 else: 388 else:
386 v = None 389 v = None
387 if name == 'id': 390 if name == 'id':
388 retired_id = v 391 retired_id = v
389 elif name == '__retired__' and retired_id and \ 392 elif (name == '__retired__' and retired_id and
390 v not in ['0', 0]: 393 v not in ['0', 0]):
391 v = retired_id 394 v = retired_id
392 d.append(v) 395 d.append(v)
393 self.sql(sql, tuple(d)) 396 self.sql(sql, tuple(d))
394 397
395 return 1 398 return 1
423 Ignore errors if there's nothing to commit. 426 Ignore errors if there's nothing to commit.
424 """ 427 """
425 def list_dir(dir): 428 def list_dir(dir):
426 import os 429 import os
427 files = os.listdir(self.dir) 430 files = os.listdir(self.dir)
428 # ['db-journal', 'files', 'db'] 431 # ['db-journal', 'files', 'db']
429 for entry in [''] + files: 432 for entry in [''] + files:
430 path = self.dir + '/' + entry 433 path = self.dir + '/' + entry
431 stat = os.stat(path) 434 stat = os.stat(path)
432 print("file: %s, uid: %s, gid: %s, mode: %o"%(path, 435 print("file: %s, uid: %s, gid: %s, mode: %o" % (
433 stat.st_uid, stat.st_gid, stat.st_mode)) 436 path, stat.st_uid, stat.st_gid, stat.st_mode))
434 437
435 # Getting sqlite3.OperationalError: disk I/O error 438 # Getting sqlite3.OperationalError: disk I/O error
436 # in CI. It happens intermittently. Try to get more 439 # in CI. It happens intermittently. Try to get more
437 # info about what is happening and retry the commit. 440 # info about what is happening and retry the commit.
438 # Some possibilities: 441 # Some possibilities:
518 for cn in self.classes.keys(): 521 for cn in self.classes.keys():
519 self.setid(cn, 0) 522 self.setid(cn, 0)
520 523
521 def create_class(self, spec): 524 def create_class(self, spec):
522 rdbms_common.Database.create_class(self, spec) 525 rdbms_common.Database.create_class(self, spec)
523 sql = 'insert into ids (name, num) values (%s, %s)' %( 526 sql = 'insert into ids (name, num) values (%s, %s)' % (
524 self.arg, self.arg) 527 self.arg, self.arg)
525 vals = (spec.classname, 1) 528 vals = (spec.classname, 1)
526 self.sql(sql, vals) 529 self.sql(sql, vals)
527 530
528 if sqlite_version in (2, 3): 531 if sqlite_version in (2, 3):

Roundup Issue Tracker: http://roundup-tracker.org/