|
17 | 17 | */ |
18 | 18 | class WP_SQLite_Connection { |
19 | 19 | /** |
20 | | - * The default timeout in seconds for SQLite to wait for a writable lock. |
| 20 | + * The default time in milliseconds for SQLite to wait for a lock. |
21 | 21 | */ |
22 | | - const DEFAULT_SQLITE_TIMEOUT = 10; |
| 22 | + const DEFAULT_SQLITE_BUSY_TIMEOUT = 10000; |
23 | 23 |
|
24 | 24 | /** |
25 | 25 | * The supported SQLite journal modes. |
@@ -76,8 +76,8 @@ class WP_SQLite_Connection { |
76 | 76 | * Must be set when PDO instance is not provided. |
77 | 77 | * @type PDO|null $pdo Optional. PDO instance with SQLite connection. |
78 | 78 | * If not provided, a new PDO instance will be created. |
79 | | - * @type int|null $timeout Optional. SQLite timeout in seconds. |
80 | | - * The time to wait for a writable lock. |
| 79 | + * @type int|null $busy_timeout Optional. SQLite busy timeout in milliseconds. |
| 80 | + * The time to wait for a lock. Defaults to 10000. |
81 | 81 | * @type string|null $journal_mode Optional. SQLite journal mode. Defaults to WAL. |
82 | 82 | * @type string|int|null $synchronous Optional. SQLite synchronous setting. Defaults to |
83 | 83 | * NORMAL when the effective journal mode is WAL. |
@@ -107,13 +107,13 @@ public function __construct( array $options ) { |
107 | 107 | // Throw exceptions on error. |
108 | 108 | $this->pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); |
109 | 109 |
|
110 | | - // Configure SQLite timeout. |
111 | | - if ( isset( $options['timeout'] ) && is_int( $options['timeout'] ) ) { |
112 | | - $timeout = $options['timeout']; |
| 110 | + // Configure SQLite busy timeout. |
| 111 | + if ( isset( $options['busy_timeout'] ) && is_int( $options['busy_timeout'] ) ) { |
| 112 | + $busy_timeout = $options['busy_timeout']; |
113 | 113 | } else { |
114 | | - $timeout = self::DEFAULT_SQLITE_TIMEOUT; |
| 114 | + $busy_timeout = self::DEFAULT_SQLITE_BUSY_TIMEOUT; |
115 | 115 | } |
116 | | - $this->pdo->setAttribute( PDO::ATTR_TIMEOUT, $timeout ); |
| 116 | + $this->query( 'PRAGMA busy_timeout = ' . $busy_timeout ); |
117 | 117 |
|
118 | 118 | // Configure SQLite journal mode. Default to WAL for best throughput. |
119 | 119 | $effective_journal_mode = null; |
|
0 commit comments