error calling stored procedure with output parameter in groovy - stored-procedures

...... I found the reason - the problem was there was actually a select in a stored proc that was called from my stored proc which I didn't notice. After removing it everything worked fine.
I call a stored procedure from my code, it has one input and one output parameter. For some reason it gives me an exception, not sure what the problem is, here is the code:
int fileNumber
sql.call("{call initIMAGINE_IDENTIFIERS_DELTAS(?, ?)}", [type, Sql.INTEGER]){ number ->
fileNumber = number
}
and here is the declaration of stored proc:
create procedure initIMAGINE_IDENTIFIERS_DELTAS
#reportType varchar(30) = '',
#loop_id int output
as
BEGIN
the error I get:
Oct 30, 2014 11:18:16 AM groovy.sql.Sql callWithRows
WARNING: Failed to execute: {call initIMAGINE_IDENTIFIERS_DELTAS(?, ?)} because: Output parameters have not yet been processed. Call getMoreResults().
Caught: java.sql.SQLException: Output parameters have not yet been processed. Call getMoreResults().
java.sql.SQLException: Output parameters have not yet been processed. Call getMoreResults().
at net.sourceforge.jtds.jdbc.ParamInfo.getOutValue(ParamInfo.java:159)
at net.sourceforge.jtds.jdbc.JtdsCallableStatement.getOutputValue(JtdsCallableStatement.java:124)
at net.sourceforge.jtds.jdbc.JtdsCallableStatement.getObject(JtdsCallableStatement.java:315)
at Test.init(SqlConnection.gy:26)
at Test$init.call(Unknown Source)
at SqlConnection.run(SqlConnection.gy:9)
The same code actually works against Sybase 15.1 in 12.5 compatibility mode but doesn't work against Sybase 15.7. I am using jtds 1.3.1 driver.

Related

MYSQL 6 - You have an error in your SQL Syntax 'Diagnostics Condition 1'

I have version 8 of MySQL but need to update a database stored procedure that is using 5. When I test this code in version 8 I do not receive any errors. However when I add it to the stored procedure on the the older version I receive the following error:
ERROR 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 'DIAGNOSTICS CONDITION 1 errstate = RETURNED_SQLSTATE, msg =
MESSAGE_TEXT;
This is the code that I have inserted that is causing the error.
DECLARE errstate CHAR(5) DEFAULT '00000';
DECLARE msg TEXT;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
BEGIN
GET DIAGNOSTICS CONDITION 1
errstate = RETURNED_SQLSTATE,
msg = MESSAGE_TEXT;
END;
I could not find any documentation specific to version 5 for using GET DIAGNOSTICS CONDITION.

SQuirrel Call Stored Procedure

I am trying to call a DB2 stored procedure from Squirrel.
I can call the stored procedure successfully from the DB2 command line
processor.
CALL PIPPOOWN.PIPPO
('04','prov','0001','provprov')
I append ;retrieveMessagesFromServerOnGetMessage=true; to connection string for the database.
jdbc:db2://xx.xx.x.xx:50001/DB2XYX:retrieveMessagesFromServerOnGetMessage=true;
But when I try this in Squirrel I get this error message. I am running
Error: [jcc][10413][10940][4.19.49]
Analisi della sostituzione letterale non riuscita per la chiamata della procedura a DB2 per z/OS.
Testo SQL non riuscito CALL
SP_XXXXX('XX','prova').
ERRORCODE=-4463, SQLSTATE=42601
SQLState: 42601
ErrorCode: -4463
2021-02-02 12:01:03,409 [Thread-6] ERROR net.sourceforge.squirrel_sql.fw.util.DefaultExceptionFormatter - Exception occurred while formatting: null
java.lang.NullPointerException
at net.sourceforge.squirrel_sql.plugins.db2.DB2JCCExceptionFormatter.format(DB2JCCExceptionFormatter.java:93)
at net.sourceforge.squirrel_sql.fw.util.DefaultExceptionFormatter.format(DefaultExceptionFormatter.java:68)
at net.sourceforge.squirrel_sql.client.session.Session.formatException(Session.java:1195)
at net.sourceforge.squirrel_sql.client.session.mainpanel.SQLExecutionHandler.sqlExecutionException(SQLExecutionHandler.java:458)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.handleError(SQLExecuterTask.java:621)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.runDirect(SQLExecuterTask.java:264)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.run(SQLExecuterTask.java:137)
at net.sourceforge.squirrel_sql.fw.util.TaskExecuter.run(TaskExecuter.java:82)
at java.lang.Thread.run(Unknown Source)
i updated jdbc drivers but i didn't fix.
DB2 Version: 11.01
If I use IBM DATA STUDIO or I use a DB2 AIX it works.
EDIT 03/02/2021
I downloaded "IBM Data Server Driver for JDBC and SQLJ (JCC Driver)" Version 11.5.4, then I configured it to use db2jcc4.jar
Now it gives the following error:
NO AUTHORIZED PROCEDURE NAMED PIPPOOWN.PIPPO HAVING COMPATIBLE ARGUMENTS WAS FOUND.
SQLCODE=-440, SQLSTATE=42884, DRIVER=4.26.14 SQL Code: -440, SQL State: 42884
but if i use IBM DATA STUDIO with the same user and statements i get no error
Stored Procedure "PIPPO" - GRANT
GRANT EXECUTE ON PROCEDURE "PIPPOOWN"."PIPPO" TO "ALL";
GRANT EXECUTE ON PROCEDURE "PIPPOOWN"."PIPPO" TO "PUBLICB";
GRANT EXECUTE ON PROCEDURE "PIPPOOWN"."PIPPO" TO "PIPPOOWN" WITH GRANT OPTION;
GRANT EXECUTE ON PROCEDURE "PIPPOOWN"."PIPPO" TO "USERWEB";
GRANT EXECUTE ON PROCEDURE "PIPPOOWN"."PIPPO" TO PUBLIC;
Stored Procedure "PIPPO" - Distribution Options (using Data Studio)
CURRENT_PATH BY SQUIRREL
SELECT CURRENT_PATH FROM SYSIBM.SYSDUMMY1
RESULTS
-----------------------------------------------
"SYSIBM","SYSFUN","SYSPROC","SYSIBMADM","PIPPOOWN"
Finally, I can't find any error in the Squirrel log.
Any ideas?
EDIT 04/02/2021
I excecute the call statement on Squirrel, enabling the JDBC log and I found this error:
[jcc][Time:2021-02-04-10:16:23.549][Thread:Thread-4][Statement#f7f204]**execute (CALL OWNER1.SP_ABC('xx')) called**
[jcc][Time:2021-02-04-10:16:23.549][Thread:Thread-4][Statement#f7f204]stmt_bidiTransform (CALL OWNER1.SP_ABC('xx')) called
[jcc][Time:2021-02-04-10:16:23.549][Thread:Thread-4][Statement#f7f204]**stmt_bidiTransform not enabled (CALL OWNER1.SP_ABC('xx')) called**
[jcc][t4][time:2021-02-04-10:16:23.549][Thread:Thread-4][tracepoint:1][Request.flush]
[jcc][t4] SEND BUFFER: EXCSQLSTT (ASCII) (EBCDIC)
...
.....
**com.ibm.db2.jcc.am.SqlSyntaxErrorException
** at com.ibm.db2.jcc.am.b7.a(b7.java:810)
at com.ibm.db2.jcc.am.b7.a(b7.java:66)
at com.ibm.db2.jcc.am.b7.a(b7.java:140)
at com.ibm.db2.jcc.am.k4.b(k4.java:2471)
at com.ibm.db2.jcc.am.k4.c(k4.java:2452)
at com.ibm.db2.jcc.t4.ab.n(ab.java:914)
at com.ibm.db2.jcc.t4.ab.f(ab.java:156)
at com.ibm.db2.jcc.t4.p.e(p.java:81)
at com.ibm.db2.jcc.t4.av.k(av.java:175)
at com.ibm.db2.jcc.am.k4.ao(k4.java:2413)
at com.ibm.db2.jcc.am.k4.a(k4.java:3383)
at com.ibm.db2.jcc.am.k4.e(k4.java:1131)
at com.ibm.db2.jcc.am.k4.execute(k4.java:1110)
at net.sourceforge.squirrel_sql.client.session.StatementWrapper.execute(StatementWrapper.java:168)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.processQuery(SQLExecuterTask.java:361)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.runDirect(SQLExecuterTask.java:214)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.run(SQLExecuterTask.java:137)
at net.sourceforge.squirrel_sql.fw.util.TaskExecuter.run(TaskExecuter.java:82)
at java.lang.Thread.run(Unknown Source)
For comparing the different logs, I also activate the IBM DATA STUDIO JDBC log (where the CALL statements work correctly) and I noticed that a prepareCall() is done before executing execute().
IBM DATA STUDIO
[jcc][Time:2021-02-03-20:52:10.381][Thread:Worker-19][Connection#97f8a03c]prepareCall (CALL OWNER1.SP_ABC('XX')) called
[jcc] [time:2021-02-03-20:52:10.383][Thread:Worker-19][tracepoint:4000]LiteralInfo entry,sql:CALL OWNER1.SP_ABC('XX')
[jcc] [time:2021-02-03-20:52:10.387][Thread:Worker-19][tracepoint:4005]LiteralInfo.return,OriginalSQL:CALL OWNER1.SP_ABC('XX'), modifiedSQL:CALL OWNER1.SP_ABC(?), literalCount=1, parmCount=1[CHARACTER(XX)]
[jcc][Time:2021-02-03-20:52:10.390][Thread:Worker-19][Connection#97f8a03c]prepareCall () returned MappedCallableStatement#691cf97[com.ibm.db2.jcc.am.CallableStatement#88958c83]
[jcc][Time:2021-02-03-20:52:10.390][Thread:Worker-19][Connection#97f8a03c]prepareCall () returned MappedCallableStatement#691cf97[com.ibm.db2.jcc.am.CallableStatement#88958c83]
[jcc][Thread:Worker-19][SystemMonitor:stop] core: 9.5471ms | network: 0.0ms | server: 0.0ms
[jcc][Time:2021-02-03-20:52:10.390][Thread:Worker-19][CallableStatement#88958c83]setMaxRows (0) called
[jcc][Time:2021-02-03-20:52:10.390][Thread:Worker-19][CallableStatement#88958c83]setString (1, XX) called
[jcc][Thread:Worker-19][SystemMonitor:start]
[jcc][Time:2021-02-03-20:52:10.390][Thread:Worker-19][CallableStatement#88958c83]execute () called
[jcc][Time:2021-02-03-20:52:10.390][Thread:Worker-19][CallableStatement#88958c83]stmt_bidiTransform (CALL OWNER1.SP_ABC(?)) called
[jcc][Time:2021-02-03-20:52:10.390][Thread:Worker-19][CallableStatement#88958c83]stmt_bidiTransform not enabled (CALL OWNER1.SP_ABC(?)) called
[jcc][t4][time:2021-02-03-20:52:10.390][Thread:Worker-19][tracepoint:1][Request.flush]
I looked in the [IBM documentation][4] and it seems that in order to call SP with parameters in the Z/OS environment, it is necessary to perform a PreparedStatement.
At this point I think it’s a Squirrel BUG...
I tried to open a BUG: squirrel-sql:bugs#1457 Call Stored Procedure with input parameters on DB2 z/os

Can I call a postgres "Procedure" (not "function") from java using the postgres JDBC driver?

I'm new to postgres but am attempting to call a procedure in Postgres 11 (new "procedure" not a "function"), calling from java as a spring SimpleJDBCCall (using Postgresql-42.2.5 jdbc driver). However, when I execute the procedure I am encountering the following exception:
org.springframework.jdbc.BadSqlGrammarException:
CallableStatementCallback; bad SQL grammar [{call
pa_test_schema.pr_dosomething(?)}]; nested exception is
org.postgresql.util.PSQLException: ERROR:
pa_test_schema.pr_dosomething(bigint) is a procedure Hint: To call a
procedure, use CALL. Position: 15 at
org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:101)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at
org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1402)
at
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1065)
at
org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1104)
at
org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:414)
at
org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:397)
at
org.springframework.jdbc.core.simple.SimpleJdbcCall.execute(SimpleJdbcCall.java:193)
My procedure code:
CREATE PROCEDURE pa_test_schema.pr_DoSomething
( P_input_ID IN inputs.input_ID%TYPE
) AS $$
BEGIN
-- do something
END;
$$ LANGUAGE plpgsql;
My java code:
SimpleJdbcCallOperations pr_DoSomething = new SimpleJdbcCall(jdbcTemplate)
.withSchemaName("pa_test_schema")
.withProcedureName("pr_DoSomething");
Map<String, Object> inputs = Maps.newHashMap();
inputs.put("p_input_id", 123456);
pr_DoSomething.execute(inputs);
When I step through the code I can see the driver is modifying the sql of the callable statement to the syntax required for calling a postgres function:
select * from pa_test_schema.pr_dosomething(?) as result
This is the method in the driver that is doing this conversion:
https://github.com/pgjdbc/pgjdbc/blob/faab499853c56f67cb70fb242f75b918452f2a6f/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L766
I understand procedures were only introduced in Postgres 11 (previously one would have used void-returning functions) and have read through the postgres driver documentation but don't see any reference to calling procedures rather than functions.
Does this mean that the current postgres driver does not yet support this or is there another approach I should be using? Should I just be using postgres functions instead?
Currently (as of Postgres 11.1 and driver version 42.2.5) the standard JDBC approach using a CallableStatement cannot be used to call a stored procedure.
I don't really use Spring JDBC Template, but the following code works in plain JDBC and should be adaptable to Spring JDBC Tempalte:
Connection con = DriverManager.getConnection(...);
PreparedStatement pstmt = con.prepareStatement("call pa_test_schema.pr_DoSomething(?)");
pstmt.setInt(1, 42);
pstmt.execute();
Note that this uses Postgres' call command. Do not confuse this with the "{call ...}" syntax for a CallableStatement.
Some more details on why currently a CallableStatement does not work can be found in the JDBC mailing list here and here

Now that TEurekaExceptionRecord is deprecated in EurekaLog 7, what replaces LogText?

While migrating from EurekaLog 6 to 7, I came to notice a compiler warning that TEurekaExceptionRecord is deprecated and I should use TEurekaExceptionInfo.
In my Delphi 7 app with EurekaLog 6, there is a statement like:
exceptionRecord : TEurekaExceptionRecord;
myString := exceptionRecord.logText;
Now when I am using TEurekaExceptionInfo instead of TEurekaExceptionRecord in my Delphi XE4 with EurekaLog 7 like following:
exceptionInfo : TEurekaExceptionInfo;
myString := exceptionInfo.logText;
I am getting error on the second line because logText does not exist now. Which method has replaced it in EurekaLog 7?
I am the EurekaLog support person. There are large differences between v6 and v7. Your question is difficult to answer since while the globals you are used to in v6 remain in v7, you may not be able to modify or check them in the same way in v7. Success is dependent on when you read or modify the variables. There are several event handlers and each one reads/writes various fields in our EL classes. They are called sequentially, so this is where the timing issue I mentioned comes in. Log text is now created in our dialog box classes, but there are ways to extract raw log text from them.
I recommend that you open a trouble ticket on our web site and post some code that demonstrates what you are trying to do. You can also check our code snippets library for log management ideas.
If you are looking for getting general exception information (class, message, address, etc.) - see How to get exception information?
If you are looking for getting exception's call stack - see How to get exception's call stack?
If you are looking for saving report file into database or network share (with screenshots, attached files, web page, dumps, etc.) - see How to save report instead of sending?
If you want to operate on bug report file - see How to get file name for the bug report?
Normally you do not need to access bug report:
EurekaLog 7.7.8.2
Application:
-------------------------------------------------------
1.1 Start Date : Wed, 17 Oct 2018 16:23:33 +0300
1.2 Name/Description: Project1.exe
1.3 Version Number :
1.4 Parameters :
1.5 Compilation Date: Wed, 17 Oct 2018 16:23:15 +0300
1.6 Up Time : 6 second(s) Exception:
------------------------------------------------------------------------
2.1 Date : Wed, 17 Oct 2018 16:23:39 +0300
2.2 Address : 012A03F0
2.3 Module Name : Project1.exe
2.4 Module Version:
2.5 Type : ERangeError
2.6 Message : Range check error at Unit1.Button1Click (Line 261)
2.7 ID : ABBB0630
2.8 Count : 1
...
It is sufficient to use one of the mentioned above usage cases.
However, one particular example of when you want to access a simple bug report is when you are migrating old code from EurekaLog 6. Bug report was removed from OnExceptionNotify event because bug report does not exist outside of exception processing in EurekaLog 7 (unlike EurekaLog 6). For example, if you decide not to handle exception in OnExceptionNotify event handler - then there will be no bug report generated at all, thus saving processing time.
If you still want EurekaLog 6 style behavior - then bug report content can be retrieved from Dialog.BugReport property at any time (which is basically a cache of LogBuilder.Report property). For example:
uses
EException, // for TEurekaExceptionInfo
ELogBuilder; // for TBaseLogBuilder and RegisterEventEndReportGen
procedure UploadToDB(const ACustom: Pointer;
AExceptionInfo: TEurekaExceptionInfo;
ALogBuilder: TBaseLogBuilder;
var CallNextHandler: Boolean);
var
BugID: Cardinal;
Report: String;
begin
BugID := AExceptionInfo.BugID;
Report := ALogBuilder.Report;
// ... write bug report's content to your DB or
// do whatever you want with it
end;
initialization
RegisterEventEndReportGen(nil, UploadToDB, True);
end.
E.g. you should replace your OnExceptionNotify event handler with OnEndReportGen event handler. This event handler will be called like this:
UploadToDB
TBaseDialog.SaveBugReport
TBaseDialog.Execute
ShowException
ProcessException
ExceptionManager.Handle
Forms.TApplication.HandleException
Alternatively, bug report can be created at any time (on demand) - by using BuildBugReport function:
uses
EException, // for TEurekaExceptionInfo
ELogBuilder; // for BuildBugReport
var
EI: TEurekaExceptionInfo;
Report: String;
begin
try
// ...
except
on E: Exception do
begin
EI := ExceptionManager.Info(E);
// EI = nil for disabled EurekaLog
// or when exception is ignored
if Assigned(EI) then
begin
Report := BuildBugReport(EI);
// ... write bug report's content to your DB
// or do whatever you want with it
end;
end;
end;

Unable to retrieve destination column descriptions from the parameters of the SQL command

I am trying to upgrade an SSIS package from 2008 to 2012 and getting the below error.
Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has
occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft SQL Server Native
Client 11.0" Hresult: 0x80004005 Description: "The metadata could
not be determined because statement 'EXEC master.dbo.xp_logevent
#ErrorCode, #Message, error' in procedure 'DebugPrint' invokes an
extended stored procedure.".
Error: Unable to retrieve destination column descriptions from the
parameters of the SQL command.
Basically, we have an OLE DB Command to call a stored procedure which call several (nested) stored procedures and one of it is DebugPrint which call master.dbo.xp_logevent. Any idea to fix it? It works in SSIS 2008.
Thanks
You could try using 'with result sets' when calling your proc and setting your metadata there.
Example :
EXEC dbo.proc
WITH RESULT SETS (
ID INT
,Col2 VARCHAR)
I came across a similar error.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "The metadata could not be determined because statement '....' uses a temp table.".
Work around.
If SP uses a #table or ##table and it is used in the SP, then we need to specify the #table structure along with the EXEC.
The SP should be given along with the structure.
EXEC SP_TestTemp 1,2
it should be given like
EXEC SP_TestTemp 1,2 WITH RESULT SETS
(
(
id int,
Marks int
)
)
Note: the 'retain same connection = true' and 'validate external metadata' = false did not help/work here

Resources