162 Commits

Author SHA1 Message Date
Matthew Bucci
3d164e15a6 remove the field function because it's already accounted for in the rewriter 2023-11-10 11:24:49 -08:00
Matthew Bucci
2485f31cdc Change connections to pass by reference to better emulate the mysqli driver 2023-11-10 11:11:04 -08:00
Matthew Bucci
54b4ffb4df add connect error handling 2023-11-09 23:01:26 -08:00
Matthew Bucci
31ce063e06 ignore multi query as part of flush 2023-11-09 22:51:55 -08:00
Matthew Bucci
1f3692d4f9 implement pg_ping 2023-11-09 21:28:21 -08:00
Matthew Bucci
259a58b144 remove nonexistant PG_query mode 2023-11-09 21:24:38 -08:00
Matthew Bucci
20f0d7b9e9 driver fixes 2023-11-09 20:19:02 -08:00
Matthew Bucci
eb3a4c1711 port over what exists from the old pgsql driver 2023-11-09 19:53:49 -08:00
Matthew Bucci
50db9c8fd8 rewrite mysql driver implementation to replace mysqli instead of mysql 2023-11-09 09:34:33 -08:00
Matthew Bucci
e3f3682bc0 update wordpress dependency files for WP 6.4.1 2023-11-08 22:48:27 -08:00
Matthew Bucci
a810cfb7da cleanup AlterTableSQLRewriter 2023-11-07 15:50:52 -08:00
Matthew Bucci
ed00779cf5 add connection to pg_last_error call 2023-11-07 15:32:19 -08:00
Matthew Bucci
dad1f0d264 formatting 2023-11-07 15:29:37 -08:00
Matthew Bucci
c60d8f90b1 Migrate install rewriting to new rewriters 2023-11-07 15:26:03 -08:00
Matthew Bucci
3754ae32e4 Change plugin info 2023-10-30 22:15:04 -07:00
Matthew Bucci
fa6222bdee correct regex for insert matching 2023-10-30 21:02:50 -07:00
Matthew Bucci
63f3f092ba ensure we don't pass null to trim during ensureGroupByOrAggregate 2023-10-30 15:20:15 -07:00
Matthew Bucci
ec9079d9c9 don't split on ',' if within a function 2023-10-30 14:24:27 -07:00
Matthew Bucci
9fda15b2da correct DB_DRIVER define 2023-10-30 09:27:19 -07:00
Matthew Bucci
83002198b1 Polymorphic refactor + improvements to select sql rewriting 2023-10-28 02:56:41 -07:00
Matthew Bucci
a45338251e Merge branch 'postgres15-compatibility' into mb-php8-wp6-support 2023-10-28 02:54:37 -07:00
Matthew Bucci
0e692fd263 Merge branch 'php8-compatiblity' into mb-php8-wp6-support 2023-10-28 02:54:19 -07:00
Matthew Bucci
8816e1dcaa replace incorrect constant 2023-10-28 02:50:05 -07:00
Matthew Bucci
1bde430f0d PHP 8 compatibility fixes 2023-10-28 02:43:59 -07:00
Matthew Bucci
aef2e89812 patches for postgres 15 compatibility, various warnings fixes and more 2023-10-28 02:27:14 -07:00
ycz
f2a05dddbe fix meta_value compares bug 2019-07-23 21:19:40 +00:00
Alexander Schlarb
0607337f6b Also check in the WordPress base directory for the PG4WP files 2018-03-17 14:43:04 +01:00
Kevin Locke
06884bd732 Move pg4wp_rewrite_field out of pg4wp_rewrite
To fix "Cannot redeclare pg4wp_rewrite_field"

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2017-09-24 15:41:21 -06:00
Kevin Locke
54042c1bcc Convert MySQL RAND() to PostgreSQL RANDOM()
These functions are compatible, with the exception that MySQL RAND()
optionally takes a seed argument.  If future queries require seed
support, a call to PostgreSQL SETSEED() can be added.

Fixes: #12

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2017-09-24 14:18:25 -06:00
Kevin Locke
f896bb1759 Rewrite MySQL FIELD function to CASE statement
PostgreSQL does not provide an equivalent to the MySQL FIELD function.
It is possible to create such a function, although the syntax is
version-dependent (and creates a persistent database object, which so
far has not been done by this plugin).  So use a generic CASE statement.

