Page 1 of 1

Erreur création article sous PostgreSQL

Posted: 09 Jun 2026, 17:45
by tintinux
C'est une requête qui fonctionne sous MariaDb et MySql mais qui n'est pas (ou plus) acceptée sous PostgreSQL.

J'ai l'impression qu'il suffit de changer la ligne 1046 de UnitProduct.pas comme indiqué dans les pièces jointes.

Cela permettra peut-être au moins de créer des articles, puis du stock et de tout tester.

N'ayant pas de serveur PostgreSQL, je ne peux pas le faire.

Re: Erreur création article sous PostgreSQL

Posted: 09 Jun 2026, 23:28
by Reefounet
Pour répondre à l'erreur du script, il y a un conflit :

Code: Select all

SELECT 0 AS Footer, ps.id, wh.id AS WarehouseId, wh.name AS WarehouseName, ps.qty_checked, ps.date_checked, 
ps.qty_quoted, ps.qty_ordered, ps.qty_delivered, qty_checked-COALESCE(ps.qty_delivered,0) AS qty_remaining,
ps.updatedate FROM Warehouses wh LEFT JOIN ProductsStocks ps ON ps.warehouseid=wh.id AND ps.ProductId = $1 
JOIN Products psp ON psp.Id = ps.productid 
UNION SELECT 1, 
pst.id, --CONFLIT
NULL AS WarehouseId,
'*' AS WarehouseName,
SUM(pst.qty_checked) AS qty_checked, --CONFLIT
NULL AS date_checked,
SUM(COALESCE(pst.qty_quoted,0)) AS qty_quoted, --CONFLIT
SUM(COALESCE(pst.qty_ordered,0)) AS qty_ordered, --CONFLIT
SUM(COALESCE(pst.qty_delivered,0)) AS qty_delivered, --CONFLIT
SUM(pst.qty_checked)-SUM(COALESCE(pst.qty_delivered,0)) AS qty_remaining,  --CONFLIT
MAX(pst.updatedate) AS updatedate --CONFLIT
FROM ProductsStocks pst WHERE pst.productid = $1
ORDER BY 1,4
J'ai cherché le conflit mais je n'ai pas trouvé. Si on supprime pst.id, ça passe.
Si on supprime le premier SUM, c'est le second qui est en conflit, etc !
Le seul moyen que j'ai trouvé pour contourner cela est de faire : select sum(qty_checked) as qty_checked from ProductsStocks WHERE pst.productid = $1
le code devient alors

Code: Select all

SELECT 0 AS Footer, ps.id, wh.id AS WarehouseId, wh.name AS WarehouseName, ps.qty_checked, ps.date_checked, 
ps.qty_quoted, ps.qty_ordered, ps.qty_delivered, qty_checked-COALESCE(ps.qty_delivered,0) AS qty_remaining,
ps.updatedate FROM Warehouses wh LEFT JOIN ProductsStocks ps ON ps.warehouseid=wh.id AND ps.ProductId = $1 
JOIN Products psp ON psp.Id = ps.productid 
UNION SELECT 1, 
pst.id,
NULL AS WarehouseId,
'*' AS WarehouseName,
(SELECT SUM(qty_checked) FROM ProductsStocks WHERE productid = $1) AS qty_checked,
NULL AS date_checked,
(SELECT SUM(COALESCE(qty_quoted,0)) FROM ProductsStocks WHERE productid = $1) AS qty_quoted,
(SELECT SUM(COALESCE(qty_ordered,0)) FROM ProductsStocks WHERE productid = $1) AS qty_ordered,
(SELECT SUM(COALESCE(qty_delivered,0)) FROM ProductsStocks WHERE productid = $1) AS qty_delivered,
(SELECT SUM(qty_checked)-SUM(COALESCE(qty_delivered,0)) FROM ProductsStocks WHERE productid = $1) AS qty_remaining,
(SELECT MAX(updatedate) FROM ProductsStocks WHERE productid = $1) AS updatedate
FROM ProductsStocks pst WHERE pst.productid = $1
ORDER BY 1,4
Sous PgAdmin, c'est OK !

Re: Erreur création article sous PostgreSQL

Posted: 09 Jun 2026, 23:30
by Reefounet
J'ai modifier la requête dans Unitproduct.pas et ça fonctionne.

Il faut donc le tester sous Mysql et MariaDB

Je joins le fichier modifié.

Re: Erreur création article sous PostgreSQL

Posted: 10 Jun 2026, 12:21
by tintinux
Bonjour

Je ne vois pas de modification dans le fichier joint.

Re: Erreur création article sous PostgreSQL

Posted: 10 Jun 2026, 12:55
by Reefounet
Ligne 1049 et suivantes

Re: Erreur création article sous PostgreSQL

Posted: 10 Jun 2026, 13:32
by tintinux
La modification proposée avec le diff ne convenait pas ?

Re: Erreur création article sous PostgreSQL

Posted: 10 Jun 2026, 14:08
by Reefounet
Je n'ai pas testé.
Je regarde ça ce soir.