Failed to execute stored procedure having full database level privileges - stored-procedures

I am using MariaDB 10.0.20.
I do have one database e.g. "Db1", and have one stored procedure under this database named as "SP1". I created one user "user1" as:
GRANT ALL ON DB1.* to user1#'%' identified by '';
Now the problem is that, using this user I am not able to execute Stored procedure and it is returning below error:
ERROR 1370 (42000): execute command denied to user
I've execute the GRANT EXECUTE on user1 as well, but still no luck.
The Security_type of procedure was set to "DEFINER", and later changing to "INVOKER" it didn't help.
Is there any issue with the Grants or SP ? Or its some bug with MariaDB?

Got resolution :).
EXECUTE GRANT For stored Procedure is something like :
GRANT EXECUTE ON Procedure DB1.SP1 to user1;

Related

DB2-12 (Z/OS) - Create Alias for Stored Procedure

it's possible to define an alias for a stored procedure (sql-native)?
In the documentation, reference is made only to: SEQUENCE and TABLES
1) CREATE PROCEDURE OWXXCOLL.STORED1()
2) CREATE ALIAS DB2C.STORED1 FOR OWXXCOLL.STORED1;
3) CALL DB2C.STORED1();
EDIT 2021-05-14
The original question arises for the following problem (I was hoping to get away with using aliases)
Intro
I have defined a native SP
The OWXXCOLL schema is the same one I also use for tables/index...
(I noticed that the tables also have different aliases)
CREATE PROCEDURE OWXXCOLL.STORED1(...)
LANGUAGE SQL
ISOLATION LEVEL CS
WLM ENVIRONMENT FOR DEBUG MODE WLMENV1
ALLOW DEBUG MODE
BEGIN
...
END#
I also modified the cobol program (name:PGMSTO1) to call the Stored with the CALL statement (without qualifier)
EXEC SQL
CALL STORED1 (...)
END-EXEC.
The problem
The various table accesses (SELECT) work correctly BUT When I run the PGMSTO1 the call to the Stored ends with sqlcode -440
NO AUTHORIZED PROCEDURE BY THE NAME STORED1 HAVING COMPATIBLE ARGUMENTS WAS FOUND<
The error comes from the fact that it is not using the owner OWXXCOLL but DB2C (DB2C is user who scheduled the jcl/batch)
If I enter the qualifier (OWXXCOLL) the call it's OK.
I don't understand what to check and what configurations are missing.
Thanks
The cobol program (PGMSTO1) that calls the stored procedure has the following BIND parameters:
COLLID NAME OWNER CREATOR QUALIFIER DYNAMICRULES PATHSCHEMAS
OWXXCOLL PGMSTO1 DB2C DB2C FPXX B "DB2C"
"DB2C" path is used to resolve unqualified stored procedure
I will need to modify the bind parameter "PATH".
I will try to ask to add my schema as well (OWXXCOLL)
PATH("OWXXCOLL","DB2C")

Unable to run a stored procedure in snowflake database

