I'm using liquibase to execute oracle scripts. This oracle scripts, are executing merge into statements for oracle, this work fine, but the problem is that the data that I need to insert have strange characters, so in order to work we are using SET DEFINE OFF (at the beginning of the file) and SET DEFINE ON (at the end of the file) in order to avoid the errors.
But if I try to run the same script in liquiBase is not working and I get this error:
Liquibase Update Failed: Error executing SQL SET DEFINE OFF
My changelog looks like this:
<changeSet author="e-ballo" id="nopa_data_email" dbms="oracle" >
<sqlFile path="email/NOPA_ACTIVATE_SECURITY.sql" relativeToChangelogFile="true" splitStatements="true" stripComments="true" />
Anyone know how to avoid this problem ?
Thanks in advance
SET DEFINE is not SQL but a SQL*Plus command. SQL*Plus is an Oracle proprietary client, and most other clients (such as IDEs) don't recognise its commands.
The Liquibase forums suggest using CDATA as the best way to pass non-standard characters. Find out more.
Related
I am trying to run the following Firebird SQL query in LibreOffice, which has embedded Firebird:
SELECT RDB$GET_CONTEXT('SYSTEM', 'ENGINE_VERSION') AS "VERSION"
FROM "RDB$DATABASE";
I get the message Syntax error in SQL statement. Can anyone tell me what I am doing wrong? This works in FlameRobin, but not in LibreOffice.
The error "Syntax error in SQL statement" is a HSQLDB error. So, first, make sure your LibreOffice Base project is actually created as a Firebird Embedded project.
I was able to reproduce the error in LibreOffice Base 6.4.4.2 with a Firebird Embedded project. It looks like LibreOffice first tries to parse the query using HSQLDB (probably to be able to transform HSQLDB syntax to Firebird syntax), and only then forwards it to Firebird.
The cause of the error is the $ in RDB$GET_CONTEXT which is not a valid character in an unquoted object name in the HSQLDB SQL syntax, while it is valid in the Firebird SQL syntax. Normally, double quoting the specific object name would solve this, but RDB$GET_CONTEXT is not actually a function, but a syntax construct, so it can't be quoted in Firebird.
To be able to execute this query, you need to enable the 'Run SQL command directly' option in the SQL View, either under Edit > 'Run SQL command directly', or using the 'Run SQL command directly' button in the toolbar (database icon with >_).
I'm trying to apply a liquibase changeset in sql format with valid PostgreSQL syntax. The query contains a ? operator and a regexp with ? special character.
When running this query against DB from psql everything works perfect.
When I try to apply this changeset with liquibase, I get an error:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
Looks like liquibase considers ? a prepared statement argument and fails. I don't have any prepared statements in my query and I don't want liquibase to transform my query to a prepared statement.
I've found a workaround for a ? operator (substituting it with double ?? seems to work, though undocumented), but there is no workaround for regexp.
How can I set liquibase to just run the query against my DB as is?
Found help here
Reference usage with liquibase:
<changeSet id="1234" author="xyz">
<sql>
UPDATE blog
SET blog__metadata = blog__metadata::JSONB - 'someUnwantedKey',
WHERE blog__metadata::JSONB ?? 'someUnwantedKey';
</sql>
</changeSet>
I'm trying to use multiple contexts support in Liquibase and I can't achieve the result. My changeset in SQL format looks as follows
--changeset bkolasa:1 context:new-db and !edb dbms:postgresql
Then when I execute command
java -jar liquibase.jar --contexts=new-db,edb --driver=org.postgresql.Driver --url=jdbc:postgresql://example.com:5432/liqtest?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory --username=liqtest --password=liqtest --changeLogFile=mychangelog.sql update
the changeset is still loaded.
My version of Liquibase is 3.2.2.
-- changeset istepniak:db-1.14.1 context:dev and test
This works for me
–context=dev,qa worked for me.
With Liquibase 3.2, support was added to for context expressions in changeSets.
An example: context=”qa or (dev and release)”
Newer versions have label which can be used for complex business cases.
Have you tried specifying the context at runtime as follows?
--contexts="new-db and edb"
If you want a change set to be executed in two contexts, namely dev and test, you probably want to use or instead of and:
or requires only one of the contexts.
and requires all contexts.
For example, the following change set will be applied in dev context, and it will also be applied in the test context:
-- changeset istepniak:db-1.14.1 context:dev or test
Instead, the following change set needs both contexts to be present:
-- changeset istepniak:db-1.14.1 context:dev and oracle
Context
We're changing our install scripts to use ant's "sql" task and jdbc rather than proprietary sql clients sqlplus (oracle) and osql (msft).
Updated: added more context. Our "base data" (seed data) consists of a collection of .sql files containing "vendor-neutral"(i.e. works both in oracle and mssql) sql statements.
The Problem
The scripts run fine, with one exception:
This sql fails in Oracle. Specifically, something (ant or jdbc driver) treats the dashes/hyphens as "beginning of a comment"--even though they are embedded in a string. Note that the same sql works fine with ant/sql and microsoft's jdbc driver.
INSERT INTO email_client (email_client_id,generated_reply_text) VALUES(100002,'----- Original Message -----');
Related Bug
This ant bug appears to identify the problem. As it's still open (after 8 years), I'm not hoping for a fix soon. However, because the problem appears only in oracle, it may lie with the driver.
The oracle driver: jdbc thin driver, version 10.2.0.1.0
The Question
Does anyone have a workaround which works in both mssql and oracle? (e.g. changing the offending lines to define an escape character? I don't see an 'escape' on the 'insert' sql92 syntax)
thanks
After viewing the 'SQLExec' source and turning on verbose logging, I found a workaround:
Workaround
if the sql statement includes a string containing '--', place the delimiter (semi-colon) on the next line.
This Fails
INSERT INTO email_client (email_client_id,generated_reply_text) VALUES(100002,'----- Original Message -----');
This Succeeds
Note that semi-colon is on a separate line
INSERT INTO email_client (email_client_id,generated_reply_text) VALUES(100002,'----- Original Message -----')
;
Details
Turning on verbose logging, I saw that when Ant came across the offending sql statement, it actually passed three sql statements in at once to the jdbc driver. The offending statement, the next statement (which also included an embedded '--'), and the subsequent statement (which did not include an embedded '--').
I gave the Ant code a quick glance and didn't see any obvious errors. Since I wasn't planning to patch Ant, I looked for a workaround.
Tweaking with it I found that if I simply moved the delimiter (semicolon) to the next line for the statements with embedded '--', the scripts executed successfully.
thanks everyone for weighing in
You could try this:
INSERT INTO email_client (email_client_id,generated_reply_text)
VALUES(100002,LPAD('-',5,'-') || ' Original Message ' || LPAD('-',5,'-'));
I have an oracle script that I am trying to convert to valid db2 syntax. Within this sql file I have various calls to other sql files passing in a parameter using the '#' syntax.
e.g.
#script1 param1
#script2 param2
Can anyone help me with valid db2 equivalent statements? Is there an equivalent run command in db2? is it possible to pass parameters to a sql script in db2?
thanks,
smauel
The thing you are after is the DB2 Command Line Processor (CLP).
If you want to execute a script, you would execute in the CLP:
db2 -vtf script1
-f tells the CLP to run command input from the given file.
Here's the full list of options.
Unfortunately db2 doesn't support passing parameters to a script. You would have to combine your db2 -vtf commands with other scripting commands (such as sed) to generate the scripts for you, as in this example.
1) place the filename.sql file in SQLLIB/BIN
2) run db2cmd
3) execute this to connect to the required db
db2 connect to *dbname* user *userid* using *password*
4) excute this command
db2 -vtf *filename.sql*
This should execute the sql statements in the file one by one. The sql statements must be ending with a semicolon
There is an easier way for passing in parameters, that works fine for us (it might not work with (complex) multiline sql statements).
Convert your sql-script into a shell script by adding 'db2 ' at the beginning of each line. Than you can use the standard variable replacement syntax from your shell in your scripts.
so instead of
insert ...
update ...
you will have
db2 insert ...
db2 update ...
Place file in one directory.
Open db2cmd.exe as administrator
Navigate to directory where you have place the script
type db2 -vtf `