Hello,

After upgrading from 8.x-1.5 to 8.x-1.7, access to the sitemap.xml path, or rebuild the sitemap generate an SQL error. I try tp uninstall and reinstall simple_sitemap, but same issue occurs.

Otherwise, simple and useful module :-)

The error message

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'generated) VALUES ('0', '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xml' at line 1: INSERT INTO {simplesitemap} (id, sitemap_string, generated) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"> <url> <loc>http://flocon.new/</loc> <xhtml:link rel="alternate" hreflang="en" href="http://flocon.new/en"/> <xhtml:link rel="alternate" hreflang="fr" href="http://flocon.new/"/> <priority>1</priority> </url> </urlset> [:db_insert_placeholder_2] => 1453557820 ) in Drupal\simplesitemap\Simplesitemap->save_sitemap() (line 172 of modules/simple_sitemap/src/Simplesitemap.php).
Drupal\Core\Database\Statement->execute(Array, Array)
Drupal\Core\Database\Connection->query('INSERT INTO {simplesitemap} (id, sitemap_string, generated) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2)', Array, Array)
Drupal\Core\Database\Driver\mysql\Connection->query('INSERT INTO {simplesitemap} (id, sitemap_string, generated) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2)', Array, Array)
Drupal\Core\Database\Driver\mysql\Insert->execute()
Drupal\simplesitemap\Simplesitemap->save_sitemap()
Drupal\simplesitemap\Simplesitemap->generate_sitemap()
Drupal\simplesitemap\Form\SimplesitemapSettingsForm->rebuild_sitemap(Array, Object)
call_user_func_array(Array, Array)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object)
Drupal\Core\Form\FormBuilder->processForm('simplesitemap_settings_form', Array, Object)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1)
Stack\StackedHttpKernel->handle(Object, 1, 1)
Drupal\Core\DrupalKernel->handle(Object)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

flocondetoile created an issue. See original summary.

flocondetoile’s picture

And after reinstallation you can't anyway access to the settings form of simple sitemap or even on the content type form.

