'no such function' error on sqlite UPDATE - sql

Summary:
I am trying to update a database that contains metadata for many scientific articles. In particular, the database is for the Papers application. My problem is that when I try to UPDATE a table, I get
Error: no such function: enableTransactionLog.
What is the problem? If you don't know, can you point me to where I should look for debugging? I've done a lot of searching on SO and Google, but I can't find anything that helps me.
More background:
An overview of my table:
sqlite> PRAGMA table_info(Publication);
0|ROWID|INTEGER|0||1
1|abbreviation|TEXT|0||0
2|accepted_date|TEXT|0||0
3|attributed_subtitle|TEXT|0||0
4|attributed_title|TEXT|0||0
5|author_string|TEXT|0||0
6|author_year_string|TEXT|0||0
7|body|TEXT|0||0
8|bundle|TEXT|0||0
9|bundle_string|TEXT|0||0
10|canonical_title|TEXT|0||0
11|citekey|TEXT|0||0
...I cut off the last ~50 lines of output
My command:
sqlite> UPDATE Publication SET citekey=NULL;
Error: no such function: enableTransactionLog
The schema.
CREATE TABLE "Publication" (ROWID INTEGER PRIMARY KEY, abbreviation TEXT, accepted_date TEXT, attributed_subtitle TEXT, attributed_title TEXT, author_string TEXT, author_year_string TEXT, body TEXT, bundle TEXT, bundle_string TEXT, canonical_title TEXT, citekey TEXT, citekey_base TEXT, copyright TEXT, created_at DOUBLE, document_number TEXT, doi TEXT, draft INTEGER, editor_string TEXT, endpage TEXT, extensible_properties BLOB, factor FLOAT, flagged INTEGER, full_author_string TEXT, full_editor_string TEXT, full_photographer_string TEXT, full_translator_string TEXT, imported_date DOUBLE, initial TEXT, institution TEXT, keyword_string TEXT, kind TEXT, label INTEGER, language TEXT, lastread_date DOUBLE, location TEXT, manuscript INTEGER, marked_deleted INTEGER, marked_duplicate INTEGER, marked_edited INTEGER, matched INTEGER, newly_added INTEGER, notes TEXT, number TEXT, open_access INTEGER, photographer_string TEXT, place TEXT, printed_date DOUBLE, privacy_level INTEGER, publication_count INTEGER, publication_date TEXT, publication_string TEXT, publisher TEXT, quality INTEGER, rating INTEGER, read_status INTEGER, refreshed_at DOUBLE, revision_date TEXT, searchresult INTEGER, startpage TEXT, status TEXT, submission_date TEXT, subtitle TEXT, subtype INTEGER, summary TEXT, tag_string TEXT, times_cited INTEGER, times_read INTEGER, title TEXT, translator_string TEXT, type INTEGER, update_count INTEGER, updated_at DOUBLE, user_label TEXT, uuid TEXT UNIQUE NOT NULL, version TEXT, volume TEXT, FOREIGN KEY (bundle) REFERENCES Publication (uuid) ON DELETE RESTRICT);
CREATE INDEX Publication_abbreviation_IDX ON Publication (abbreviation);
CREATE INDEX Publication_accepted_date_IDX ON Publication (accepted_date);
CREATE INDEX Publication_citekey_IDX ON Publication (citekey);
CREATE INDEX Publication_citekey_base_IDX ON Publication (citekey_base);
CREATE INDEX Publication_created_at_IDX ON Publication (created_at);
CREATE INDEX Publication_doi_IDX ON Publication (doi);
CREATE INDEX Publication_endpage_IDX ON Publication (endpage);
CREATE INDEX Publication_factor_IDX ON Publication (factor);
CREATE INDEX Publication_imported_date_IDX ON Publication (imported_date);
about 50 lines of output deleted here
CREATE INDEX Publication_version_IDX ON Publication (version);
CREATE INDEX Publication_volume_IDX ON Publication (volume);
CREATE TRIGGER _del_log_Publication AFTER DELETE ON Publication WHEN enableTransactionLog() AND (OLD."searchresult" <> 1 AND NOT (OLD."type" < 0 AND OLD."type" > -1000)) BEGIN
INSERT INTO changeLog (modifiedDate, modTable, modUUID, modType, modColumn, modValue, device, dbRevision) VALUES ((strftime("%s", "now") + strftime("%f", "now") - strftime("%S", "now")), "Publication", OLD."uuid", 1, NULL, NULL, device(), dbRevision());END;
CREATE TRIGGER _del_log_Publication_Bundle AFTER DELETE ON Publication WHEN enableTransactionLog() AND (OLD."searchresult" <> 1 AND (OLD."type" < 0 AND OLD."type" > -1000)) BEGIN
INSERT INTO changeLog (modifiedDate, modTable, modUUID, modType, modColumn, modValue, device, dbRevision) VALUES ((strftime("%s", "now") + strftime("%f", "now") - strftime("%S", "now")), "Publication", OLD."uuid", 1, "abbreviation,accepted_date,attributed_subtitle,attributed_title,body,bundle,canonical_title,citekey,citekey_base,copyright,created_at,document_number,doi,draft,endpage,extensible_properties,factor,flagged,imported_date,initial,institution,kind,label,language,lastread_date,location,manuscript,marked_deleted,marked_duplicate,marked_edited,matched,newly_added,notes,number,open_access,place,printed_date,privacy_level,publication_date,publication_string,publisher,quality,rating,read_status,refreshed_at,revision_date,searchresult,startpage,status,submission_date,subtitle,subtype,summary,tag_string,times_cited,times_read,title,type,updated_at,user_label,uuid,version,volume", quote(OLD."abbreviation")||','||quote(OLD."accepted_date")||','||quote(OLD."attributed_subtitle")||','||quote(OLD."attributed_title")||','||quote(OLD."body")||','||quote(OLD."bundle")||','||quote(OLD."canonical_title")||','||quote(OLD."citekey")||','||quote(OLD."citekey_base")||','||quote(OLD."copyright")||','||quote(OLD."created_at")||','||quote(OLD."document_number")||','||quote(OLD."doi")||','||quote(OLD."draft")||','||quote(OLD."endpage")||','||quote(OLD."extensible_properties")||','||quote(OLD."factor")||','||quote(OLD."flagged")||','||quote(OLD."imported_date")||','||quote(OLD."initial")||','||quote(OLD."institution")||','||quote(OLD."kind")||','||quote(OLD."label")||','||quote(OLD."language")||','||quote(OLD."lastread_date")||','||quote(OLD."location")||','||quote(OLD."manuscript")||','||quote(OLD."marked_deleted")||','||quote(OLD."marked_duplicate")||','||quote(OLD."marked_edited")||','||quote(OLD."matched")||','||quote(OLD."newly_added")||','||quote(OLD."notes")||','||quote(OLD."number")||','||quote(OLD."open_access")||','||quote(OLD."place")||','||quote(OLD."printed_date")||','||quote(OLD."privacy_level")||','||quote(OLD."publication_date")||','||quote(OLD."publication_string")||','||quote(OLD."publisher")||','||quote(OLD."quality")||','||quote(OLD."rating")||','||quote(OLD."read_status")||','||quote(OLD."refreshed_at")||','||quote(OLD."revision_date")||','||quote(OLD."searchresult")||','||quote(OLD."startpage")||','||quote(OLD."status")||','||quote(OLD."submission_date")||','||quote(OLD."subtitle")||','||quote(OLD."subtype")||','||quote(OLD."summary")||','||quote(OLD."tag_string")||','||quote(OLD."times_cited")||','||quote(OLD."times_read")||','||quote(OLD."title")||','||quote(OLD."type")||','||quote(OLD."updated_at")||','||quote(OLD."user_label")||','||quote(OLD."uuid")||','||quote(OLD."version")||','||quote(OLD."volume"), device(), dbRevision());END;
I cutoff the rest of the output
I'm using the sqlite3 that shipped with my MacBook Pro. If you're interested, I'm trying to accomplish the task described in the third post of this discussion.
The solution (after Dan D. got me 99.9% of the way there):
sqlite> DROP TRIGGER _upd_log_Publication_citekey;
sqlite> UPDATE Publication SET citekey = NULL;
sqlite> CREATE TRIGGER _upd_log_Publication_citekey AFTER UPDATE OF citekey ON Publication
...> WHEN enableTransactionLog() AND (NEW."searchresult" = 0) AND (OLD."citekey" IS NULL AND NEW."citekey" IS NOT NULL OR OLD."citekey" IS NOT NULL AND NEW."citekey" IS NULL OR OLD."citekey" <> NEW."citekey") BEGIN
...> DELETE FROM changeLog WHERE modUUID = NEW."uuid" AND modColumn="citekey" AND modType=2; -- delete old changes immediately, for cleanup
...> INSERT INTO changeLog (modifiedDate, modTable, modUUID, modType, modColumn, modValue, device, dbRevision) VALUES ((strftime("%s", "now") + strftime("%f", "now") - strftime("%S", "now")), "Publication", NEW."uuid", 2, "citekey", NEW."citekey", device(), dbRevision());END;

