Get query that caused a trigger SQLite - sql

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.

Related

how to fix this error:ddl statement interferred with query replan?

database : vertica
when I use insert into.....select.... statement to add data, following error occurred:
notice : error encounterred in contriant validation
error : ddl statement interferred with query plan
hint : please reissue query
This error, although it is not the actual error, is pretty self explanatory. You tried to issue an INSERT statement, but there was another DDL statement that interfered (was holding a lock on the table) at the same time and so your INSERT statement was killed.
At this point you probably won't be able to see it any more, but in the future when you see this error, take note of the time that the statement was executed, then query the v_monitor.query_requests system table to see what other DDL statements were being executed at the same time.
If this was just an ad hoc INSERT statement, then the solution is to do exactly what the Vertica notice message said, re-issue the query. If this is part of a script or application logic, then you need to handle this error accordingly and add the logic to re-issue the statement again if this error is thrown.

Insert works in SQL Client but not in my code (SQL7008)

I am trying to perform insert/update statements in a DB2-AS400 database.
I use the jt400 driver, version 9.5 for java 8 in order to be able to connect and dialog with my DB.
In my app, I can perform selects just fine but when I try to insert or update I get the following SQL Error:
[SQL7008] Table not valid for operation.
I have done some research and it seems that it would be a journaling problem on the DB side and not in my code.
What I would like to understand is why am I able to perform insert/update using my SQL Client (DBeaver) on the same table with the exact same user ?
You might try disabling transaction isolation by adding transaction isolation=none to your connection string:
jdbc:as400://systemname;naming=sql;errors=full;transaction isolation=none;date format=iso
Ref: SQL7008 Error - Workaround?

Numeric overflow error while Truncating table in Oracle

Truncate table test_abc;
It is giving me error :
Oracle error 01426: Numeric Overflow.
Oracle version is 11g.
I agree with Alex Poole that it seems odd for a TRUNCATE to cause that error. Perhaps there is an error with a recursive SQL or PL/SQL statement that executes with
each truncate. Post the entire error message, it should include the relevant errors, objects, and line numbers.
If that doesn't help, look for any triggers that execute for each truncate. There are many potentially relevant triggering events. These are the most likely, but it's
also possible there is an INSERT, UPDATE, or DELETE trigger on an X$ table or something odd.
select *
from dba_triggers
where triggering_event like '%DDL%' or triggering_event like '%TRUNCATE%';
The objects can be viewed through DBA_SOURCE, unless they are wrapped.

Oracle - Obtain the SQL as a string when an exception occurs

I am trying to get the SQL query to be returned from a database call, when the query fails to execute and the return cursor has a failure state. This query string will be used for logging purposes.
One way to do this is to hold a variable that contains the SQL query as a string, and then wrap each query in the PL/SQL block with the exception handler and if an exception arises, return the query string with the failure status to the UI component.
Is there a better way to do this? Does Oracle exception object or any other package support this feature?
This question seems like a duplicate for the thread: Obtain the Query/CommandText that caused a SQLException
However, I did not find a solution to the problem in that thread, and I would like to know if there are any new packages supported by Oracle that gives us the query string that caused the exception to occur.
When you are calling the database from an external language (Java, C#) you can probably do it, by implementing your own JDBC (or whatever) driver.
You would do so by delegating the real world to a normal driver, but whenever a statement is sent to the database you remember the statement and if causes an exception you create a new exception which also includes the sql statement (and possibly bind variables).
Note that this will only give you your statement. If you execute a stored procedure or cause a trigger to fire which in turn fails you only get the original statement not the one that actually failed.

Rails 3.x How to write update all based on row value?

I would like the following SQL query to be executed in a migration file after adding a column (updating the new field with existing column value from the same row)
UPDATE users SET last_login=updated_at;
The SQL statements work properly when executed on the database, but in rails I tried multiple syntax using the ActiveRecord update_all method but without success
User.update_all("last_login=updated_at")
I get the following error
ActiveRecord::StatementInvalid: PGError: ERROR: current transaction is aborted, commands ignored until end of transaction block
: UPDATE "users" SET last_login=updated_at
Obviously something is missing in my syntax, but can't figure out what.
Can anyone point me to the right syntax?
Regards/J.
Syntax is indeed correct, the issue was relying in the fact that I had to rollback the previous transaction.
User.update_all("last_login=updated_at")
This statement works properly.