Multisite and SQL Syntax Errors
-
Hello,
While trying your plugin for a large multi-site network, I came across two errors relating to the database upgrade/installation process.
The first issue is with the check for the database version not working correctly on a multisite installation. This was reported once before without a resolution: https://www.ads-software.com/support/topic/activation-issue-on-multisite/. The issue remains, where the
hfcm_options_install()
function usesadd_option()
to set the installed version, whilehfcm_db_update_check()
usesget_site_option()
to check it. When the plugin is activated on a single site on a network,get_site_option()
checks at the network level (the terminology for multisite is a bit muddled, “site” means “network”), which is not set byadd_option()
.The related issue here is in the database create query done in
hfcm_options_install()
. This has also been reported more than once https://www.ads-software.com/support/topic/sql-syntax-error-18/ and https://www.ads-software.com/support/topic/you-have-an-error-in-your-sql-syntax-26/. You’re usingdbDelta()
, which is good, but as the Codex notes,dbDelta
is quite picky (it’s essentially using regexes to parse the query). There are two issues with your query. One is the inclusion ofIF NOT EXISTS
, whichdbDelta
is trying to parse as part of the table name.dbDelta
already has code to check for the table existing, so this is not needed. The other issue is the lack of any whitespace between the table name and the opening parenthesis$table_name(
, which causes the same issue wheredbDelta
tries to include the parenthesis as part of the table name.Correcting the first line of the opening SQL statement to
"CREATE TABLE $table_name (
should solve both of these issues.A further note:
dbDelta
can also do schema upgrades transparently, so you could get rid of all of your checks and ALTERs if you wanted to.
- The topic ‘Multisite and SQL Syntax Errors’ is closed to new replies.