Readonly mode DB
This commit is contained in:
		
							parent
							
								
									e02a0b4e50
								
							
						
					
					
						commit
						3689fbd3ae
					
				
					 1 changed files with 6 additions and 1 deletions
				
			
		| 
						 | 
					@ -3,13 +3,18 @@ class Database
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	public static $handle = null;
 | 
						public static $handle = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function __construct($createDatabase = false)
 | 
						public function __construct($createDatabase = false, bool $readonly = false)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (self::$handle === null) {
 | 
							if (self::$handle === null) {
 | 
				
			||||||
			self::$handle = new SQLite3(SQLITE_DB);
 | 
								self::$handle = new SQLite3(SQLITE_DB);
 | 
				
			||||||
			self::$handle->enableExceptions(true);
 | 
								self::$handle->enableExceptions(true);
 | 
				
			||||||
			self::$handle->busyTimeout(60000);
 | 
								self::$handle->busyTimeout(60000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if ($readonly === true) {
 | 
				
			||||||
 | 
									self::$handle->exec("PRAGMA read_uncommitted = true");
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$initialQueries = [
 | 
								$initialQueries = [
 | 
				
			||||||
				"PRAGMA journal_mode = WAL",
 | 
									"PRAGMA journal_mode = WAL",
 | 
				
			||||||
				"PRAGMA synchronous = OFF",
 | 
									"PRAGMA synchronous = OFF",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue