VBA et OLEDB => Execution de procs stockées
Bonjour,
J'ai commencé a développer une application en VBA sous Autocad.
Des fonctions appellent des procédures stockées Oracle (PL/SQL).
Ca fonctionne sans problème.
Mais j'aimerais adapter la solution sous PostgreSQL. J'ai commencé a essayé de me connecter à une base de données Postgres et a écrire des procédures très simples en PL/PGSQL.
Création de la connection:
Code:
1 2 3 4 5 6 7 8 9
|
Public Sub CreerConnectionPostgres()
...
ChaineConn = "user id=postgres;password=zsefjkzhlfk;Provider=PostgreSQL OLE DB Provider;Data source=127.0.0.1"
cnxPost = ChaineConn
cnxPost.Open
End Sub |
Appel d'une procedure:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
Private Sub callPostgresProceduresCercle()
...
Dim Cmd As New ADODB.Command
CreerConnectionPostgres
Cmd.ActiveConnection = cnxPost
Cmd.CommandType = adCmdStoredProc
Cmd.CommandText = "insertionCercle"
Cmd.Parameters.Append Cmd.CreateParameter("nomtest", adVarChar, adParamInput, 20, "Cercle")
MsgBox "Avant erreur"
Cmd.Execute
MsgBox "Après erreur"
Set Cmd = Nothing
cnxOra.Close
End Sub |
Script Procedure PL/PGSQL
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
CREATE OR REPLACE FUNCTION "public"."insertioncercle"(nomtest varchar)
RETURNS void AS
$BODY$DECLARE
mavar integer DEFAULT 45;
BEGIN
EXECUTE 'INSERT INTO gTest(id,nom) VALUES (' || mavar || ',''' || nomTest|| ''')';
END;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION "public"."insertioncercle"(nomtest varchar) OWNER TO "postgres";
COMMENT ON FUNCTION "public"."insertioncercle"(nomtest varchar) IS ''; |
J'obtiens l'erreur "Procedure name for automatic arguments is not unique" :aie:
Je comprends pas trop le problème. J'ai aucune autres fonctions qui s'applle comme ca avec des paramètres différents.
Il y a t'il un moyen simple de tester la fonction directement sous PostgreSQL (pgadmin III ou Navicat). J'ai essayé avec des
-EXECUTE PROCEDURE insertioncercle('hello')
-EXECUTE PROCEDURE insertioncercle("hello")
-EXECUTE PROCEDURE insertioncercle 'hello'
...
Mais j'ai a chaque fois l'erreur "Syntax error at or near "insertioncercle" au caractère 19"