chetana bhargav wrote:
Hi,
I was trying out to test some trigger stuff, basically if I have 2 connections
open, and one of the connection registered a user defined function to be
invoked. Now when the other connection inserts into table was trying to see if
the first functions registered function is called or not.
I am having a trigger in this format,
CREATE TRIGGER trigs_partid_t01
AFTER INSERT
ON ids
BEGIN
SELECT foo_bar_trigs(new.mId);
END;
I have proper implementation for the foo_bar_trigs function registered in the
first function, and that is open always.
When I prepared a statement to insert in the second connection, while preparing, I am
getting an error as, "no such function: foo_bar_trigs".
Is it always necessary that the second function also need to have this function
registered, as I am not even able to prepare a statement, and its coming out
with this error.
Chetana,
Yes, you will need to register your user defined function with each
connection that will execute SQL statements that cause the trigger to
fire. The trigger itself is stored in the database along with the table
definitions. The user defined functions are registered with the
connection only, they are not saved in the database, and are not
available to other connections.
The best way to handle this is to move your sqlite_open and
sqlite_create_function calls into a subroutine that you use to open all
your database connections.
int my_sqlite_open(const char *filename, sqlite3 **ppdb)
{
int rc = sqlite3_open(filename, ppdb);
if (rc == SQLITE_OK) {
sqlite_create_function(*ppdb, "function_one", ...);
sqlite_create_function(*ppdb, "function_two", ...);
...
}
return rc;
}
This way you are sure you have all the functions registered with each
connection you use. Now you can safely execute any SQL statement. If it
causes the trigger to fire, it will have the correct user defined
function available.
HTH
Dennis Cote
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------