Rails PG::InvalidTextRepresentation - ERROR: invalid input syntax for type uuid - postgresql

We are migrating Rails application from MySql to Postgres. Generally, the application is loading fine.
I get the following issue if I try to update a record using update_column:
irb> parent.id
=> #<UUID:0x3fd2c1a61cf0 UUID:F2CABB99AAB84BEB8C64AD23AAC775C0>
irb> child.update_column(:parent_id, parent.id)
PG::InvalidTextRepresentation - ERROR: invalid input syntax for type uuid: "--- !ruby/object:UUIDTools::UUID
time_low: 856850911
time_mid: 49931
time_hi_and_version: 17649
clock_seq_hi_and_reserved: 165
clock_seq_low: 247
nodes:
- 179
- 116
- 149
- 190
- 190
- 157
"
LINE 1: UPDATE "children" SET "parent_id" = '--- !ruby/ob...
^
It's actually dumping the UUID YAML in resulting SQL instead of the string representation of UUID.
However, it works fine if I assign attribute and then save:
irb> child.parent_id = parent.id
irb> parent.save
=> true
Since we already have used update_column in many places in the application so we can't change it to assign and save.
rails 4.2.7.1 pg 0.21.0 activeuuid 0.6.1

Related

Easytrieve Plus and Db2 - Read a file as input to matching against Db2 table

I am running a batch job that reads in a file in with a list of templates. I am trying to find an example since the one I was provided will not work. I have tried to find any example of reading in a file via EZTPA00. The JCL is correct, but I keep getting an error. Here's the basic code followed by the error I'm getting:
LIST ON
PARM SSID('DB2G')
FILE INFILE1 VB (133 6233)
IP-REC 01 133 A
TEMPLATE 01 015 A
FILE OUFILE1 FB (100 1000)
OP-REC 01 100 A
COMMUN_TRANS_ID 01 040 A
COMMUN_TEMPLATE_NO 42 015 A
DEFINE H-CNT W 13 N
SQL DECLARE C1 CURSOR FOR +
SELECT TRANSACTION, TEMPLATE +
FROM DB2.TEMPLATE_TABLE WHERE +
TEMPLATE = INFILE1:TEMPLATE
FETCH FROM INFILE1
IF EOF INFILE1
DISPLAY 'TEMPLATE ' TEMPLATE ' NOT RETURNED'
STOP
END-IF
CLOSE INFILE1
* INPUT SETUP
JOB INPUT(INFILE1) +
START 010-INIT +
FINISH 999-END
* START THE SQL
SQL OPEN C1
DO WHILE SQLCODE NE +100
SQL FETCH C1 +
INTO :WS-TMPLT, :WS-COMMID
IF SQLCODE NE 0
DISPLAY 'PF : ERROR : SQLCODE : ' SQLCODE
STOP
END-IF
13 SQL DECLARE C1 CURSOR FOR +
SELECT COMMUN_TRANS_ID, COMMUN_TEMPLATE_NO +
FROM VMUSIU.E_COMM_DLVY WHERE +
COMMUN_TEMPLATE_NO = INFILE1:TEMPLATE
13 *******B204 SQL - SQL ERROR, SQLCODE IS -104
13 *******B204 SQL - DSNT408I SQLCODE = -104, ERROR: ILLEGAL SYMBOL "?". SOME SYMBOLS THAT MIGHT BE LEGAL
13 *******B204 SQL - ARE: AND * AT OR SELECTIVITY YEAR YEARS MONTH MONTHS DAY DAYS HOUR
13 *******B204 SQL - DSNT418I SQLSTATE = 42601 SQLSTATE RETURN CODE
I have no idea what the "?" is. I tried using a fetch for infile1 but it said it was invalid. Everything I try gives me the same answer. I even tried using ws variables, but it still failed. Does someone have something that allows you to match db2 table info against a file?

I am trying to update column where the filter is a string in Laravel 8

I tried:
Acessos::where('user_id',$uid)->where('routes','=',$routes )->update(['qtd_acessos' => 'qtd_acessos + 1'] );
the Error:
SQLSTATE[HY000]: General error: 1366 Incorrect integer value:
'qtd_acessos + 1' for column 'qtd_acessos' at row 2 (SQL: update
acessos set qtd_acessos = qtd_acessos + 1 where user_id = 3 and
routes = /home)
the question is: How to put the quotes in the routes column using eloquent?
I would use the increment method instead of update.
You can find the documantetion about it here: Database query builder

