Skip to content

Commit 71652e6

Browse files
committed
wip
1 parent fc4473d commit 71652e6

5 files changed

Lines changed: 30 additions & 9 deletions

tests/WP_SQLite_Information_Schema_Reconstructor_Tests.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ public function setUp(): void {
5959
);
6060
}
6161

62-
public function testReconstructTable(): void {
62+
/**
63+
* @dataProvider dataPdoStringifyFetches
64+
*/
65+
public function testReconstructTableWithPdoStringifyFetches( bool $pdo_stringify_fetches ): void {
66+
$this->engine->get_connection()->get_pdo()->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, $pdo_stringify_fetches );
67+
6368
$this->engine->get_connection()->query(
6469
'
6570
CREATE TABLE t (
@@ -392,6 +397,13 @@ public function testInvalidDataTypeCacheDataForIndexDefinition(): void {
392397
);
393398
}
394399

400+
public function dataPdoStringifyFetches(): array {
401+
return array(
402+
'PDO::ATTR_STRINGIFY_FETCHES set to true' => array( true ),
403+
'PDO::ATTR_STRINGIFY_FETCHES set to false' => array( false ),
404+
);
405+
}
406+
395407
private function assertQuery( $sql ) {
396408
$retval = $this->engine->query( $sql );
397409
$this->assertNotFalse( $retval );

tests/WP_SQLite_Translator_Tests.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3557,4 +3557,13 @@ public function testCreateTableWithDefaultNowFunction() {
35573557
$result = $this->assertQuery( 'SELECT * FROM test_now_default WHERE id = 2' );
35583558
$this->assertRegExp( '/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/', $result[0]->updated );
35593559
}
3560+
3561+
public function testAsdf(): void {
3562+
$this->assertQuery(
3563+
'CREATE TABLE t (id INT, tms timestamp, d decimal (26 , 8 ) KEY timestamp(timestamp))'
3564+
);
3565+
$res = $this->assertQuery( "SELECT * FROM _mysql_data_types_cache WHERE `table` = 't'" );
3566+
var_dump( $res );
3567+
var_dump( $this->assertQuery( 'SHOW CREATE TABLE t' ) );
3568+
}
35603569
}

wp-includes/sqlite-ast/class-wp-pdo-mysql-on-sqlite.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5986,7 +5986,7 @@ function ( $column ) {
59865986
}
59875987
$rows[] = sprintf( ' PRIMARY KEY (%s)', implode( ', ', $column_list ) );
59885988
} else {
5989-
$is_unique = '0' === $info['NON_UNIQUE'];
5989+
$is_unique = 0 === (int) $info['NON_UNIQUE'];
59905990

59915991
// Prefix the original index name with the table name.
59925992
// This is to avoid conflicting index names in SQLite.
@@ -6267,7 +6267,7 @@ function ( $column ) {
62676267
);
62686268
$sql .= ')';
62696269
} else {
6270-
$is_unique = '0' === $info['NON_UNIQUE'];
6270+
$is_unique = 0 === (int) $info['NON_UNIQUE'];
62716271

62726272
$sql = sprintf(
62736273
' %s%s%sKEY ',

wp-includes/sqlite-ast/class-wp-sqlite-information-schema-reconstructor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,13 @@ private function generate_column_definition( string $table_name, array $column_i
359359
$definition[] = $mysql_type;
360360

361361
// NULL/NOT NULL.
362-
if ( '1' === $column_info['notnull'] ) {
362+
if ( 1 === (int) $column_info['notnull'] ) {
363363
$definition[] = 'NOT NULL';
364364
}
365365

366366
// Auto increment.
367367
$is_auto_increment = false;
368-
if ( '0' !== $column_info['pk'] ) {
368+
if ( 0 !== (int) $column_info['pk'] ) {
369369
$is_auto_increment = $this->driver->execute_sqlite_query(
370370
'SELECT 1 FROM sqlite_master WHERE tbl_name = ? AND sql LIKE ?',
371371
array( $table_name, '%AUTOINCREMENT%' )
@@ -403,7 +403,7 @@ private function generate_key_definition( string $table_name, array $key_info, a
403403
$definition[] = 'FULLTEXT KEY';
404404
} elseif ( 'SPATIAL' === $cached_type ) {
405405
$definition[] = 'SPATIAL KEY';
406-
} elseif ( 'UNIQUE' === $cached_type || '1' === $key_info['unique'] ) {
406+
} elseif ( 'UNIQUE' === $cached_type || 1 === (int) $key_info['unique'] ) {
407407
$definition[] = 'UNIQUE KEY';
408408
} else {
409409
$definition[] = 'KEY';

wp-includes/sqlite/class-wp-sqlite-db.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ public function set_charset( $dbh, $charset = null, $collate = null ) {
7979
*
8080
* @return string The character set.
8181
*/
82-
public function get_col_charset( $table, $column ) {
82+
//public function get_col_charset( $table, $column ) {
8383
// Hardcoded for now.
84-
return 'utf8mb4';
85-
}
84+
// return 'utf8mb4';
85+
//}
8686

8787
/**
8888
* Changes the current SQL mode, and ensures its WordPress compatibility.

0 commit comments

Comments
 (0)