diff --git a/wp-content/pg4wp/driver_pgsql.php b/wp-content/pg4wp/driver_pgsql.php index a9e1bb7..f43422d 100644 --- a/wp-content/pg4wp/driver_pgsql.php +++ b/wp-content/pg4wp/driver_pgsql.php @@ -139,6 +139,14 @@ $sql = preg_replace($pattern, ' "ID" ', $sql); } // CAPITALS + // REGEXP and RLIKE + $sql = str_replace( ' REGEXP BINARY ', ' ~ ', $sql); + $sql = str_replace( ' NOT REGEXP BINARY ', ' !~ ', $sql); + $sql = str_replace( ' REGEXP ', ' ~* ', $sql); + $sql = str_replace( ' NOT REGEXP ', ' !~* ', $sql); + $sql = str_replace( ' RLIKE ', ' ~* ', $sql); + $sql = str_replace( ' NOT RLIKE ', ' !~* ', $sql); + if( 0 === strpos($sql, 'SELECT')) { $logto = 'SELECT'; @@ -182,7 +190,7 @@ // MySQL 'LIKE' is case insensitive by default, whereas PostgreSQL 'LIKE' is $sql = str_replace( ' LIKE ', ' ILIKE ', $sql); - + // INDEXES are not yet supported if( false !== strpos( $sql, 'USE INDEX (comment_date_gmt)')) $sql = str_replace( 'USE INDEX (comment_date_gmt)', '', $sql); @@ -233,6 +241,10 @@ $sql = str_replace("VALUES ('0',", "VALUES(", $sql); } + // ON DUPLICATE KEY not supported (should use + // UPDATE and if that fails, INSERT) + $sql = preg_replace( '/ ON DUPLICATE KEY .*$/', '', $sql); + // Those are used when we need to set the date to now() in gmt time $sql = str_replace( "'0000-00-00 00:00:00'", 'now() AT TIME ZONE \'gmt\'', $sql); @@ -271,7 +283,7 @@ $table = $matches[1]; $sql = 'SELECT bc.relname AS "Table", CASE WHEN i.indisunique THEN \'0\' ELSE \'1\' END AS "Non_unique", - CASE WHEN i.indisprimary THEN \'PRIMARY\' WHEN bc.relname LIKE \'%usermeta\' AND ic.relname = \'umeta_key\' THEN \'meta_key\' ELSE ic.relname END AS "Key_name", + CASE WHEN i.indisprimary THEN \'PRIMARY\' WHEN bc.relname LIKE \'%usermeta\' AND ic.relname = \'umeta_key\' THEN \'meta_key\' WHEN bc.relname LIKE \'%postmeta\' AND ic.relname = \'pmeta_key\' THEN \'meta_key\' ELSE ic.relname END AS "Key_name", a.attname AS "Column_name", NULL AS "Sub_part" FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a @@ -320,6 +332,8 @@ WHERE bc.oid = i.indrelid // Workaround for index name duplicate if( $table == $table_prefix.'usermeta' && $index == 'meta_key') $index = 'umeta_key'; + if( $table == $table_prefix.'postmeta' && $index == 'meta_key') + $index = 'pmeta_key'; $sql = "CREATE {$unique}INDEX $index ON $table ($columns)"; } } @@ -392,6 +406,8 @@ WHERE pg_class.relname='$table_name' AND pg_attribute.attnum>=1 AND NOT pg_attri // Workaround for index name duplicate if( $table == $table_prefix.'usermeta' && $index == 'meta_key') $index = 'umeta_key'; + if( $table == $table_prefix.'postmeta' && $index == 'meta_key') + $index = 'pmeta_key'; $sql .= "\nCREATE {$unique}INDEX $index ON $table ($columns);"; } // Now remove handled indexes