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>
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>
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>
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>
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>
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>
The database instantiation during setup is not currently handled
properly. Until that is fixed, users will need to create wp-content.php
on their own.
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
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>
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>
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>
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>
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>
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>
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>