Skip to content
Code-Schnipsel Gruppen Projekte
Commit 830c8bd2 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

fix: for wrong primary key

Übergeordneter cb0668df
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -42,7 +42,6 @@
<field type="VARCHAR(255) NOT NULL">area</field>
<field type="TEXT NULL">brick</field>
<primary>id,area</primary>
<index>area</index>
</table>
</projects>
......
......@@ -3,4 +3,4 @@
<event on="onSiteSave" fire="\QUI\Bricks\Events::onSiteSave"/>
<event on="onSmartyInit" fire="\QUI\Bricks\Events::onSmartyInit"/>
<event on="onPackageSetup" fire="\QUI\Bricks\Events::onPackageSetup"/>
</events>
\ No newline at end of file
</events>
......@@ -222,6 +222,25 @@ public static function onPackageSetup(QUI\Package\Package $Package)
return;
}
// unique bricks cache patch
$projects = QUI::getProjectManager()->getProjectList();
foreach ($projects as $Project) {
$projectCacheTable = QUI::getDBProjectTableName(
Manager::TABLE_CACHE,
$Project
);
try {
QUI::getDataBase()->fetchSQL(
"`ALTER TABLE ``{$projectCacheTable}`` DROP PRIMARY KEY;`"
  • Maintainer

    @henbug

    When I execute a QUIQQER setup I get the following error for each language in my project:

    INFO - 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 '`ALTER TABLE ``Mainproject_de_bricksCache`` DROP PRIMARY KEY;`' at line 1`ALTER TABLE ``Mainproject_de_bricksCache`` DROP PRIMARY KEY;`

    The SQL statement contains to many backticks I guess. The proper correct statement would be the following, right?

    ALTER TABLE `{$projectCacheTable}` DROP PRIMARY KEY;

    Or is there a reason for the backticks in the beginning and end and the double backticks around the name of the table?


    I cannot confirm that my idea is the correct fix since I'm now getting warnings in my logs. Maybe you could have another look at this section.

  • Maintainer

    The following info is also logged for each language:

     Syntax error or access violation: 1091 Can't DROP 'PRIMARY'; check that column/key existsALTER TABLE `Mainproject_de_bricksCache` DROP PRIMARY KEY;
  • Autor(in) Owner

    will it happen again in the next setup? I think that was intentional. (its a workaround)

  • Maintainer

    I applied my fix from above and the following error still occurred after executing the setup a second time:

    Syntax error or access violation: 1091 Can't DROP 'PRIMARY'; check that column/key existsALTER TABLE `Mainproject_de_bricksCache` DROP PRIMARY KEY;
    von Jan Wennrich bearbeitet
  • Please registrieren or Anmelden to reply
);
} catch (QUI\Exception $Exception) {
QUI\System\Log::addInfo($Exception->getMessage());
}
}
// unique id patch
$php = 'php';
if (\defined('PHP_BINARY')) {
......
  • Autor(in) Owner

    Also bringt dein Fix nix? Dann bitte rückgängig machen.

  • Maintainer

    Jein, mein Fix sorgt zumindest dafür, dass der Fehler

    INFO - 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 '`ALTER TABLE ``Mainproject_de_bricksCache`` DROP PRIMARY KEY;`' at line 1`ALTER TABLE ``Mainproject_de_bricksCache`` DROP PRIMARY KEY;`

    verschwindet. Er korrigiert also die fehlerhafte Syntax. In meiner Antwort oben habe ich glaube ich die falsche Fehlermeldung kopiert. Die Meldung, die danach erscheint ist folgende:

    Syntax error or access violation: 1091 Can't DROP 'PRIMARY'; check that column/key existsALTER TABLE `Mainproject_de_bricksCache` DROP PRIMARY KEY;
  • Maintainer

    Das Problem ist wohl, dass die Tabellen keinen Primary Key haben

  • Maintainer

    Mein Ansatz einer Query/Procedure, die den PK nur dann entfernt, wenn es einen gibt funktioniert so nicht, da Tabellennamen nicht aus Parametern kommen können:

    DELIMITER //
    
    DROP PROCEDURE IF EXISTS drop_primary_key_if_exists //
    
    CREATE PROCEDURE drop_primary_key_if_exists(table_name_param VARCHAR(255))
    BEGIN
        IF EXISTS(
            SELECT constraint_name
                FROM information_schema.table_constraints
                WHERE table_name = table_name_param
                AND constraint_name = 'PRIMARY'
        ) THEN
            ALTER TABLE table_name_param DROP PRIMARY KEY;
        END IF;
    END //
    DELIMITER ;
    
    CALL drop_primary_key_if_exists('feeds');

    Es wird also notwendig sein per PHP erst zu schauen ob die Tabelle einen PK hat. Das Ergebnis der nachfolgenden Query ist 1, wenn ein PK in der Tabelle my_table existiert.

    SELECT COUNT(constraint_name)
        FROM information_schema.table_constraints
        WHERE table_name = `my_table`
        AND constraint_name = 'PRIMARY'

    Anschließend kann die nachfolgende Query ausgeführt werden, um den PK zu entfernen:

    ALTER TABLE table_name_param DROP PRIMARY KEY;
  • Jan Wennrich @JanWennrich

    mentioned in merge request !8 (merged)

    ·

    mentioned in merge request !8 (merged)

    Commit-Liste ein-/ausklappen
  • Maintainer

    Zur Vollständigkeit: Wurde nun auf dev und master gefixt

0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren