I cannot speak to misterdidi's answer it may apply also . . . but
Your error message points specifically to a syntax error. As I said in the comments it appears to be a " ; " - the semicolon at
$query = $database->select('commerce_product_variation', 'cpv');
which should be
$query = $database->select('commerce_product_variation', 'cpv')
A PHP code checker will report no issue with either but Drupal is sensitive to it
For instance in Drupal 7 this code below
$weight = db_select('system', 's')
->fields('s', array('weight'))
->condition('name', 'uc_quote', '=')
->execute()
->fetchField();
db_update('system')
->fields(array('weight' => $weight + 1))
->condition('name', 'uc_addresses', '=')
->execute();
ONLY has the semicolon at the end or execute and in Drupal 8/9 Drupalmoduleupgrader changed it to
$weight = \Drupal::database()->select('system', 's')
->fields('s', array('weight'))
->condition('name', 'uc_quote', '=')
->execute()
->fetchField();
// TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
// You will need to use
\Drupal\core\Database\Database::getConnection()` if you
do not yet have access to the container here.
\Drupal::database()->update('system')
->fields(array('weight' => $weight + 1))
->condition('name', 'uc_addresses', '=')
->execute();
While there is no "system" table any longer in Drupal 8 / 9 the purpose of DrupalModuleUpgader and Drupal Rector is to correct syntax and apply coding standards
You will notice whether it is $weight or your $query variable there is no semicolon behind the statement.
The semicolon needs to be removed