Error Number: 1064 Codigniter old version

Try to run this syntax on localhost is fine, but on hosting seem like old version of phpmysql
Error Number: 1064
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'groups as c WHERE a.user_id=b.id AND a.group_id=' at line 2
SELECT
b.id,b.first_name,b.last_name,b.username,b.email,c.name,FROM_UNIXTIME(b.created_on)
as created_on,b.active FROM users_groups as a , users as b , groups as
c WHERE a.user_id=b.id AND a.group_id=c.id
Filename: models/Users_model.php
Line Number: 40
MODEL_FILE
function get_all_query()
{
$sql = "SELECT b.id,b.first_name,b.last_name,b.username,b.email,c.name,FROM_UNIXTIME(b.created_on) as created_on,b.active
FROM users_groups as a , users as b , groups as c
WHERE a.user_id=b.id
AND a.group_id=c.id";
return $this->db->query($sql)->result();
}
Please..

creating sql function implemented in java via flyway

I'm trying to create a function like:
--#SET TERMINATOR #
CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11))
RETURNS INTEGER
RETURNS NULL ON NULL INPUT
FENCED THREADSAFE
DETERMINISTIC
NO SQL
LANGUAGE JAVA
PARAMETER STYLE JAVA
EXTERNAL NAME
'StringUtil:se.uhr.nya.commons.db.procedures.Proquint!quint2uint'
NO EXTERNAL ACTION
#
from flyway. The jar file is already installed on the server, and I can create the function without problems via clp:
~]$ db2 -v -td# -f aa.sql
CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11))
RETURNS INTEGER
RETURNS NULL ON NULL INPUT
FENCED THREADSAFE
DETERMINISTIC
NO SQL
LANGUAGE JAVA
PARAMETER STYLE JAVA
EXTERNAL NAME
'StringUtil:se.uhr.nya.commons.db.procedures.Proquint!quint2uint'
NO EXTERNAL ACTION
DB20000I The SQL command completed successfully.
I also tried creating via dbeaver from my local machine without a problem:
Updated Rows 0
Query CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11))
RETURNS INTEGER
RETURNS NULL ON NULL INPUT
FENCED THREADSAFE
DETERMINISTIC
NO SQL
LANGUAGE JAVA
PARAMETER STYLE JAVA
EXTERNAL NAME
'StringUtil:se.uhr.nya.commons.db.procedures.Proquint!quint2uint'
NO EXTERNAL ACTION
Finish time Tue Jan 11 22:14:46 CET 2022
But if I try to run the same file from flyway:
]$ flyway -schemas=NYA_FLYWAY -table="FLYWAY_SCHEMA_HISTORY" -driver=${driver} -url=jdbc:db2://${host}:${port}/${db} -user=${username} -password=${passwd} -jarDirs=${jarDirs} -locations="filesystem:${upgradedir}" migrate
A new version of Flyway is available
Upgrade to Flyway 8.4.1: https://rd.gt/2X0gakb
Flyway Community Edition 8.0.5 by Redgate
Database: jdbc:db2://130.239.91.21:50000/NYA (DB2/LINUXX8664 11.5)
Successfully validated 36 migrations (execution time 00:00.027s)
Current version of schema "NYA_FLYWAY": 22.223.100.3
Migrating schema "NYA_FLYWAY" to version "22.223.100.4"
ERROR: Migration of schema "NYA_FLYWAY" to version "22.223.100.4" failed! Changes successfully rolled back.
ERROR: Migration V22.223.100.4__.sql failed
------------------------------------
SQL State : 46008
Error Code : -20204
Message : The user defined function or procedure "NYA.QUINT_2_UINT" was unable to map to a single Java method.. SQLCODE=-20204, SQLSTATE=46008, DRIVER=4.29.24
Location : /home/lejo0004/Project/db-legacy/nya/src/main/resources/db/migration/V22.223.100/V22.223.100.4__.sql (/home/lejo0004/Project/db-legacy/nya/src/main/resources/db/migration/V22.223.100/V22.223.100.4__.sql)
Line : 3
Statement : CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11))
RETURNS INTEGER
RETURNS NULL ON NULL INPUT
FENCED THREADSAFE
DETERMINISTIC
NO SQL
LANGUAGE JAVA
PARAMETER STYLE JAVA
EXTERNAL NAME
'StringUtil:se.uhr.nya.commons.db.procedures.Proquint!quint2uint'
NO EXTERNAL ACTION
Caused by: Migration V22.223.100.4__.sql failed
------------------------------------
SQL State : 46008
Error Code : -20204
Message : The user defined function or procedure "NYA.QUINT_2_UINT" was unable to map to a single Java method.. SQLCODE=-20204, SQLSTATE=46008, DRIVER=4.29.24
Location : /home/lejo0004/Project/db-legacy/nya/src/main/resources/db/migration/V22.223.100/V22.223.100.4__.sql (/home/lejo0004/Project/db-legacy/nya/src/main/resources/db/migration/V22.223.100/V22.223.100.4__.sql)
Line : 3
Statement : CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11))
RETURNS INTEGER
RETURNS NULL ON NULL INPUT
FENCED THREADSAFE
DETERMINISTIC
NO SQL
LANGUAGE JAVA
PARAMETER STYLE JAVA
EXTERNAL NAME
'StringUtil:se.uhr.nya.commons.db.procedures.Proquint!quint2uint'
NO EXTERNAL ACTION
Caused by: com.ibm.db2.jcc.am.SqlException: The user defined function or procedure "NYA.QUINT_2_UINT" was unable to map to a single Java method.. SQLCODE=-20204, SQLSTATE=46008, DRIVER=4.29.24
I'm using the same driver with dbeaver and flyway. I also tried running it from gradle with the same error. Any clue on what might cause this issue with flyway?
There are other functions in the jar as well and all that I have tried, share the same problem as described above
FWIW, the underlying function is A Proposal for Proquints: Identifiers that are Readable, Spellable, and Pronounceable
EDIT:
The jar file is normally installed in a similar fashion as Mark demonstrated in calling-sqlj-install-jar-from-jdbc using gradle.
But to eliminate any errors there, I manually installed the jarfile on the server as:
[db2inst1#nya-01 ~]$ db2 "call sqlj.install_jar('file:///opt/nya/users/db2inst1/STRINGUTIL.jar', 'STRINGUTIL')"
SQL20201N The install, replace or remove of "DB2INST1.STRINGUTIL" failed as
the jar name is invalid. SQLSTATE=46002
[db2inst1#nya-01 ~]$ db2 "call sqlj.replace_jar('file:///opt/nya/users/db2inst1/STRINGUTIL.jar', 'STRINGUTIL')"
DB20000I The CALL command completed successfully.
[db2inst1#nya-01 ~]$ db2 "call sqlj.refresh_classes()"
DB20000I The CALL command completed successfully.
Now, on the server I can:
[db2inst1#nya-01 ~]$ db2 connect
Database Connection Information
Database server = DB2/LINUXX8664 11.5.6.0
SQL authorization ID = DB2INST1
Local database alias = EKLN_N11
[db2inst1#nya-01 ~]$ db2 -v -td# -f aa.sql
CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11))
RETURNS INTEGER
RETURNS NULL ON NULL INPUT
FENCED THREADSAFE
DETERMINISTIC
NO SQL
LANGUAGE JAVA
PARAMETER STYLE JAVA
EXTERNAL NAME
'StringUtil:se.uhr.nya.commons.db.procedures.Proquint!quint2uint'
NO EXTERNAL ACTION
DB20000I The SQL command completed successfully.
db2 "VALUES NYA.QUINT_2_UINT('aabbccddee')"
1
-----------
17
1 record(s) selected.
Using dbeaver from my workstation, against the same server/database, also works fine (so jdbc does not seem to be a problem per se):
CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11))
RETURNS INTEGER
RETURNS NULL ON NULL INPUT
FENCED THREADSAFE
DETERMINISTIC
NO SQL
LANGUAGE JAVA
PARAMETER STYLE JAVA
EXTERNAL NAME
'StringUtil:se.uhr.nya.commons.db.procedures.Proquint!quint2uint'
NO EXTERNAL ACTION
#
VALUES NYA.QUINT_2_UINT('ddeeaabbccd') #
1 |
-------+
1114113|
But if I try to run it from flyway on my workstation against the same server/database I get the error:
SQL State : 46008
Error Code : -20204
Message : The user defined function or procedure "NYA.QUINT_2_UINT" was unable to map to a single Java method.. SQLCODE=-20204, SQLSTATE=46008, DRIVER=4.29.24
The java code itself is not very exciting:
package se.uhr.nya.commons.db.procedures;
public class Proquint {
...
static int quint2uint(String quint) {
long res = 0;
for (char c : quint.toCharArray()) {
int index = indexOf(uint2consonant, c);
if (index != -1) {
res <<= 4;
res += index;
} else {
index = indexOf(uint2vowel, c);
if (index != -1) {
res <<= 2;
res += index;
}
}
}
return (int) res;
}
I used the same user/passwd for all 3 cases (clp, dbeaver. flyway)
EDIT2:
I did a small test program:
import java.sql.*;
public class tst {
public static void main(String [] args) {
String urlPrefix = "jdbc:db2:";
String url;
String user;
String password;
String dummy;
Connection con;
Statement stmt;
ResultSet rs;
System. out.println ("**** Enter class tst" );
if (args.length !=3)
{
System. err.println ("Invalid value. First argument appended to " +
"jdbc:db2: must specify a valid URL." );
System. err.println ("Second argument must be a valid user ID." );
System. err.println ("Third argument must be the password for the user ID.");
System. exit(1);
}
url = urlPrefix + args[0];
user = args[1];
password = args[2];
try {
Class. forName("com.ibm.db2.jcc.DB2Driver");
System. out.println("**** Loaded the JDBC driver" );
con = DriverManager. getConnection(url, user, password);
con.setAutoCommit( false);
System. out.println("**** Created a JDBC connection to the data source");
stmt = con.createStatement();
System. out.println("**** Created JDBC Statement object" );
String s = "CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11)) ";
s += "RETURNS INTEGER ";
s += "RETURNS NULL ON NULL INPUT ";
s += "FENCED THREADSAFE ";
s += "DETERMINISTIC ";
s += "NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA ";
s += "EXTERNAL NAME 'StringUtil:se.uhr.nya.commons.db.procedures.Proquint!quint2uint' ";
s += "NO EXTERNAL ACTION";
//stmt.executeUpdate(s);
stmt.execute(s);
System. out.println("**** Created function" );
s = "values NYA.QUINT_2_UINT('aabbccddeeg')";
rs = stmt.executeQuery(s);
while (rs.next()) {
dummy = rs.getString(1);
System. out.println("number = " + dummy);
}
System. out.println("**** Fetched all rows from JDBC ResultSet" );
rs.close();
System. out.println("**** Closed JDBC ResultSet" );
// Close the Statement
stmt.close();
System. out.println("**** Closed JDBC Statement" );
// Connection must be on a unit-of-work boundary to allow close
con.commit();
System. out.println ( "**** Transaction committed" );
con.close();
System. out.println("**** Disconnected from data source" );
System. out.println("**** JDBC Exit from class tst - no errors" );
}
catch(ClassNotFoundException e) {
System. err.println("Could not load JDBC driver" );
System. out.println("Exception: " + e);
e.printStackTrace();
}
catch(SQLException ex) {
System. err.println("SQLException information" );
while(ex!=null ) {
System. err.println ("Error msg: " + ex.getMessage());
System. err.println ("SQLSTATE: " + ex.getSQLState());
System. err.println ("Error code: " + ex.getErrorCode());
ex.printStackTrace();
ex = ex.getNextException(); // For drivers that support chained exceptions
}
}
}
}
and compared the jdbc trace for that with a jdbc trace for flyway. The flyway trace looks like:
[jcc][Time:2022-01-13-12:22:49.714][Thread:main][Statement#275fe372]setEscapeProcessing (false) called
[jcc][Thread:main][SystemMonitor:start]
[jcc][Time:2022-01-13-12:22:49.714][Thread:main][Statement#275fe372]execute (CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11)) RETURNS INTEGER RETURNS NULL ON NULL INPUT FENCED THREADSAFE DETERMINISTIC NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA EXTERNAL NAME 'STRINGUTIL:se.uhr.nya.commons.db.procedures.Proquint!quint2uint' NO EXTERNAL ACTION) called
[jcc][Time:2022-01-13-12:22:49.714][Thread:main][Statement#275fe372]stmt_bidiTransform (CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11)) RETURNS INTEGER RETURNS NULL ON NULL INPUT FENCED THREADSAFE DETERMINISTIC NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA EXTERNAL NAME 'STRINGUTIL:se.uhr.nya.commons.db.procedures.Proquint!quint2uint' NO EXTERNAL ACTION) called
[jcc][Time:2022-01-13-12:22:49.714][Thread:main][Statement#275fe372]stmt_bidiTransform not enabled (CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11)) RETURNS INTEGER RETURNS NULL ON NULL INPUT FENCED THREADSAFE DETERMINISTIC NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA EXTERNAL NAME 'STRINGUTIL:se.uhr.nya.commons.db.procedures.Proquint!quint2uint' NO EXTERNAL ACTION) called
[jcc][t4][time:2022-01-13-12:22:49.714][Thread:main][tracepoint:1][Request.flush]
whereas the test program:
[jcc][Thread:main][SystemMonitor:start]
[jcc][Time:2022-01-13-12:22:28.089][Thread:main][Statement#1372ed45]execute (CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11)) RETURNS INTEGER RETURNS NULL ON NULL INPUT FENCED THREADSAFE DETERMINISTIC NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA EXTERNAL NAME 'StringUtil:se.uhr.nya.commons.db.procedures.Proquint!quint2uint' NO EXTERNAL ACTION) called
[jcc][Time:2022-01-13-12:22:28.089][Thread:main][Statement#1372ed45]stmt_bidiTransform (CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11)) RETURNS INTEGER RETURNS NULL ON NULL INPUT FENCED THREADSAFE DETERMINISTIC NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA EXTERNAL NAME 'StringUtil:se.uhr.nya.commons.db.procedures.Proquint!quint2uint' NO EXTERNAL ACTION) called
[jcc][Time:2022-01-13-12:22:28.089][Thread:main][Statement#1372ed45]stmt_bidiTransform not enabled (CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11)) RETURNS INTEGER RETURNS NULL ON NULL INPUT FENCED THREADSAFE DETERMINISTIC NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA EXTERNAL NAME 'StringUtil:se.uhr.nya.commons.db.procedures.Proquint!quint2uint' NO EXTERNAL ACTION) called
>>> [jcc][t4] [time:2022-01-13-12:22:28.089][Thread:main]
>>> [tracepoint:10]SetClientPiggybackCommand: flowToServerNeeded() = true
>>> [jcc][t4] [time:2022-01-13-12:22:28.089][Thread:main]
>>> [tracepoint:10]SetClientPiggybackCommand: flowToServerNeeded() = true
[jcc][t4][time:2022-01-13-12:22:28.089][Thread:main][tracepoint:1][Request.flush]
I.e. the test program does:
SetClientPiggybackCommand: flowToServerNeeded() = true
before Request.flush
but whether that is relevant or not I don't know yet
EDIT3:
[db2inst1#nya-03 ~]$ ls -lR sqllib/function/
sqllib/function/:
totalt 0
lrwxrwxrwx. 1 root db2iadm1 35 14 sep 14.15 db2json -> /opt/ibm/db2/V11.5/function/db2json*
lrwxrwxrwx. 1 root db2iadm1 36 14 sep 14.15 db2psmds -> /opt/ibm/db2/V11.5/function/db2psmds*
lrwxrwxrwx. 1 root db2iadm1 35 14 sep 14.15 db2rtsc -> /opt/ibm/db2/V11.5/function/db2rtsc*
lrwxrwxrwx. 1 root db2iadm1 34 14 sep 14.15 fpeevm -> /opt/ibm/db2/V11.5/function/fpeevm*
drwxrwxr-x. 3 db2inst1 db2iadm1 22 1 mar 2021 jar/
lrwxrwxrwx. 1 root db2iadm1 37 14 sep 14.15 libdb2u.a -> /opt/ibm/db2/V11.5/function/libdb2u.a*
drwxrwsr-t. 2 db2inst1 db2iadm1 6 23 feb 2021 routine/
lrwxrwxrwx. 1 root db2iadm1 33 14 sep 14.15 tblpd -> /opt/ibm/db2/V11.5/function/tblpd*
drwxrwsr-t. 2 db2inst1 db2iadm1 37 14 sep 14.15 unfenced/
sqllib/function/jar:
totalt 0
drwxrwxr-x. 2 db2inst1 db2iadm1 28 13 jan 09.48 DB2INST1/
sqllib/function/jar/DB2INST1:
totalt 12
-rw-rw-r--. 1 db2inst1 db2iadm1 8934 13 jan 09.48 STRINGUTIL.jar
sqllib/function/routine:
totalt 0
sqllib/function/unfenced:
totalt 0
lrwxrwxrwx. 1 root db2iadm1 44 14 sep 14.15 asnqmon -> /opt/ibm/db2/V11.5/function/unfenced/asnqmon*
lrwxrwxrwx. 1 root db2iadm1 45 14 sep 14.15 db2gsead -> /opt/ibm/db2/V11.5/function/unfenced/db2gsead*
I think I have found what caused the problem, atleast I can now create the function without a problem. The root cause is that Flyway appears to:
SET CURRENT_SCHEMA = <variable assigned via property -schemas>
When this is changed from the instance owner, db2 is unable to find the jar file. If I change the migration to:
set CURRENT SCHEMA = 'DB2INST1' #
CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11))
RETURNS INTEGER
RETURNS NULL ON NULL INPUT
FENCED THREADSAFE DETERMINISTIC
NO SQL
LANGUAGE JAVA
PARAMETER STYLE JAVA
EXTERNAL NAME 'STRINGUTIL:se.uhr.nya.commons.db.procedures.Proquint!quint2uint'
NO EXTERNAL ACTION #
Everything works as expected. I'm not to excited about having to set current_path in the migration (and I'm not sure what effect it will have on Flyway), so I'll have a look if there is another property that can be used to assign a schema for FLYWAY_SCHEMA_HISTORY. But this works for now.
EDIT:
The following migration works if I remove -schemas as an argument to Flyway:
--#SET TERMINATOR #
values ('CURRENT SCHEMA', cast(CURRENT SCHEMA as varchar(100))) #
CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11)) RETURNS INTEGER RETURNS NULL ON NULL INPUT FENCED THREADSAFE DETERMINISTIC NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA EXTERNAL NAME 'STRINGUTIL:se.uhr.nya.commons.db.procedures.Proquint!quint2uint' NO EXTERNAL ACTION #
values NYA.QUINT_2_UINT('aabbccddeef') #
flyway -table="FLYWAY_SCHEMA_HISTORY" -driver=${driver} -url=jdbc:db2://${host}:${port}/${db} -user=${username} -password=${passwd} -jarDirs=${jarDirs} -locations="filesystem:${upgradedir}" migrate
Flyway is up to date
Flyway Community Edition 8.4.1 by Redgate
Database: jdbc:db2://130.239.91.235:50000/nyax (DB2/LINUXX8664 11.5)
----------------------------------------
Flyway Teams features are enabled by default for the next 27 days. Learn more at https://rd.gt/3A4IWym
----------------------------------------
Successfully validated 1 migration (execution time 00:00.017s)
Creating Schema History table "DB2INST1"."FLYWAY_SCHEMA_HISTORY" ...
Current version of schema "DB2INST1": << Empty Schema >>
Migrating schema "DB2INST1" to version "22.223.100.4"
+----------------+----------+
| 1 | 2 |
+----------------+----------+
| CURRENT SCHEMA | DB2INST1 |
+----------------+----------+
+-----+
| 1 |
+-----+
| 274 |
+-----+
If I add a specific schema as in:
flyway -schemas=NYA_FLYWAY -table="FLYWAY_SCHEMA_HISTORY" -driver=${driver} -url=jdbc:db2://${host}:${port}/${db} -user=${username} -password=${passwd} -jarDirs=${jarDirs} -locations="filesystem:${upgradedir}" migrate
Flyway is up to date
Flyway Community Edition 8.4.1 by Redgate
Database: jdbc:db2://130.239.91.235:50000/nyax (DB2/LINUXX8664 11.5)
----------------------------------------
Flyway Teams features are enabled by default for the next 27 days. Learn more at https://rd.gt/3A4IWym
----------------------------------------
Creating schema "NYA_FLYWAY" ...
Creating Schema History table "NYA_FLYWAY"."FLYWAY_SCHEMA_HISTORY" ...
Current version of schema "NYA_FLYWAY": null
Migrating schema "NYA_FLYWAY" to version "22.223.100.4"
+----------------+------------+
| 1 | 2 |
+----------------+------------+
| CURRENT SCHEMA | NYA_FLYWAY |
+----------------+------------+
ERROR: Migration of schema "NYA_FLYWAY" to version "22.223.100.4" failed! Changes successfully rolled back.
CURRENT_SCHEMA is changed to NYA_FLYWAY and I assume this is why Db2 can not locate the jar file. If I explicitly set CURRENT_SCHEMA in the migration:
--#SET TERMINATOR #
set CURRENT_SCHEMA = 'DB2INST1' #
values ('CURRENT SCHEMA', cast(CURRENT SCHEMA as varchar(100))) #
...
It once again works as expected:
flyway -schemas=NYA_FLYWAY -table="FLYWAY_SCHEMA_HISTORY" -driver=${driver} -url=jdbc:db2://${host}:${port}/${db} -user=${username} -password=${passwd} -jarDirs=${jarDirs} -locations="filesystem:${upgradedir}" migrate
Flyway is up to date
Flyway Community Edition 8.4.1 by Redgate
Database: jdbc:db2://130.239.91.235:50000/nyax (DB2/LINUXX8664 11.5)
----------------------------------------
Flyway Teams features are enabled by default for the next 27 days. Learn more at https://rd.gt/3A4IWym
----------------------------------------
Successfully validated 2 migrations (execution time 00:00.018s)
Current version of schema "NYA_FLYWAY": null
Migrating schema "NYA_FLYWAY" to version "22.223.100.4"
+----------------+----------+
| 1 | 2 |
+----------------+----------+
| CURRENT SCHEMA | DB2INST1 |
+----------------+----------+
+-----+
| 1 |
+-----+
| 274 |
+-----+
Also, if I change my little test prog so that it sets current_schema to 'NYA_FLYWAY' before creating the function, I get the same error:
java -cp .:/home/lejo0004/db2jcc4.jar tst //nya-03.its.umu.se:50000/nyax db2inst1 $passwd
**** Enter class tst
**** Loaded the JDBC driver
**** Created a JDBC connection to the data source
**** Created JDBC Statement object
CURRENT SCHEMA = NYA_FLYWAY
SQLException information
Error msg: DB2 SQL Error: SQLCODE=-20204, SQLSTATE=46008, SQLERRMC=NYA.QUINT_2_UINT, DRIVER=4.29.24
SQLSTATE: 46008
Error code: -20204
com.ibm.db2.jcc.am.SqlException: DB2 SQL Error: SQLCODE=-20204, SQLSTATE=46008, SQLERRMC=NYA.QUINT_2_UINT, DRIVER=4.29.24
at com.ibm.db2.jcc.am.b7.a(b7.java:815)
at com.ibm.db2.jcc.am.b7.a(b7.java:66)
at com.ibm.db2.jcc.am.b7.a(b7.java:140)
at com.ibm.db2.jcc.am.k9.c(k9.java:2844)
at com.ibm.db2.jcc.am.k9.d(k9.java:2828)
at com.ibm.db2.jcc.am.k9.b(k9.java:2188)
at com.ibm.db2.jcc.t4.ab.k(ab.java:444)
at com.ibm.db2.jcc.t4.ab.c(ab.java:102)
at com.ibm.db2.jcc.t4.p.b(p.java:38)
at com.ibm.db2.jcc.t4.av.h(av.java:124)
at com.ibm.db2.jcc.am.k9.ak(k9.java:2183)
at com.ibm.db2.jcc.am.k9.a(k9.java:3387)
at com.ibm.db2.jcc.am.k9.e(k9.java:1135)
at com.ibm.db2.jcc.am.k9.execute(k9.java:1114)
at tst.main(tst.java:61)
FWIW, this can also be reproduced via clp:
[db2inst1#nya-03 ~]$ db2 "set current_schema = 'DB2INST1'"
DB20000I The SQL command completed successfully.
[db2inst1#nya-03 ~]$ db2 "CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11))
RETURNS INTEGER
RETURNS NULL ON NULL INPUT
FENCED THREADSAFE
DETERMINISTIC
NO SQL
LANGUAGE JAVA
PARAMETER STYLE JAVA
EXTERNAL NAME
'StringUtil:se.uhr.nya.commons.db.procedures.Proquint!quint2uint'
NO EXTERNAL ACTION"
DB20000I The SQL command completed successfully.
[db2inst1#nya-03 ~]$ db2 "set current_schema = 'NYA_FLYWAY'"
DB20000I The SQL command completed successfully.
[db2inst1#nya-03 ~]$ db2 "CREATE OR REPLACE FUNCTION NYA.QUINT_2_UINT( I VARCHAR(11))
RETURNS INTEGER
RETURNS NULL ON NULL INPUT
FENCED THREADSAFE
DETERMINISTIC
NO SQL
LANGUAGE JAVA
PARAMETER STYLE JAVA
EXTERNAL NAME
'StringUtil:se.uhr.nya.commons.db.procedures.Proquint!quint2uint'
NO EXTERNAL ACTION"
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL20204N The user defined function or procedure "NYA.QUINT_2_UINT" was
unable to map to a single Java method. LINE NUMBER=10. SQLSTATE=46008
One might ask why I insist on setting schema- and table- for flyway. As for the table name, the reason is that Flyway otherwise creates them with as quoted identifiers in lowercase. It is a painful experience having to quote these identifiers every time you need to query the table (especially when querying the table from sh). Unfortunately I have not found a way to influence Flyway to behave when it comes to the name for columns, so you will still have to quote them as in:
db2 "select \"version\" from ..."
I tried manually creating the table, but the flyway fails to handle it. I have not tried it yet, but I may add generated columns or a view for the purpose.
As for the schema name, I've got several products that run their own instance of Flyway. It feels much easier to use the schema + "_FLYWAY" for their instance. I don't want to put the flyway table in the product schema since I run validation scripts on the schema before each committed version.
I also would like to add that I only tried this with flyway community 8.4.1, there may be some other error with flyway community 8.0.5 which I started with
Many thanks to mao and Mark for their input (this will probably be removed but now I have added it:-)

NotImplementedError when calling .alter() (0.13.1)

I am on datajoint python 0.13.1.
When executing .alter() on a table in my schema I am getting the following error message:
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-43-f79406c4b690> in <module>
----> 1 MyTable.alter()
/opt/miniconda3/envs/analysis/lib/python3.6/site-packages/datajoint/table.py in alter(self, prompt, context)
102 del frame
103 old_definition = self.describe(context=context, printout=False)
--> 104 sql, external_stores = alter(self.definition, old_definition, context)
105 if not sql:
106 if prompt:
/opt/miniconda3/envs/analysis/lib/python3.6/site-packages/datajoint/user_tables.py in definition(self)
75 """
76 raise NotImplementedError(
---> 77 'Subclasses of Table must implement the property "definition"')
78
79 #ClassProperty
NotImplementedError: Subclasses of Table must implement the property "definition"
What am I doing wrong?
Makes sense. Currently, alter can only change secondary attributes. I cannot yet modify foreign keys, primary key, and indexes. Issue #901 explains this in part: https://github.com/datajoint/datajoint-python/issues/901
The workaround currently is to use SQL ALTER command, which you can issue using dj.conn().query(....). If you show your before and after table definitions, I will be able to generate the full ALTER command.
One of the problems was that I didn't load the schema code directly. However, then the error message changes to:
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-6-f79406c4b690> in <module>
----> 1 MyTable.alter()
/opt/miniconda3/envs/analysis/lib/python3.6/site-packages/datajoint/table.py in alter(self, prompt, context)
102 del frame
103 old_definition = self.describe(context=context, printout=False)
--> 104 sql, external_stores = alter(self.definition, old_definition, context)
105 if not sql:
106 if prompt:
/opt/miniconda3/envs/analysis/lib/python3.6/site-packages/datajoint/declare.py in alter(definition, old_definition, context)
370 raise NotImplementedError('table.alter cannot alter foreign keys (yet).')
371 if index_sql != index_sql_:
--> 372 raise NotImplementedError('table.alter cannot alter indexes (yet)')
373 if attribute_sql != attribute_sql_:
374 sql.extend(_make_attribute_alter(attribute_sql, attribute_sql_, primary_key))
NotImplementedError: table.alter cannot alter indexes (yet)