Bonjour,
J'ai une table orders :
Pour insérer des éléments dans cette table, j'utilise une procédure stockée :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 CREATE TABLE orders ( id_order serial NOT NULL, password text NOT NULL DEFAULT generate_password(), order_date timestamp with time zone NOT NULL DEFAULT now(), client_firstname text NOT NULL, client_lastname text NOT NULL, client_email text NOT NULL, last_ref_transaction integer, amount integer, status order_status NOT NULL DEFAULT 'ONGOING'::order_status, -- ONGOING, PENDING_PAYMENT, CANCELED, VALIDATED or PROCESSED CONSTRAINT orders_pkey PRIMARY KEY (), CONSTRAINT orders_last_ref_transaction_fkey FOREIGN KEY () REFERENCES transactions () MATCH SIMPLE ON UPDATE CASCADE ON DELETE SET NULL )
Le problème étant que lorsque depuis PHP je lance la requête "SELECT create_order("John", "Doe", "john.doe@nowhere.oups)" Il me renvoi une chaîne de caractères du type "(14,aRZn9$km3x,"2013-07-29 14:33:52.193777-02",John,Doe,john.doe@nowhere.oups,,,ONGOING)".
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 CREATE OR REPLACE FUNCTION create_order(firstname text, lastname text, email text) RETURNS orders AS $BODY$ DECLARE orderid integer; new_order orders%ROWTYPE; BEGIN INSERT INTO orders ("client_firstname", "client_lastname", "client_email") VALUES (firstname, lastname, email) RETURNING orders.id_order INTO orderid; IF NOT FOUND THEN RETURN NULL; END IF; SELECT * FROM orders WHERE id_order = orderid INTO new_order; RETURN new_order; END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100;
Y a-t-il un moyen de modifier la procédure ou la requête qui l'appelle pour que je puisse travailler directement avec le résultat sans avoir à parser une chaîne ?
Merci.
Partager