[BUGREPORT] Errore SQL: 1064 - You have an error .....

Documentazione generica riguardo osCommerce

Moderatore: mod Documentazione

Rispondi
Avatar utente
marcus
membro Master
membro Master
Messaggi: 1619
Iscritto il: 04/12/2003, 1:00
Contatta:

[BUGREPORT] Errore SQL: 1064 - You have an error .....

Messaggio da marcus »

Spesso effettuando il listing delle offerte, o dei produttori, o degli ordini, o altro, si verifica un errore SQL del tipo:

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 '-20, 20' at line 1

...segue la query eseguita...

[TEP STOP]


L'errore si verifica puntualmente tutte le volte che il numero di elementi da listare è zero, ma solo se la versione di MySQL è la 4.1 o sup.

La causa è un bug non critico delle classi split_page_results (file: split_page_results.php), sia lato shop che lato admin.
Il codice errato della classe lato shop è il seguente (riga 61 circa):

Codice: Seleziona tutto

if ($this->current_page_number > $this->number_of_pages) {
        $this->current_page_number = $this->number_of_pages;
}


La prima volta che il listing viene istanziato $this->current_page_number viene inizializzato ad 1. Se il numero di items è zero $this->number_of_pages vale 0, per cui $this->current_page_number viene settato a 0.

La linea di codice successiva:

Codice: Seleziona tutto

$offset = ($this->number_of_rows_per_page * ($this->current_page_number - 1));


genera allora un offset negativo nell'opzione LIMIT della query che fa 'arrabbiare' MySQL se la versione e la 4.1 o sup.

Una soluzione banale consiste nell'aggiungere un if di controllo, come segue:

Codice: Seleziona tutto

if ($this->number_of_pages > 0) {
     if ($this->current_page_number > $this->number_of_pages) {
           $this->current_page_number = $this->number_of_pages;
     }
} else $this->current_page_number=1;



Un discorso del tutto analogo vale per la classe split lato admin.

Concludo segnalando anche la mancanza di un controllo di consistenza sulla variabile $max_rows, in altre parole valori nulli o negativi non vengono 'filtrati'.

Marcus
Ultima modifica di marcus il 22/07/2008, 20:23, modificato 1 volta in totale.
Avatar utente
marcus
membro Master
membro Master
Messaggi: 1619
Iscritto il: 04/12/2003, 1:00
Contatta:

Messaggio da marcus »

E' stato rilasciato il Fix ufficiale a questo bug, che riporto qui sotto:

------------------------------------------------------------------------------
limit -20, 20
http://www.oscommerce.com/community/bugs,1605
------------------------------------------------------------------------------

Problem:

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 '-20, 20' at line 1

Solution:

Line 67 in catalog/includes/classes/split_page_results.php must be changed from:

$this->sql_query .= " limit " . $offset . ", " . $this->number_of_rows_per_page;

to:

$this->sql_query .= " limit " . max($offset, 0) . ", " . $this->number_of_rows_per_page;

Line 38 in catalog/admin/includes/classes/split_page_results.php must be changed from:

$sql_query .= " limit " . $offset . ", " . $max_rows_per_page;

to:

$sql_query .= " limit " . max($offset, 0) . ", " . $max_rows_per_page;



Marcus
Nuovo pacchetto osCommercePRO (osCPRO) + Modulo Interfacciamento Gestionale Danea.
Visita la demo: http://oscpro.oscommercedev.com/index.php
madooeiei
membro Junior
membro Junior
Messaggi: 4
Iscritto il: 26/09/2015, 9:46

Re: [BUGREPORT] Errore SQL: 1064 - You have an error .....

Messaggio da madooeiei »

$this->number_of_rows_per_page;
ดาวน์โหลด royal1688
adrank888
membro Junior
membro Junior
Messaggi: 1
Iscritto il: 26/09/2016, 5:47

Re: [BUGREPORT] Errore SQL: 1064 - You have an error .....

Messaggio da adrank888 »

La linea di codice successiva:





Gclub
kakasmall
membro Junior
membro Junior
Messaggi: 3
Iscritto il: 26/06/2017, 12:30

Re: [BUGREPORT] Errore SQL: 1064 - You have an error .....

Messaggio da kakasmall »

Bel sito! Amiamo visitare nel tuo blog ... torneremo presto.

^_^ทางเข้าจีคลับ^_^

^_^goldenslot register^_^
Rispondi