@@ -161,12 +161,48 @@ def __init__(
161161 self .output_threshold_cost = output_threshold_cost
162162 self .sqlite_inputs = sqlite or {}
163163
164- # SQLite performance defaults
165- self .sqlite_journal_mode = str (self .sqlite_inputs .get ('journal_mode' , 'WAL' ))
166- self .sqlite_synchronous = str (self .sqlite_inputs .get ('synchronous' , 'NORMAL' ))
167- self .sqlite_temp_store = str (self .sqlite_inputs .get ('temp_store' , 'MEMORY' ))
168- self .sqlite_mmap_size = int (self .sqlite_inputs .get ('mmap_size' , 8589934592 ))
169- self .sqlite_cache_size = int (self .sqlite_inputs .get ('cache_size' , - 512000 ))
164+ # SQLite performance settings
165+ # journal_mode: DELETE | TRUNCATE | PERSIST | MEMORY | WAL | OFF
166+ jm_allowed = {'DELETE' , 'TRUNCATE' , 'PERSIST' , 'MEMORY' , 'WAL' , 'OFF' }
167+ jm = self .sqlite_inputs .get ('journal_mode' , 'WAL' )
168+ if isinstance (jm , str ) and jm .upper () in jm_allowed :
169+ self .sqlite_journal_mode : str | int = jm .upper ()
170+ elif isinstance (jm , (int , float , str )) and str (jm ).isdigit ():
171+ self .sqlite_journal_mode = int (jm )
172+ else :
173+ self .sqlite_journal_mode = 'WAL'
174+
175+ # synchronous: OFF (0) | NORMAL (1) | FULL (2) | EXTRA (3)
176+ sync_allowed = {'OFF' , 'NORMAL' , 'FULL' , 'EXTRA' }
177+ sync = self .sqlite_inputs .get ('synchronous' , 'NORMAL' )
178+ if isinstance (sync , str ) and sync .upper () in sync_allowed :
179+ self .sqlite_synchronous : str | int = sync .upper ()
180+ elif isinstance (sync , (int , float , str )) and str (sync ).isdigit ():
181+ self .sqlite_synchronous = int (sync )
182+ else :
183+ self .sqlite_synchronous = 'NORMAL'
184+
185+ # temp_store: DEFAULT (0) | FILE (1) | MEMORY (2)
186+ temp_allowed = {'DEFAULT' , 'FILE' , 'MEMORY' }
187+ ts = self .sqlite_inputs .get ('temp_store' , 'MEMORY' )
188+ if isinstance (ts , str ) and ts .upper () in temp_allowed :
189+ self .sqlite_temp_store : str | int = ts .upper ()
190+ elif isinstance (ts , (int , float , str )) and str (ts ).isdigit ():
191+ self .sqlite_temp_store = int (ts )
192+ else :
193+ self .sqlite_temp_store = 'MEMORY'
194+
195+ mmap_size = self .sqlite_inputs .get ('mmap_size' , 8589934592 )
196+ if isinstance (mmap_size , (int , float , str )):
197+ self .sqlite_mmap_size = int (mmap_size )
198+ else :
199+ self .sqlite_mmap_size = 8589934592
200+
201+ cache_size = self .sqlite_inputs .get ('cache_size' , - 512000 )
202+ if isinstance (cache_size , (int , float , str )):
203+ self .sqlite_cache_size = int (cache_size )
204+ else :
205+ self .sqlite_cache_size = - 512000
170206
171207 # Cycle detection limits
172208 if not isinstance (cycle_count_limit , int ) or cycle_count_limit < - 1 :
@@ -317,8 +353,11 @@ def __repr__(self) -> str:
317353 msg += spacer
318354 msg += '{:>{}s}: {}\n ' .format ('SQLite journal mode' , width , self .sqlite_journal_mode )
319355 msg += '{:>{}s}: {}\n ' .format ('SQLite synchronous' , width , self .sqlite_synchronous )
356+ msg += '{:>{}s}: {}\n ' .format ('SQLite temp store' , width , self .sqlite_temp_store )
320357 msg += '{:>{}s}: {}\n ' .format ('SQLite mmap size (bytes)' , width , self .sqlite_mmap_size )
321- msg += '{:>{}s}: {}\n ' .format ('SQLite cache size (pages)' , width , self .sqlite_cache_size )
358+ msg += '{:>{}s}: {}\n ' .format (
359+ 'SQLite cache size (pages or KiB if negative)' , width , self .sqlite_cache_size
360+ )
322361
323362 msg += spacer
324363 msg += '{:>{}s}: {}\n ' .format ('Time sequencing' , width , self .time_sequencing )
0 commit comments