No Code Attached Yet
avatar stAn47
stAn47
30 Aug 2021

Hello, i am experimenting

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 '' at line 1 Query: INSERT INTO gw6wm_template_overrides

during a complex extension update on joomla 4.

it seems that code in \plugins\installer\override\override.php

does "continue" when an update is detected but still allows to proceed with insert which gives the SQL error.

current code:

private function saveOverrides($pks)
	{
		
		// Insert columns.
		$columns = [
			'template',
			'hash_id',
			'action',
			'created_date',
			'modified_date',
			'extension_id',
			'state',
			'client_id',
		];

		// Create an insert query.
		$insertQuery = $this->db->getQuery(true)
			->insert($this->db->quoteName('#__template_overrides'))
			->columns($this->db->quoteName($columns));

		foreach ($pks as $pk)
		{
			$date = new Date('now');
			$createdDate = $date->toSql();

			if (empty($pk->coreFile))
			{
				$modifiedDate = null;
			}
			else
			{
				$modifiedDate = $createdDate;
			}

			if ($this->load($pk->id, $pk->extension_id))
			{
				$updateQuery = $this->db->getQuery(true)
					->update($this->db->quoteName('#__template_overrides'))
					->set(
						[
							$this->db->quoteName('modified_date') . ' = :modifiedDate',
							$this->db->quoteName('action') . ' = :pkAction',
							$this->db->quoteName('state') . ' = 0',
						]
					)
					->where($this->db->quoteName('hash_id') . ' = :pkId')
					->where($this->db->quoteName('extension_id') . ' = :exId')
					->bind(':modifiedDate', $modifiedDate)
					->bind(':pkAction', $pk->action)
					->bind(':pkId', $pk->id)
					->bind(':exId', $pk->extension_id, ParameterType::INTEGER);

				// Set the query using our newly populated query object and execute it.
				$this->db->setQuery($updateQuery);
				$this->db->execute();

				continue;
			}

			// Insert values, preserve order
			$bindArray = $insertQuery->bindArray(
				[
					$pk->template,
					$pk->id,
					$pk->action,
					$createdDate,
					$modifiedDate,
				],
				ParameterType::STRING
			);
			$bindArray = array_merge(
				$bindArray,
				$insertQuery->bindArray(
					[
						$pk->extension_id,
						0,
						(int) $pk->client,
					]
				)
			);

			$insertQuery->values(implode(',', $bindArray));
			
			
		}

		$this->db->setQuery($insertQuery);
		$this->db->execute();
	}

possible fix:

private function saveOverrides($pks)
	{
		
		// Insert columns.
		$columns = [
			'template',
			'hash_id',
			'action',
			'created_date',
			'modified_date',
			'extension_id',
			'state',
			'client_id',
		];

		// Create an insert query.
		$insertQuery = $this->db->getQuery(true)
			->insert($this->db->quoteName('#__template_overrides'))
			->columns($this->db->quoteName($columns));

		foreach ($pks as $pk)
		{
			$date = new Date('now');
			$createdDate = $date->toSql();

			if (empty($pk->coreFile))
			{
				$modifiedDate = null;
			}
			else
			{
				$modifiedDate = $createdDate;
			}

			if ($this->load($pk->id, $pk->extension_id))
			{
				$updateQuery = $this->db->getQuery(true)
					->update($this->db->quoteName('#__template_overrides'))
					->set(
						[
							$this->db->quoteName('modified_date') . ' = :modifiedDate',
							$this->db->quoteName('action') . ' = :pkAction',
							$this->db->quoteName('state') . ' = 0',
						]
					)
					->where($this->db->quoteName('hash_id') . ' = :pkId')
					->where($this->db->quoteName('extension_id') . ' = :exId')
					->bind(':modifiedDate', $modifiedDate)
					->bind(':pkAction', $pk->action)
					->bind(':pkId', $pk->id)
					->bind(':exId', $pk->extension_id, ParameterType::INTEGER);

				// Set the query using our newly populated query object and execute it.
				$this->db->setQuery($updateQuery);
				$this->db->execute();

				continue;
			}

			// Insert values, preserve order
			$bindArray = $insertQuery->bindArray(
				[
					$pk->template,
					$pk->id,
					$pk->action,
					$createdDate,
					$modifiedDate,
				],
				ParameterType::STRING
			);
			$bindArray = array_merge(
				$bindArray,
				$insertQuery->bindArray(
					[
						$pk->extension_id,
						0,
						(int) $pk->client,
					]
				)
			);

			$insertQuery->values(implode(',', $bindArray));
			
			
		}
                if (!empty($bindArray)) {
		$this->db->setQuery($insertQuery);
		$this->db->execute();
                }
	}

I do not know how to reproduce this exactly as i came on this one during intensive testing of other parts and extensions.

Best regards, stan

avatar stAn47 stAn47 - open - 30 Aug 2021
avatar stAn47 stAn47 - change - 30 Aug 2021
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 30 Aug 2021
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 30 Aug 2021
avatar alikon alikon - change - 30 Aug 2021
Status New Closed
Closed_Date 0000-00-00 00:00:00 2021-08-30 17:44:29
Closed_By alikon
avatar alikon alikon - close - 30 Aug 2021
avatar alikon
alikon - comment - 30 Aug 2021

duplicate of #35427

avatar stAn47 stAn47 - change - 30 Aug 2021
The description was changed
avatar stAn47 stAn47 - edited - 30 Aug 2021
avatar stAn47
stAn47 - comment - 30 Aug 2021

yes, duplicate is caused by this - #35428

Add a Comment

Login with GitHub to post a comment