CREATE OR REPLACE PROCEDURE wh.sp_schema.my_sp(arg1 STRING, arg2 STRING)
RETURNS VARCHAR(16777216)
LANGUAGE JAVASCRIPT
AS
$$
stmt = snowflake.createStatement(
{sqlText: `CREATE OR REPLACE TABLE wh.table_schema.RAW_`+arg2+`_`+arg1+` LIKE wh.temp_schema.RAW_`+arg2+`_TEMPLATE`}
);
rs = stmt.execute();
rs.next();
output = rs.getColumnValue(1);
return output;
$$
;
when i create the above stored procedure - below message is displayed
Function my_sp successfully created.
when i run the stored procedure from the worksheet using
CALL my_sp('2018','abc');
I see the below error:
SQL compilation error: Invalid identifier my_sp
I even tried running using fully qualified name for the stored procedure:
CALL wh.sp_schema.my_sp('2018','abc');
I still see the below error:
SQL compilation error: Invalid identifier my_sp.
Also, i would like to know a command to see if my stored procedure has been created or not.
I've looked in the snowflake UI, under 'wh" warehouse and "sp_schema" schema, but could not see anything(stored procedures) other than tables.
This is a simple case of a grants issue. As SECURITYADMIN, if you apply the necessary grants to the role you're using,
GRANT USAGE ON DATABASE wh TO ROLE <role>;
GRANT USAGE ON SCHEMA wh.sp_schema TO ROLE <role>;
GRANT USAGE ON ALL PROCEDURES IN SCHEMA wh.sp_schema TO ROLE <role>;
you'll get past this ambiquous error and get to the next real error
JavaScript execution error: Uncaught ReferenceError: arg2 is not defined in MY_SP
Which is due to javascript SP parameters being case sensitive, so you need to modify the code as follows (change arg to ARG):
{sqlText: `CREATE OR REPLACE TABLE wh.table_schema.RAW_`+ARG2+`_`+ARG1+` LIKE wh.temp_schema.RAW_`+ARG2+`_TEMPLATE`}
Snowflake does not support Stored Procedures. They are implementingjavascript` based APIs for it, but it's still in draft mode.
Here's the link to their APIs (Note Draft Document is written on right hand side).
and here's the link to a ticket on their support forum where they've confirmed it.
There are two obvious possibilities why this may go wrong:
You've implicitly donated the procedure ownership to a ROLE you don't have
There is now a mismatch between the procedure and call type signatures. Verify that there is a wh.sp_schema.my_sp(STRING, STRING) and that your call is like CALL wh.sp_schema.my_sp('2018'::STRING,'abc'::STRING);
Try to solve the error by following query syntax.
CALL database_name.schema.MY_SP('database_name','schema');

On IBM i, how to run a stored procedure via DB2 command of QShell?

How would you run a stored procedure via DB2 command of QShell, as I need a simple way to unit test a change to a stored procedure?
On IBM i
Started qshell with
QSH
Entered these db2 commands in various formats without success
db2 call libraryname.stroredprocedurename('param1value' 'param2value' ?)
db2 call libraryname.stroredprocedurename ('param1value' 'param2value' ?)
db2 call libraryname.stroredprocedurename (param1value param2value ?)
Only reference source I could find
Have tried using CLP to call stored proceduresbut there are no CLP examples
here
You can also use the JDBC client included with jt400.jar. You can run it from QSH by using the following command.
java -cp /qibm/proddata/os400/jt400/lib/jt400.jar com.ibm.as400.access.jdbcClient.Main jdbc:db2:localhost
The client will also handle stored procedure output parameters as shown by the following example.
create procedure add1(in inparm int, out outparm int) language sql begin set outparm = inparm +1; end
call add1(1,?)
Parameter 1 returned 2
I use Squirrel SQL Client http://squirrel-sql.sourceforge.net/ to test all of my SQL.
call libraryname.stroredprocedurename('param1value', 'param2value')
Note the separator is a comma ,, and ? is not a valid parameter marker when called interactively like this.
In addition to the client, you will need a JDBC driver. You can use the JTOpen driver for IBM i found here: http://jt400.sourceforge.net/
From the CL command line, or inside a CL program, you can use the RUNSQL command to execute an SQL statement.
If you're going to be trying multiple ad hoc SQL statements, you might use the STRSQL command. Personally, I tend to use the SQL window provided as part iNavigator.
Finally got the basic syntax
db2 "CALL lib.proc ('parmvalue1')"
Which resulted in:
DB20000I THE SQL COMMAND COMPLETED SUCCESSFULLY.

Unable to cancel a query in DB2

I have the following stored procedure in DB2:
CREATE OR REPLACE PROCEDURE CANCEL_ACTIVITY (IN application_handle INTEGER)
LANGUAGE SQL
BEGIN
DECLARE UOW_ID INTEGER;
DECLARE ACTIVITY_ID INTEGER;
FOR v AS cur1 CURSOR FOR
SELECT UOW_ID, ACTIVITY_ID FROM TABLE(SYSPROC.MON_GET_ACTIVITY(application_handle, -1))
DO
CALL WLM_CANCEL_ACTIVITY(application_handle, v.uow_id, v.activity_id);
END FOR ;
END
Using the following query, I am able to find my connection ID:
SELECT MON_GET_APPLICATION_HANDLE() from SYSIBM.SYSDUMMY1
Which would return a value like 36547. So I call the procedure I just created like so:
CALL CANCEL_ACTIVITY(36547);
As a result, I get the following:
However, if I execute the query that gets connection IDs again, it doesn't seem like that connection ID is gone. I still get the 36547 value returned.
I am quite confused whether this query canceling is working at all. I am getting a range of different type of errors in different environments I am executing the code at.
When I am running it as a SQL query, I get the above error code / response. When my code is being executed in my webpage, I get the following error:
Cannot cancel queries: Java::ComIbmDb2JccAm::SqlDataException: DB2 SQL Error: SQLCODE=-802, SQLSTATE=22003, SQLERRMC=null, DRIVER=4.16.53
I am curious what I am doing wrong?
I would recommend to read Canceling Activies in the DB2 documentation. Canceling an activity is not closing a connection, but selectively aborting a query or other running tasks:
If an activity is consuming too many resources, or is running too
long, you can cancel it. Canceling an activity is gentler than forcing
the application that submitted the activity. A canceled activity
returns SQL4725N to the user, but does not end the connection or
affect any other user activity. Forcing the application ends both the
connection and user activities.
In your procedure you are looking for the app handle, uow and a specific activity ID. Have you looked what the activity you are going to cancel is/was doing? You could use WLM_CAPTURE_ACTIVITY_IN_PROGRESS to first dump information about that activity, so that you can debug your scenario.

Table or view does not exist when opening cursor?

I have a procedure that identifies each locked
account that was locked because of invalid login attempts. However the sp is creating with compilation errors: "ORA-00942: table does not exist". If I run the select statement by itself it works fine but within the sp. Can anyone help?
Create or replace PROCEDURE IdentifyLockedAccounts(p_recordset OUT SYS_REFCURSOR) AS
BEGIN
OPEN p_recordset FOR SELECT USERNAME FROM DBA_USERS WHERE ACCOUNT_STATUS = 'LOCKED' OR ACCOUNT_STATUS = 'LOCKED(TIMED)';
END IdentifyLockedAccounts;
/
Your schema probably has SELECT privilege on DBA_USERS via some role (SELECT_CATALOG_ROLE for instance) - that is why you are able to run it via SQL client.
Roles are not enabled during the compilation of plsql/views therefore you have to grant SELECT ON DBA_USERS directly to schema to be able to use it in stored procedure.
GRANT SELECT ON DBA_USERS to YOURSCHEMA;

Resources