I'm trying to query the database inside my module, but I get this error.
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 'FROM "commerce_product_variation" "cpv" WHERE ("variation_id" NOT IN (NULL)) AND' at line 1: SELECT FROM "commerce_product_variation" "cpv" WHERE ("variation_id" NOT IN (:db_condition_placeholder_0)) AND ("status" = :db_condition_placeholder_1); Array ( [:db_condition_placeholder_0] => [:db_condition_placeholder_1] => 1 ) in deactivateProductVariantsNotInList() (regel 816 van /data/sites/web/pcreathingbe/subsites/staging.protectasolutions.be/web/modules/custom/importproducts/importproducts.module).
The code I am using is the following.
function deactivateProductVariantsNotInList($variant_type) {
global $milieu_data;
if ($variant_type == 'milieutechniek') {
$database = \Drupal::service('database');
$query = $database->select('commerce_product_variation', 'cpv');
$query->condition('variation_id', $milieu_data, 'NOT IN')
->condition('status', 1)
->execute();
}
}