I see two options:
Mock out enableTransactionLog() with a UDF that returns false. This can't be done from the sqlite3 console.
Drop the triggers, run the update, and then re-create the triggers using the statements outputted from .schema. This can be done from the sqlite3 console.

Related

MARIADB and routine : error on declaring routine

I use HeidiSQL to make a stored procedure into my MariaDB DB.
Here's my DB.
MariaDB 10.5, centos 7, HeidiSQL 10.3.0.5771. I do not understand the error message.
CREATE TABLE HostName (
ID_HostName INT NOT NULL AUTO_INCREMENT,
Name TEXT,
Platform TEXT,
PRIMARY KEY (ID_HostName)
);
CREATE TABLE UserName (
ID_UserName INT NOT NULL AUTO_INCREMENT,
SAMAccountName TEXT,
FirstName TEXT,
GivenName TEXT,
PRIMARY KEY (ID_UserName)
);
CREATE TABLE EventData (
ID_EventData INT NOT NULL AUTO_INCREMENT,
ObjectType TEXT,
AccessList TEXT,
ObjectName TEXT,
MessageFull TEXT,
ID_UserName INT NOT NULL,
ID_HostName INT NOT NULL,
FOREIGN KEY (ID_UserName) REFERENCES UserName(ID_UserName),
FOREIGN KEY (ID_HostName) REFERENCES HostName(ID_HostName),
PRIMARY KEY (ID_EventData)
);
CREATE TABLE Event (
ID_Event INT NOT NULL AUTO_INCREMENT,
Heure TEXT,
Provider TEXT,
Code TEXT,
Action TEXT,
OutCome TEXT,
Niveau TEXT,
ID_EventData INT NOT NULL,
FOREIGN KEY (ID_EventData) REFERENCES EventData(ID_EventData),
PRIMARY KEY (ID_Event)
);
Here's my stored procedure, i would like to fill database with JDBC (Logstash jdbc output).
DELIMITER $$
CREATE PROCEDURE `LOGTOMDB`(
IN `in_Name` TEXT,
IN `in_Platform` TEXT,
IN `in_SAMAccountName` TEXT,
IN `in_ObjectType` TEXT,
IN `in_AccessList` TEXT,
IN `in_ObjectName` TEXT,
IN `in_MessageFull` TEXT,
IN `in_Heure` TEXT,
IN `in_Provider` TEXT,
IN `in_Code` TEXT,
IN `in_Action` TEXT,
IN `in_Outcome` TEXT,
IN `in_Niveau` TEXT
)
LANGUAGE SQL
NOT DETERMINISTIC
MODIFIES SQL DATA
SQL SECURITY DEFINER
COMMENT ''
BEGIN
IF NOT EXISTS ( SELECT Name FROM HostName WHERE Name = in_Name ) THEN
BEGIN
INSERT INTO HostName (Name, Platform) VALUES (in_Name, in_Platform);
END;
IF NOT EXISTS ( SELECT SAMAccountName FROM UserName WHERE SAMAccountName = in_SAMAccountName ) THEN
BEGIN
INSERT INTO UserName (SAMAccountName) VALUES (in_SAMAccountName);
END;
INSERT INTO EventData (ObjectType, AccessList, ObjectName, MessageFull, ID_UserName, ID_HostName) VALUES( in_ObjectType, in_AccessList, in_ObjectName, in_MessageFull, ID_UserName, ID_HostName );
INSERT INTO Event (Heure, Provider, Code, Action, Outcome, Niveau, ID_EventData) VALUES( in_Heure, in_Provider, in_Code, in_Action, in_Outcome, in_Niveau, ID_EventData );
END $$
DELIMITER ;
When i save my procedure, i get this error
Can you help me?
Regards.
You need to END your IF statements
DELIMITER $$
CREATE PROCEDURE `LOGTOMDB`(
IN `in_Name` TEXT,
IN `in_Platform` TEXT,
IN `in_SAMAccountName` TEXT,
IN `in_ObjectType` TEXT,
IN `in_AccessList` TEXT,
IN `in_ObjectName` TEXT,
IN `in_MessageFull` TEXT,
IN `in_Heure` TEXT,
IN `in_Provider` TEXT,
IN `in_Code` TEXT,
IN `in_Action` TEXT,
IN `in_Outcome` TEXT,
IN `in_Niveau` TEXT
)
LANGUAGE SQL
NOT DETERMINISTIC
MODIFIES SQL DATA
SQL SECURITY DEFINER
COMMENT ''
BEGIN
IF NOT EXISTS ( SELECT Name FROM HostName WHERE Name = in_Name ) THEN
INSERT INTO HostName (Name, Platform) VALUES (in_Name, in_Platform);
END IF;
IF NOT EXISTS ( SELECT SAMAccountName FROM UserName WHERE SAMAccountName = in_SAMAccountName ) THEN
INSERT INTO UserName (SAMAccountName) VALUES (in_SAMAccountName);
END IF;
INSERT INTO EventData (ObjectType, AccessList, ObjectName, MessageFull, ID_UserName, ID_HostName) VALUES( in_ObjectType, in_AccessList, in_ObjectName, in_MessageFull, ID_UserName, ID_HostName );
INSERT INTO Event (Heure, Provider, Code, Action, Outcome, Niveau, ID_EventData) VALUES( in_Heure, in_Provider, in_Code, in_Action, in_Outcome, in_Niveau, ID_EventData );
END $$
DELIMITER ;