Seems that the column language_code is missing in the database.

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'language_code' in 'where clause': SELECT s.sitemap_string AS sitemap_string FROM {simplesitemap} s WHERE (language_code = :db_condition_placeholder_0); Array ( [:db_condition_placeholder_0] => fr ) in Drupal\simplesitemap\Simplesitemap->get_sitemap_from_db() (line 55 of modules/simple_sitemap/src/Simplesitemap.php).
Drupal\Core\Database\Statement->execute(Array, Array)
Drupal\Core\Database\Connection->query('SELECT s.sitemap_string AS sitemap_string
FROM 
{simplesitemap} s
WHERE  (language_code = :db_condition_placeholder_0) ', Array, Array)
Drupal\Core\Database\Driver\mysql\Connection->query('SELECT s.sitemap_string AS sitemap_string
FROM 
{simplesitemap} s
WHERE  (language_code = :db_condition_placeholder_0) ', Array, Array)
Drupal\Core\Database\Query\Select->execute()
Drupal\simplesitemap\Simplesitemap->get_sitemap_from_db()
flocondetoile’s picture

Priority: Normal » Critical
flocondetoile’s picture

The hook_schema do not contains anymore the language_code field.

Edit : but seems that it's normal in regard to the save_sitemap() method.

In version 1.7

/**
 * Implements hook_schema().
 */
function simplesitemap_schema() {
  $schema['simplesitemap'] = array(
    'description' => 'Holds XML sitemaps as strings for quick retrieval.',
    'fields' => array(
      'id' => array(
        'description' => 'Sitemap chunk unique identifier.',
        'type' => 'int',
        'size' => 'small',
        'not null' => TRUE,
      ),
      'sitemap_string' => array(
        'description' => 'XML sitemap chunk string.',
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
      ),
      'generated' => array(
        'description' => 'Timestamp of sitemap chunk generation.',
        'type' => 'int',
        'default' => 0,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array('id'),
  );
  return $schema;
}

In version 1.5


/**
 * Implements hook_schema().
 */
function simplesitemap_schema() {
  $schema['simplesitemap'] = array(
    'description' => 'Holds XML sitemaps as strings for quick retrieval.',
    'fields' => array(
      'language_code' => array(
        'description' => 'Language code of the sitemap used as unique identifier.',
        'type' => 'varchar',
        'not null' => TRUE,
        'length' => 12,
      ),
      'sitemap_string' => array(
        'description' => 'XML sitemap string.',
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array('language_code'),
  );
  return $schema;
}
flocondetoile’s picture

Title: SQLSTATE[42000]: Syntax error or access violation afetr upgrading to 8.x-1.7 » SQLSTATE[42000]: Syntax error or access violation after upgrading to 8.x-1.7
gbyte’s picture

Hi flocondetoile,

did you upgrade all the files and then run /update.php? Running update.php is a must after any module update.

To recover you should be able to leave 1.7 on the server and reinstall. You will loose your sitemap settings however.

flocondetoile’s picture

Hi,

I made drush up simple_sitemap.
The hook_update_N have been applied.

gbyte’s picture

I cannot reproduce this, just downloaded and configured 1.5 and updated to 1.7 successfully.

Are you able to uninstall the module and install 1.7? If using drush+devel, you may want to try the devel-reinstall command.

flocondetoile’s picture

I revert simplesitemap to version 1.5 and all is fine. I try then to do an antoher update with drush. Same issue. I checked if database was well updated. It's OK.
I ran the command drush devel-reinstall, without success.

I also try to uninstall simplesitemap and install the 1.7 version from scratch. Same issue.

I wonder is this issue is not due to the content of the sitemap saved in the field "sitemap_string".
I will try to do some more debug.

flocondetoile’s picture

Status: Active » Needs review
FileSize
2.58 KB

I revert to version 1.5 and upgraded to 1.6. Simple sitemap works fine.
Upgraded from 1.6 to 1.7. Same issue.

After digging in MySQL, seems that this issue is because the word "generated" is used for a column's title in the simplesitemap table. Since MySQL 5.7.6, "generated" is a reserved word (see https://dev.mysql.com/doc/refman/5.7/en/keywords.html) and so must be quoted if used as a column title. Or more simpler, we can use an another word for this column's title.

And I'm using MySQL 5.7.9.

The patch attached change the word "generated" used in the table by "sitemap_date" (and in the code of course). After applying this patch, simplesitemap 1.7 works fine on MySQL 5.7.9.

thanks for your review

  • gbyte.co committed 61c1e2a on 8.x-1.x authored by flocondetoile
    Issue #2655432 by flocondetoile: SQLSTATE[42000]: Syntax error or access...
gbyte’s picture

gbyte’s picture

Status: Needs review » Closed (fixed)

Wow this one is quite exotic, a new reserved word in MySQL... how did you manage to debug it?

I had to modify your patch, as altering an existing hook_update_N implementation would lead to all users of 1.6 not getting the update. Can you please reinstall 1.5 and update to the newest dev to verify the upgrade works? I do not have a >= 5.7.6 MySQL environment at hand.

flocondetoile’s picture

Version: 8.x-1.7 » 8.x-1.x-dev
Status: Closed (fixed) » Needs review
FileSize
832 bytes

Hi,

I was a bit lucky. After debugging your code, and found nothing, it remained only as a possible cause MySQL itself. And while playing with fields properties in the database, I've got a warning message about this reserved word :-D

Sorry, I forgot that we can't modify existing hook_update_N but add new one.

Testing your patch.
I reinstall simplesitemap on version 1.5 and then do the update to the dev version. The hook simplesitemap_update_8106() don't apply => error : Unable to change the field. field 'generated' not exists.
I reinstall simplesitemap on version 1.7 and then do the update to the dev version. The hook simplesitemap_update_8106() don't apply => error : Unable to change the field. field 'generated' not exists.

In fact, as I'am on MySQL 5.7.9, using db_change_field, db_drop_field on this reserved name does not work.
I success to change the database schema with a db_drop_table and a db_creta_table. but it's a little overkill.

I managed to change the name of the column with a direct query on the table, because I can escape the column title in the query

Database::getConnection()->query('alter table `simplesitemap` CHANGE `generated` sitemap_created int(11) NOT NULL ');

Patch attached. This patch applies to the DEV version

gbyte’s picture

Status: Needs review » Closed (fixed)

Thanks man! Altered slightly and pushed back to dev.