Disable flyway escaping escape char in Snowflake javascript procedure definition - stored-procedures

I have Snowflake scripts migrated to Snowflake through Flyway migration. Where I'm facing issue in migrating a Snowflake javascript procedure with regex pattern in it.
The following line of code in procedure
var precision = type.match(/\\d+/gi)[0];
Is migrated as
var precision = type.match(/\\\\d+/gi)[0];
We can clearly see that Flyway is escaping the escape char (backslash), which I want to disable. Any idea how to do it?
Flyway version: 8.5.12

Related

Getting invalid SQL syntax upon executing stored procedure via DB2 CLI

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

BigQuery stored procedure access through simba jdbc driver

All,
I am trying to execute a stored procedure in google bigquery using a jdbc connection but having no luck with it.
I followed the example here https://cloud.google.com/blog/products/data-analytics/command-and-control-now-easier-in-bigquery-with-scripting-and-stored-procedures.
I am able to create and call the stored procedure from bigquery web ui but when i set up a data source in intellij using the simba driver as explained here https://blog.jetbrains.com/datagrip/2018/07/10/using-bigquery-from-intellij-based-ide/
Then when i run the call to execute the stored procedure
DECLARE target_employee_id INT64 DEFAULT 9;
DECLARE employee_hierarchy ARRAY<INT64>;
dataset.GetEmployeeHierarchy(target_employee_id, employee_hierarchy);
SELECT target_employee_id, employee_hierarchy;
i get an error
[HY000][100032] [Simba][BigQueryJDBCDriver](100032) Error executing query job. Message: Unrecognized name: target_employee_id at [1:8] com.simba.googlebigquery.support.exceptions.GeneralException: [Simba][BigQueryJDBCDriver](100032) Error executing query job. Message: Unrecognized name: target_employee_id at [1:8]
As the stored procedure support is in pre-release beta, I am wondering if the Simba driver supports it as of now?
If not are there any other jdbc drivers that do currently?
So turns out all the 4 statements need to be executed as a single Bloc not as individual statements.
In intellij you can highlight all those statements and hit run to execute it and return the results.
In Java just pass them as a single string in statement.execute.

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.

Error while creating a simple DB2 sql procedure

I am trying to create a db2 procedure on DB2 z/OS 10.1.5. The code I am using is :
CREATE PROCEDURE WSDIWW16.CALCULATE_SALARY()
LANGUAGE SQL
BEGIN ATOMIC
update wsdiww16.emptable
set dailywage = dailywage * 30;
END;
I am getting sqlcode - 104
SQL0104N An unexpected token "<END-OF-STATEMENT>" was found following "".
Expected tokens may include: "DECLARE".
I haven't created an sql procedure earlier. Can somebody please help ?
You've got two semicolons in that CREATE statement. The first one needs to be a different character that's recognized as a statement terminator.
What development environment are you using? In Rational Developer for z, you can right-click the editor and select the Set Statement Terminator option:
1
Similar options should be available in Data Studio, etc.
You should use end line terminator such as '/' and execute your query using below command -
db2 +c -td/ -vf SQL_file_name
HTH
The answer with the graphical menu worked for me. From inside my SQL script I did a right click anywhere in the white space. The menu above then appeared. I then left clicked on "Set Statement Terminator" (as requested). I then changed my terminator character to "#" (no quote marks). After that the semicolon character ";" started working again.
I hope this helps.
I believe you need to end your procedures with a '/'.

Magento: Create Stored Procedure

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);

Resources