@@ -472,6 +472,13 @@ class WP_MySQL_On_SQLite extends PDO {
472472 */
473473 private $ error_mode = PDO ::ERRMODE_EXCEPTION ;
474474
475+ /**
476+ * Whether fetched scalar values should be converted to strings.
477+ *
478+ * @var bool
479+ */
480+ private $ stringify_fetches = false ;
481+
475482 /**
476483 * SQLSTATE associated with the last PDO operation.
477484 *
@@ -679,9 +686,11 @@ class WP_MySQL_On_SQLite extends PDO {
679686 * @param string $dsn MySQL-on-SQLite DSN containing the SQLite path and database name.
680687 * @param string|null $username Optional. Ignored by this driver.
681688 * @param string|null $password Optional. Ignored by this driver.
682- * @param array $options {
689+ * @param array|null $options {
683690 * Optional driver options.
684691 *
692+ * Numeric keys are handled as standard PDO constructor options.
693+ *
685694 * @type int $mysql_version Optional. MySQL version to emulate. Default 80038.
686695 * @type PDO|null $pdo Optional. Existing SQLite PDO connection.
687696 * @type string|null $journal_mode Optional. SQLite journal mode. Default 'WAL'.
@@ -694,8 +703,10 @@ public function __construct(
694703 string $ dsn ,
695704 ?string $ username = null ,
696705 ?string $ password = null ,
697- array $ options = array ()
706+ ? array $ options = null
698707 ) {
708+ $ options = $ options ?? array ();
709+
699710 // PDO DSN can't include "\0" bytes; parsing stops at the first one.
700711 $ first_null_byte_index = strpos ( $ dsn , "\0" );
701712 if ( false !== $ first_null_byte_index ) {
@@ -736,9 +747,18 @@ public function __construct(
736747 $ db_name = $ args ['dbname ' ] ?? 'sqlite_database ' ;
737748
738749 // Create a new SQLite connection.
750+ $ pdo_options = array_filter (
751+ $ options ,
752+ function ( $ key ) {
753+ return is_int ( $ key );
754+ },
755+ ARRAY_FILTER_USE_KEY
756+ );
757+
739758 $ connection_options = array (
740759 'journal_mode ' => $ options ['journal_mode ' ] ?? null ,
741760 'synchronous ' => $ options ['synchronous ' ] ?? null ,
761+ 'pdo_options ' => $ pdo_options ,
742762 );
743763 if ( isset ( $ options ['pdo ' ] ) ) {
744764 $ connection_options ['pdo ' ] = $ options ['pdo ' ];
@@ -835,6 +855,15 @@ function ( string $sql, array $params ) {
835855 );
836856 }
837857 );
858+
859+ foreach ( $ pdo_options as $ attribute => $ value ) {
860+ // Persistence is a connection-time-only option and was already passed
861+ // to the underlying PDO constructor when creating a new connection.
862+ if ( PDO ::ATTR_PERSISTENT === $ attribute ) {
863+ continue ;
864+ }
865+ $ this ->setAttribute ( $ attribute , $ value );
866+ }
838867 }
839868
840869 /**
@@ -1236,7 +1265,12 @@ public function setAttribute( $attribute, $value ): bool {
12361265 $ pdo ->setAttribute ( PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
12371266 return true ;
12381267 }
1239- return $ this ->connection ->get_pdo ()->setAttribute ( $ attribute , $ value );
1268+
1269+ $ result = $ this ->connection ->get_pdo ()->setAttribute ( $ attribute , $ value );
1270+ if ( $ result && PDO ::ATTR_STRINGIFY_FETCHES === $ attribute ) {
1271+ $ this ->stringify_fetches = (bool ) $ value ;
1272+ }
1273+ return $ result ;
12401274 }
12411275
12421276 /**
@@ -1254,6 +1288,9 @@ public function getAttribute( $attribute ) {
12541288 if ( PDO ::ATTR_ERRMODE === $ attribute ) {
12551289 return $ this ->error_mode ;
12561290 }
1291+ if ( PDO ::ATTR_STRINGIFY_FETCHES === $ attribute ) {
1292+ return $ this ->stringify_fetches ;
1293+ }
12571294 return $ this ->connection ->get_pdo ()->getAttribute ( $ attribute );
12581295 }
12591296
0 commit comments