I executed this script in DB2 10.1, and after that, I do not know how to reestablish the database connection:
script.sql
--#SET TERMINATOR #
SET CURRENT SCHEMA BLOCK_DB #
CREATE PROCEDURE BLOCK_DB.A ()
BEGIN
END #
CREATE PROCEDURE BLOCK_DB.B ()
BEGIN
CALL BLOCK_DB.A ();
END #
--#SET TERMINATOR ;
UPDATE DB CFG USING CONNECT_PROC BLOCK_DB.B;
DROP PROCEDURE BLOCK_DB.A ();
CONNECT RESET;
I executed like this
db2 -tf script.sql
After that, I tried to reconnect, but it was unsuccessful.
db2 connect to sample
DO NOT TRY THIS IN A PRODUCTION ENVIRONMENT.
Simply reset the value of CONNECT_PROC:
db2 "update db cfg for <db> using connect_proc ''"
You do not need to have a database connection to execute this statement. This will set CONNECT_PROC back to the default (NULL), and you'll be able to connect to the database again.
Related
I am working on a stored procedure to update values in a couple of tables in one go. I am getting CLI0118E Invalid SQL syntax. during the execution. However, I am not able to find the issue with my stored procedure as I am not quite familiar with the whole stored procedure rules. Any help on this would be much appreciated.
CREATE OR REPLACE PROCEDURE MYPROCNAME(IN VAL1 VARCHAR(255),IN VAL2 VARCHAR(255),IN VAL3 VARCHAR(255),IN VAL4 VARCHAR(255))
LANGUAGE SQL
BEGIN ATOMIC
UPDATE SCHEMA1.TABLE1 SET col1=VAL2, col2=VAL3, col3=VAL4 WHERE col1=VAL1;
UPDATE SCHEMA2.TABLE1 SET col1=VAL3, col2=VAL3, col3=VAL4 WHERE col1=VAL1;
FOR v AS
SELECT col1 FROM SCHEMA2.TABLE2 WHERE col2=VAL1
DO
UPDATE SCHEMA2.TABLE3 SET col2=VAL2 WHERE col1=v.col1 AND col3='<<value>>';
UPDATE SCHEMA2.TABLE3 SET col2=VAL3 WHERE col1=v.col1 AND col3='<<value2>>';
END FOR;
END
#
In the FOR statement, I even tried like this FOR v AS cur1 CURSOR FOR
Used this to compile the procedure first -- db2 -td# -vf myprocname.db2
Then, tried executing the procedure using -- db2 call MYPROCNAME 'val1','val2','val3','val4'
Also, tried the execution in diff combinations like db2 call MYPROCNAME ('val1','val2','val3',val4'), db2 call MYPROCNAME("val1","val2","val3","val4"), etc...
If I use () in the db2 call, I get the bash: syntax error near unexpected token (' error.
PS: I am using db2 11.5
As mentioned in the comment to my question above, running the following db2 "call MYPROCNAME ('val1', 'val2', 'val3', 'val4')" fixes the issue
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")
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;
I recently changed from AnyDac to FireDac (8.0.5.3365). We're running Delphi 2006.
When I was using the AnyDac version of this component I could create a new database by doing the following..
Setup my connection
fConnection.LoginPrompt := false;
fConnection.ResourceOptions.SilentMode := true;
fConnection.Params.Clear;
fConnection.Params.Add(Format('DriverID=%s', ['IB']));
fConnection.Params.Add(Format('Database=%s', [fConnectionInfo.xDatabase]));
fConnection.Params.Add(Format('CharacterSet=%s', ['UTF8']));
fConnection.Params.Add(Format('user_name=%s', [fConnectionInfo.xUserName]));
fConnection.Params.Add(Format('password=%s', [fConnectionInfo.xPassword]));
fConnection.Params.Add(Format('ExtendedMetadata=%s', ['True']));
fConnection.Params.Add(Format('CreateDatabase=%s', ['Yes']));
fConnection.Params.Add(Format('Protocol=%s', ['Local']))
//database path = C:\Users\LoginName\AppData\Local\AppName\TestDB.FDB
Open and close the connection
fConnection.Open;
fConnection.Close;
And then I could run my create table sql scripts on the existing database.
But now when I do this with the FireDac version, the Open command raises the fbe_unavailable error as if I didn't specify the CreateDatabase parameter.
Should I be doing this a different way?
Thanks for your time.
Corey.
You have a full example here http://docwiki.embarcadero.com/RADStudio/Rio/en/Executing_SQL_Scripts_%28FireDAC%29
For example, the following Firebird script creates a database, and can be executed using TFDScript:
SET SQL DIALECT 3;
SET NAMES UTF8;
SET CLIENTLIB 'C:\fb25\bin\fbclient.dll';
CREATE DATABASE 'E:\Test2.ib'
USER 'sysdba' PASSWORD 'masterkey'
PAGE_SIZE 16384
DEFAULT CHARACTER SET NONE;
SET TERM ^ ;
CREATE PROCEDURE MY_PROC RETURNS (aParam INTEGER) AS
BEGIN
aParam = 10;
END^
You should use CreateDatabase=Yes connection definition parameter
additionally to other required parameters:
http://docwiki.embarcadero.com/RADStudio/Rio/en/Connect_to_Firebird_(FireDAC)
I am trying to create a Magento module installer, that will in turn create a stored procedure.
The code for the procedure has been run through: Toad, phpmyadmin, and mysql.exe command line. It worked in all 3. However, it fails when Magento goes to execute it during the installation process.
Error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;
Magento Code:
$installer = $this;
$installer->startSetup();
$sql = <<<____SQL
DELIMITER //
CREATE PROCEDURE GetStuff(
IN pSomeId int(11)
)
BEGIN
DECLARE pOtherId INT;
SELECT some_var INTO pOtherId FROM some_table WHERE id = pSomeId;
END;//
DELIMITER ;
____SQL;
$installer->run($sql);
$installer->endSetup();
There's some other code in between, of course, but simplifying did not change the error.
My guess is that it is something to do with Delimeters and how PDO/Magento is treating them. Thank you.
I figured it out.
I did not need to use any delimiters, PDO can take care of them on its own.
But I did need to switch the method from query (used by the installer) to exec.
So, I ended up with:
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$write->exec($sql);