PostgreSQL: execute a stored function (getting an error even though the arguments have been casted)

I've run into a problem I couldn't find a solution to.
I've successfully created a function. Here's the function name and arguments:
CREATE OR REPLACE FUNCTION app_private.create_user(username citext, email text, email_is_verified boolean, name text, avatar_url text, title text DEFAULT NULL::text, color character varying DEFAULT NULL::character varying, user_role smallint DEFAULT 0, password text DEFAULT NULL::text)
RETURNS app_public.users
....
CREATE FUNCTION
I've also successfully granted privilege to execute the function to a role. AND also created a comment:
grant execute on function app_private.create_user(username citext, email text, email_is_verified bool, name text, avatar_url text, title text, color varchar(7), user_role smallint, password text) to nine_manager;
GRANT
comment on function app_private.create_user(username citext, email text, email_is_verified bool, name text, avatar_url text, title text, color varchar(7), user_role smallint, password text) is
E'Creates a user account.';
COMMENT
however, when I try to create a test user by querying:
SELECT "app_private.create_user"('JS0'::citext, 'test#gmail.com'::text, true::boolean, 'John Smith'::text, 'SY'::text, 'Manager'::text, '#000000'::varchar(7), 5::SMALLINT, 'test'::text);
I get an error:
ERROR: function app_private.create_user(citext, text, boolean, text, text, text, character varying, smallint, text) does not exist
LINE 1: SELECT "app_private.create_user"('SY0'::citext, 'test#gmail....
I've tried changing the queries and casts but failed. Nearly pulling my hair out.
Thank you ahead of time.
Remove double qoutes before calling your function in select as below
Select app_private.create_user(....)
From table;

SQLite - No such column when column exists

I have a table (trackedinfo) inside my database that has the following columns (columns obtained by running PRAGMA table_info(trackedinfo);)
The problem is that even though the column sendok exists, when running a query on the database with that field, it throws an error.
Example queries:
SELECT * FROM trackedinfo WHERE sendok IS NULL;
SELECT sendok FROM trackedinfo;
Error:
SQLITE_ERROR: SQL error or missing database (no such column: sendok)
But, if I run a query selecting all of the fields, it brings me the info regarding sendok:
Here is the CREATE command of the database:
CREATE TABLE trackedinfo
(
id INTEGER PRIMARY KEY,
date_time_start TEXT,
date_time_end TEXT,
tracked_name TEXT,
tracked_origin TEXT,
tracked_maker TEXT,
tracked_version TEXT,
tracked_type TEXT,
sendok TEXT,
tracked_id TEXT
);
EDIT
It also happens with the column tracked_id
EDIT 2
Info that I got by executing .schema trackedinfo
CREATE TABLE IF NOT EXISTS "trackedinfo" ("id" INTEGER PRIMARY KEY, "date_time_start" TEXT, "date_time_end" TEXT, "tracked_name" TEXT, "tracked_origin" TEXT, "tracked_maker" TEXT, "tracked_version" TEXT, "tracked_type" TEXT, "sendok " TEXT, "tracked_id " TEXT);
The problem was that I had an space at the end of the name of the columns, solved the problem by deleting such spaces.
Before:
CREATE TABLE IF NOT EXISTS "trackedinfo" ("id" INTEGER PRIMARY KEY, "date_time_start" TEXT, "date_time_end" TEXT, "tracked_name" TEXT, "tracked_origin" TEXT, "tracked_maker" TEXT, "tracked_version" TEXT, "tracked_type" TEXT, "sendok " TEXT, "tracked_id " TEXT);
After:
CREATE TABLE IF NOT EXISTS "trackedinfo" ("id" INTEGER PRIMARY KEY, "date_time_start" TEXT, "date_time_end" TEXT, "tracked_name" TEXT, "tracked_origin" TEXT, "tracked_maker" TEXT, "tracked_version" TEXT, "tracked_type" TEXT, "sendok" TEXT, "tracked_id" TEXT);

audit trigger postgres

I want to store my old records in a table when something has changed. I tried to do it with this documentation. But i still get a error. The error is: relation serie doesn't exist.
The original table:
CREATE TABLE "Terra_nub_v1"."Serie"
(
uuid uuid NOT NULL, -- t.b.v. pakbon
serie_nr integer NOT NULL,
aantal_slijpplaten integer,
producent text,
locatie text,
klaar boolean,
onderzocht boolean,
gerapporteerd boolean,
opmerking text,
verwijzing_hoofdrapportage text,
verwijzing_overige_rapportages text,
onderzoeksgebied polygon,
CONSTRAINT "Serie_pkey" PRIMARY KEY (serie_nr)
)
The archive table:
CREATE TABLE "Terra_nub_v1".serie_history
(
uuid uuid NOT NULL,
serie_nr integer NOT NULL,
aantal_slijpplaten integer,
producent text,
locatie text,
klaar boolean,
onderzocht boolean,
gerapporteerd boolean,
opmerking text,
verwijzing_hoofdrapportage text,
verwijzing_overige_rapportages text,
onderzoeksgebied polygon,
datumtijd_wijziging timestamp without time zone,
aangepast_door text,
CONSTRAINT serie_history_pkey PRIMARY KEY (serie_nr)
)
I make the trigger function this way:
CREATE OR REPLACE FUNCTION "Terra_nub_v1".serie_history_trigger()
RETURNS trigger AS $BODY$
BEGIN
IF (TG_OP ='UPDATE') THEN
INSERT INTO Terra_nub_v1.serie_history SELECT OLD.*,NOW(), USER ;
RETURN OLD;
ELSEIF (TG_OP = 'DELETE') THEN
INSERT INTO Terra_nub_v1.serie_history SELECT OLD.*,NOW(), USER ;
RETURN OLD;
END IF;
RETURN NULL;
END;
$BODY$ LANGUAGE plpgsql VOLATILE;
Create Trigger serie_history_trigger
BEFORE UPDATE OR DELETE ON Terra_nub_v1.serie
FOR EACH ROW EXECUTE PROCEDURE process_emp_audit();
I m using postgres
Greetings

Learn SQL The Hard Way - Exercise 2 - Creating Multitable DB - .schema command

I understand the sql in this exercise perfectly, but the setup type tasks are confusing to me. Zed asks you to use the following SQL to create the following tables in a new database that are related by the id key. I'm fine there.
CREATE TABLE person (
id INTEGER PRIMARY KEY,
first_name TEXT,
last_name TEXT,
age INTEGER
);
CREATE TABLE pet (
id INTEGER PRIMARY KEY,
name TEXT,
breed TEXT,
age INTEGER,
dead INTEGER
);
CREATE TABLE person_pet (
person_id INTEGER,
pet_id INTEGER
);
In my windows command prompt I entered:
C:\SQLite> sqlite3 ex2.db < ex2.sql
ex2.db is my new db and ex2.sql contains the create statements listed above.
Zed then asks you to enter .schema using the sqlite command prompt. Nothing happens for me. It does not dump. Does .schema only work with Linux or OSX? I'm on windows.
The following is what he says you should get:
sqlite> .schema
CREATE TABLE person (
id INTEGER PRIMARY KEY,
first_name TEXT,
last_name TEXT,
age INTEGER
);
CREATE TABLE person_pet (
person_id INTEGER,
pet_id INTEGER
);
CREATE TABLE pet (
id INTEGER PRIMARY KEY,
name TEXT,
breed TEXT,
age INTEGER,
dead INTEGER
);
sqlite>
Instead, this is what I get:
sqlite> .schema
sqlite>
You have to start the sqlite3 tool with:
C:\SQLite> sqlite3 ex2.sb
sqlite> .schema
...
Without a database file name, sqlite3 just creates a temporary database.
In the Windows command prompt type:
C:\SQLite> sqlite3 ex3.db
sqlite will open.
sqlite> .schema
Create statements will display.