3434#include " CppUnit/TestCaller.h"
3535#include " CppUnit/TestSuite.h"
3636#include " Poco/String.h"
37+ #include " Poco/Tuple.h"
3738#include " Poco/Format.h"
3839#include " Poco/Exception.h"
3940#include " Poco/Data/Common.h"
@@ -54,6 +55,7 @@ using Poco::Data::ODBC::ConnectionException;
5455using Poco::Data::ODBC ::StatementException;
5556using Poco::Data::ODBC ::StatementDiagnostics;
5657using Poco::format;
58+ using Poco::Tuple;
5759using Poco::NotFoundException;
5860
5961
@@ -827,7 +829,98 @@ void ODBCOracleTest::testInternalExtraction()
827829
828830void ODBCOracleTest::testStoredProcedure ()
829831{
830- // TODO
832+ *_pSession << " CREATE OR REPLACE "
833+ " PROCEDURE storedProcedure(outParam OUT NUMBER) IS "
834+ " BEGIN outParam := -1; "
835+ " END storedProcedure;" , now;
836+
837+ int i = 0 ;
838+ *_pSession << " {call storedProcedure(?)}" , out (i), now;
839+ assert (-1 == i);
840+ *_pSession << " DROP PROCEDURE storedProcedure;" , now;
841+
842+ *_pSession << " CREATE OR REPLACE "
843+ " PROCEDURE storedProcedure(inParam IN NUMBER, outParam OUT NUMBER) IS "
844+ " BEGIN outParam := inParam*inParam; "
845+ " END storedProcedure;" , now;
846+
847+ i = 2 ;
848+ int j = 0 ;
849+ *_pSession << " {call storedProcedure(?, ?)}" , in (i), out (j), now;
850+ assert (4 == j);
851+ *_pSession << " DROP PROCEDURE storedProcedure;" , now;
852+
853+ *_pSession << " CREATE OR REPLACE "
854+ " PROCEDURE storedProcedure(ioParam IN OUT NUMBER) IS "
855+ " BEGIN ioParam := ioParam*ioParam; "
856+ " END storedProcedure;" , now;
857+
858+ i = 2 ;
859+ *_pSession << " {call storedProcedure(?)}" , io (i), now;
860+ assert (4 == i);
861+ *_pSession << " DROP PROCEDURE storedProcedure;" , now;
862+ }
863+
864+
865+ void ODBCOracleTest::testStoredFunction ()
866+ {
867+ *_pSession << " CREATE OR REPLACE "
868+ " FUNCTION storedFunction RETURN NUMBER IS "
869+ " BEGIN return(-1); "
870+ " END storedFunction;" , now;
871+
872+ int i = 0 ;
873+ *_pSession << " {? = call storedFunction()}" , out (i), now;
874+ assert (-1 == i);
875+ *_pSession << " DROP FUNCTION storedFunction;" , now;
876+
877+ *_pSession << " CREATE OR REPLACE "
878+ " FUNCTION storedFunction(inParam IN NUMBER) RETURN NUMBER IS "
879+ " BEGIN RETURN(inParam*inParam); "
880+ " END storedFunction;" , now;
881+
882+ i = 2 ;
883+ int result = 0 ;
884+ *_pSession << " {? = call storedFunction(?)}" , out (result), in (i), now;
885+ assert (4 == result);
886+ *_pSession << " DROP FUNCTION storedFunction;" , now;
887+
888+ *_pSession << " CREATE OR REPLACE "
889+ " FUNCTION storedFunction(inParam IN NUMBER, outParam OUT NUMBER) RETURN NUMBER IS "
890+ " BEGIN outParam := inParam*inParam; RETURN(outParam); "
891+ " END storedFunction;" , now;
892+
893+ i = 2 ;
894+ int j = 0 ;
895+ result = 0 ;
896+ *_pSession << " {? = call storedFunction(?, ?)}" , out (result), in (i), out (j), now;
897+ assert (4 == j);
898+ assert (j == result);
899+ *_pSession << " DROP FUNCTION storedFunction;" , now;
900+
901+ *_pSession << " CREATE OR REPLACE "
902+ " FUNCTION storedFunction(param1 IN OUT NUMBER, param2 IN OUT NUMBER) RETURN NUMBER IS "
903+ " temp NUMBER := param1; "
904+ " BEGIN param1 := param2; param2 := temp; RETURN(param1+param2); "
905+ " END storedFunction;" , now;
906+
907+ i = 1 ;
908+ j = 2 ;
909+ result = 0 ;
910+ *_pSession << " {? = call storedFunction(?, ?)}" , out (result), io (i), io (j), now;
911+ assert (1 == j);
912+ assert (2 == i);
913+ assert (3 == result);
914+
915+ Tuple<int , int > params (1 , 2 );
916+ assert (1 == params.get <0 >());
917+ assert (2 == params.get <1 >());
918+ result = 0 ;
919+ *_pSession << " {? = call storedFunction(?, ?)}" , out (result), io (params), now;
920+ assert (1 == params.get <1 >());
921+ assert (2 == params.get <0 >());
922+ assert (3 == result);
923+ *_pSession << " DROP FUNCTION storedFunction;" , now;
831924}
832925
833926
@@ -1081,6 +1174,7 @@ CppUnit::Test* ODBCOracleTest::suite()
10811174 CppUnit_addTest (pSuite, ODBCOracleTest, testTuple);
10821175 CppUnit_addTest (pSuite, ODBCOracleTest, testTupleVector);
10831176 CppUnit_addTest (pSuite, ODBCOracleTest, testStoredProcedure);
1177+ CppUnit_addTest (pSuite, ODBCOracleTest, testStoredFunction);
10841178 CppUnit_addTest (pSuite, ODBCOracleTest, testInternalExtraction);
10851179
10861180 return pSuite;
0 commit comments