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>