chacham15
chacham15

Reputation: 14251

How can I check whether a function exists in sqlite?

I am trying to build some abstract functions on top of Sqlite which can choose the best function to call. I am doing this in a custom function implementation (not in sql).

An example: A use could be something like: SELECT username FROM Users WHERE id='blah' AND password = BEST_HASH('some string'). In this case I would be implementing best_hash and I want it to check if a function called 'sha1' or 'bcrypt' exist. And when its found the best match then call the appropriate function.

My actual case needs to choose the best out of an existing set of functions (which are meaningless outside the program, hence the different example).

Being a programmer, I am trying to make a generic case to determine whether a function exists. I have a specific version working by compiling a statement with SELECT function_name(arg1, arg2, ...argN). How would I generalize this to not knowing how many arguments are available?

Upvotes: 1

Views: 1935

Answers (2)

user1461607
user1461607

Reputation: 2760

You can select from a pragma function to see if a function exists in SQLite.

 select exists(select 1 from pragma_function_list where name='sum');
 1

Upvotes: 3

gcbenison
gcbenison

Reputation: 11963

I don't know if sqlite supports information_schema, but in systems that do (such as postgres) you can query for whether a particular function exists like this:

select routine_name
from information_schema.routines
where routine_name = 'sha1';

Upvotes: 0

Related Questions