Is trigger procedure supported in HSQLDB 2.4.0 - hsqldb

I'm using postgresql dialect with HSQLDB 2.4.0 on a test context.
I'm also using a trigger procedure
When I load my first SQL script into HSQLDB:
SET DATABASE SQL SYNTAX PGS TRUE;
CREATE FUNCTION trigg_proc() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
INSERT INTO test(desc)
VALUES('hello world');
RETURN NEW;
END;
$$;
CREATE TABLE test(
desc CHARACTER VARYING(60) NOT NULL
);
I get this error from HSQLDB
...
Caused by: java.sql.SQLSyntaxErrorException: unexpected token: TRIGGER
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.execute(Unknown Source)
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:473)
... 58 more
Caused by: org.hsqldb.HsqlException: unexpected token: TRIGGER
at org.hsqldb.error.Error.parseError(Unknown Source)
at org.hsqldb.ParserBase.unexpectedToken(Unknown Source)
at org.hsqldb.ParserBase.checkIsNonCoreReservedIdentifier(Unknown Source)
at org.hsqldb.ParserDQL.checkIsSchemaObjectName(Unknown Source)
at org.hsqldb.ParserDQL.readTypeDefinition(Unknown Source)
at org.hsqldb.ParserRoutine.readProcedureOrFunctionDeclaration(Unknown Source)
at org.hsqldb.ParserRoutine.readCreateProcedureOrFunction(Unknown Source)
at org.hsqldb.ParserRoutine.compileCreateProcedureOrFunction(Unknown Source)
at org.hsqldb.ParserDDL.compileCreate(Unknown Source)
at org.hsqldb.ParserCommand.compilePart(Unknown Source)
at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
at org.hsqldb.Session.executeDirectStatement(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 61 more
I would like to know if I'm missing something about the configuration or if HSQLDB does not support trigger procedure.

Syntax of triggers in postgres and HSQLDB are not compatible.
For example if you need to creating triggers in HSQLDB, you will write it as something like below
CREATE TRIGGER my_table_trigger
BEFORE INSERT ON my_table REFERENCING NEW ROW AS NEW
FOR EACH ROW
BEGIN ATOMIC
BEGIN ATOMIC
IF NEW.id IS NULL THEN
SELECT my_table_seq.NEXTVAL INTO NEW.id FROM DUAL;
END IF;
END;
END
Which is quite similar to Oracle trigger syntax.
Database dialects usually didn't help to perform cross DB PL/SQL operations.
You should keep this point in your mind.
Wherever you need to perform any database specific functionality , you shouldn't rely on any database dialect but use native queries instead.
Also maintain different native queries for each database you want to use in your application.

Related

Get query that caused a trigger SQLite

I need to know how to get the string of the query that caused a trigger to fire in SQLite. I've found solutions for SQL, but not SQLite.

DDL command commits transaction even if it fails

I ran the below query.
insert into emp(id,name) values(1,'ONKAR');
then I wrote
Create table emp(id number(10));
it failed because emp table already exist.
then I ran
rollback;
then
select * from emp;
it is returning 1 row.
I know any DDL command after DML will commit the data. But why it is committing even when DDL command failed?
That's because Oracle issues a commit both before and after DDL, as per the documentation:
Oracle Database issues an implicit COMMIT under the following circumstances:
Before any syntactically valid data definition language (DDL) statement, even if the statement results in an error
After any data definition language (DDL) statement that completes without an error

Oracle: 'populate pending' index of another schema

When attempting to call ctx_ddl.populate_pending on an index of another schema...
call ctx_ddl.populate_pending ('OTHERSCHEMA.INDEX_NAME', null);
... I'm getting an Oracle error:
SQL-Fehler: ORA-20000: Oracle Text error:
DRG-10502: index INDEX_NAME does not exist
When I connect as OTHERSCHEMA user and execute the same statement, everything works fine.
Why does it tell me the index doesn't exist (it does, verified) here?
Am I missing any grants or anything else?
Constraint for proposed solutions: I don't want to have to use 'alter session' as a workaround.
EDIT:
Seems to be a bug in Oracle 11.2. With Oracle 12.1, the statement works fine. Treat the solution below as a workaround for Oracle 11.2.
Solved it with a delegation to a procedure in the target schema:
On target schema 'OTHERSCHEMA'
CREATE OR REPLACE PROCEDURE POPULATE_PENDING_INDEX IS
BEGIN
execute immediate 'call ctx_ddl.populate_pending(''INDEX_NAME'', NULL)';
END;
/
Execute with another schema user:
exec OTHERSCHEMA.POPULATE_PENDING_INDEX

db2 stored procedure format

I'm using db2 and SQuirreL SQL
I'm trying to create a stored procedure with a simple select statement inside of it. When I omit the select statement in the following below and run the code, the procedure is created. Also this procedure can be dropped and called.
CREATE PROCEDURE test_procedure
LANGUAGE SQL
BEGIN
END
When I add in the select statement, I get Error: DB2 SQL Error: SQLCODE=-102, SQLSTATE=42601,...
CREATE PROCEDURE test_procedure
LANGUAGE SQL
BEGIN
SELECT column_name FROM table_name
END
If you go to IBM iseries information center is says:
SQL0104 SQLCODE -104 SQLSTATE 42601
Explanation: Token &1 was not valid. Valid tokens: &2.
It appears that I wasn't given the right permissions to execute the stored procedure. SQL0551N This link explains more about the issue.
The statement terminator in SQuirreL is called "Statement separator" and it can be defined in:
Menu Session > Session Properties... > tab SQL > at the end of the SQL square, the option Statement Separator.
This is valid in version 3.5.3

Plsql statements not working with ANT

I have a file with the following content:
-- KERNEL72 - SWIFT Silver changes start
/*
drop synonym ispkss_vals
/
create synonym ispkss_vals for ispks_vals
/
*/-- KERNEL72 - SWIFT Silver changes ends after the below line
create or replace synonym ispkss_vals for ispks_vals
/
This is compiling properly in SQL Plus. But while compiling using ANT, I am getting the following error:
[sql] Failed to execute:
[sql] -- KERNEL72 - SWIFT Silver changes start
[sql] /*
[sql] drop synonym ispkss_vals
[sql] java.sql.SQLException: Invalid SQL type
[sql] Failed to execute:
[sql] create synonym ispkss_vals for ispks_vals
[sql] java.sql.SQLSyntaxErrorException: ORA-00955: name is already used by an existing object
[sql] Failed to execute:
[sql] */-- KERNEL72 - SWIFT Silver changes ends after the below line
[sql] create or replace synonym ispkss_vals for ispks_vals
[sql] java.sql.SQLSyntaxErrorException: ORA-00900: invalid SQL statement
Im using the following ANT scripts for compilation:
<sql driver="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:#10.184.1.13:1521:UPP"
userid="${UsernameB}"
password="${PasswordB}"
onerror="continue"
strictDelimiterMatching="false"
delimiter="/"
keepformat="yes">
Please advice on why ANT compilations are not proper.
Perhaps the problem is that you are using / as the statement delimiter and also trying to comment with /* ... */?
It may be treating the comment opening and closing as delimiters, creating sql statements that don't make sense. (one would start with *, etc.)