Fixes: #12

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2017-09-24 14:07:40 -06:00
Kevin Locke
35e0af4252 Convert HAVING without GROUP BY to WHERE
Fixes #9

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2017-04-14 12:54:14 -06:00
Kevin Locke
6587b4085b Create MySQL-compatible field function on connect
Fixes: #8

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2017-04-08 16:20:58 -06:00
Kevin Locke
1d2666ca1d Remove unnecessary isset() before empty()
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2017-04-08 16:20:39 -06:00
Kevin Locke
7c4d76a0b6 Fix connection failure handling
If the connection fails, bail early.  Otherwise the processing of the
queued SQL statements will cause an infinite loop by continually pushing
the same statement into the queue due to lack of connection.

Also add a local variable for the connection for clarity and
performance.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2017-04-08 13:33:13 -06:00
Kevin Locke
68d8ead5ad Partially revert 650f768
Although calling wpsql_select_db from wpsql_connect did set the
connection globally, it also caused early clearing of the connection
string when WP_INSTALLING is defined and ran queued early SQL commands
before select is called by external code (which was dubious).  Revert
it, but keep using the best guess at the database name, since this often
saves a connection.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2016-08-22 18:21:10 -06:00
Kevin Locke
bb7c8076a0 Remove obsolete comment
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2016-08-22 17:59:03 -06:00
Kevin Locke
650f768e69 Call wpsql_select_db from wpsql_connect
Rather than calling pg_connect directly, call wpsql_select_db with the
best guess at the database name.  This sets $GLOBALS['pg4wp_conn'] and avoids reconnecting whenever the guess is correct.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2016-08-22 17:58:59 -06:00
Kevin Locke
5f6e9200c0 Match wpsql_ping formatting to adjacent functions
Although I am not a big fan of the existing style, I think consistency
adds enough value to justify keeping the formatting as standardized as
possible.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2016-08-22 15:45:34 -06:00
David BARBION
8a80acdf6e fix caompatibility with WordPress 4.6 2016-08-17 22:35:24 +02:00
Kevin Locke
ac43107187 Avoid warnings due to unmatched capture groups
If the non-capturing group which contains the last two capture groups of
the expression is not matched, the indexes are not defined in the match
result, causing a warning.  Avoid this using isset() before access.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2016-06-30 15:39:15 -07:00
Kevin Locke
5b7e9a80ff Protect against undefined $wpdb in _rewrite
The wpdb constructor makes some queries (e.g. for SQL_MODE) which are
rewritten.  This occurs before the constructor returns and therefore
before the $wpdb global is set.  Handle this without errors.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2016-06-30 15:38:14 -07:00
Kevin Locke
2fc28e9bd8 Only instantiate when DB_USER is defined
During setup, before wp-content.php is created and DB_USER is defined,
there is no way to instantiate it meaningfully.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2016-06-30 15:37:14 -07:00
Kevin Locke
3a5afabcae Support using integers as booleans in expressions
For MySQL compatibility, support using integers as booleans in
expressions.  This is an expensive and unreliable check, so limit it to
the cases currently observed in the wild.  We can expand the checks
later if more uses appear.

The current appearance is from the query:

SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  WHERE 1=1 AND 0
ORDER BY wp_posts.post_date DESC LIMIT 0, 10

made by require('wp-blog-header.php'), wp, WP->main, WP->query_posts,
WP_Query->query, WP_Query->get_posts

I can't determine the exact source of the calls or whether it is
URL-dependent.  But for me that is irrelevant, since it is a case that I
need to support.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2015-10-02 14:02:31 -07:00
Kevin Locke
33740e34e5 Replace split() with explode() for PHP 7
It appears that the split function, which has been deprecated since PHP
5.3.0, has finally been removed in PHP 7.  Since it is being used to
split on a literal string, use explode() instead.

Fixes #1

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2015-09-22 08:40:02 -07:00
Kevin Locke
2ab93ef3a4 Log the SQL for errors in wpsql_insert_id
If the query produces an error, log the query which produced the error
in addition to the insert statement which preceded it.  This helped me
track down an issue with a mis-named sequence from a bad
MySQL->PostgreSQL migration.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2015-09-12 09:53:23 -07:00
Kevin Locke
b9479d4559 Fix match for string-quoted identifier
The pattern added in 785307ee only matches single-character identifiers,
but should match identifiers of any non-zero length.  Fix it.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2015-09-12 09:51:11 -07:00
Kevin Locke
42c63a916f [nextgen-gallery] Remove ORDER BY from DELETE where possible
MySQL supports the ORDER BY clause on DELETE statements for use with
the LIMIT clause to choose which rows are deleted.  PostgreSQL does
not support this clause, which leads to errors such as:

Error running :
DELETE FROM wp_posts  WHERE 1=1  AND wp_posts.post_type = 'display_type' AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft'))  ORDER BY wp_posts.post_date DESC
---- converted to ----
DELETE FROM wp_posts  WHERE 1=1  AND wp_posts.post_type = 'display_type' AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft'))  ORDER BY wp_posts.post_date DESC
----> ERROR:  syntax error at or near "ORDER"
LINE 1: ...rash' AND wp_posts.post_status <> 'auto-draft'))  ORDER BY w...

When the ORDER BY clause is specified without a LIMIT clause, as it is
in the above error, it does not have any effect that I am aware of (due
to how transactions are handled).  In these cases, we remove the ORDER
BY clause to avoid the error.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2015-06-06 21:48:28 -06:00
Kevin Locke
a9edb3a572 [nextgen-gallery] Check ORDER BY in SELECT DISTINCT
MySQL supports ordering by columns which do not appear in the field list
for a SELECT DISTINCT statement while PostgreSQL does not.  This results
in errors such as:

Error running :
SELECT DISTINCT pid , GROUP_CONCAT(CONCAT_WS('@@', meta_key, meta_value)) AS `extras` FROM `wp_ngg_pictures` LEFT OUTER JOIN `wp_postmeta` ON `wp_postmeta`.`post_id` = `extras_post_id`  WHERE (`exclude` = 0) AND (`galleryid` IN (2)) GROUP BY wp_ngg_pictures.pid ORDER BY `sortorder` ASC
---- converted to ----
SELECT DISTINCT pid , string_agg(CONCAT_WS('@@', meta_key, meta_value), ',') AS extras FROM wp_ngg_pictures LEFT OUTER JOIN wp_postmeta ON wp_postmeta.post_id = extras_post_id  WHERE (exclude = 0) AND (galleryid IN (2)) GROUP BY wp_ngg_pictures.pid ORDER BY sortorder ASC
----> ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 1: ...yid IN (2)) GROUP BY wp_ngg_pictures.pid ORDER BY sortorder ...
                                                             ^
To avoid this error, ensure that the field listed in the ORDER BY
statement also appears in the SELECT statement.  To support GROUP BY
statements, ensure that it is aggregated using MIN() to mimic the MySQL
behavior.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2015-06-06 21:48:28 -06:00
Kevin Locke
c2f5a06ae6 [nextgen-gallery] Support SIGNED data type in CAST()
MySQL recognizes SIGNED and UNSIGNED in place of SIGNED INTEGER and
UNSIGNED INTEGER.  Notice this in calls to CAST() and replace it with
INTEGER (which is signed by default).

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2015-06-06 21:48:28 -06:00
Kevin Locke
cf3f571dbf [nextgen-gallery] Support for CONVERT() in place of CAST()
MySQL provides a CONVERT function for doing data type conversion.
This currently results in errors such as:

Error running :
SELECT image_slug, SUBSTR(image_slug, 10) AS 'i' FROM wp_ngg_pictures WHERE (image_slug LIKE 'img_0601-%' AND CONVERT(SUBSTR(image_slug, 10), SIGNED) BETWEEN 1 AND 2147483647) OR image_slug = 'img_0601' ORDER BY i DESC LIMIT 1
---- converted to ----
SELECT image_slug, SUBSTR(image_slug, 10) AS "i" FROM wp_ngg_pictures WHERE (image_slug ILIKE 'img_0601-%' AND CONVERT(SUBSTR(image_slug, 10), SIGNED) BETWEEN 1 AND 2147483647) OR image_slug = 'img_0601' ORDER BY i DESC LIMIT 1
----> ERROR:  column "signed" does not exist
LINE 1: ... 'img_0601-%' AND CONVERT(SUBSTR(image_slug, 10), SIGNED) BE...

Recognize this function and replace it with CAST().

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2015-06-06 21:48:28 -06:00