Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define--> What does undefine() and define_free() actually do? #73

Closed
drjdpowell opened this issue Mar 16, 2023 · 8 comments
Closed

Define--> What does undefine() and define_free() actually do? #73

drjdpowell opened this issue Mar 16, 2023 · 8 comments

Comments

@drjdpowell
Copy link

Hi, I have this confusing behaviour (using a compiled for 32-bit define.dll):

select define('sumn', ':n * (:n + 1) / 2');
select sumn(5); --> 15
select undefine('sumn');
select define_free();
select sumn(5); --> '15'

Why does the defined function still work if I have undefined and called define_free? I checked that the 'sumn' function is properly deleted from the sqlean_define table.

@nalgeon
Copy link
Owner

nalgeon commented Mar 16, 2023

Quoting the docs:

To delete a scalar function, execute undefine(), then reconnect to the database:

sqlite> select undefine('sumn');
sqlite> select define_free();
... reconnect
sqlite> select sumn(5);
Parse error: no such function: sumn

@drjdpowell
Copy link
Author

Ah, I did not appreciate that the sqlean_define table is permanent, and survives reconnect.

Is there a way to make the table Temporary, so that each connection has its own private set of defined functions, that disappear on disconnect?

@nalgeon
Copy link
Owner

nalgeon commented Mar 17, 2023

Not at the moment. Why would you need it, what is your use case?

@drjdpowell
Copy link
Author

Similar to using a Temporary View, to make following SQL simpler and clearer, without two independant connections (with possibly different versions of the View) interfering with each other.

@nalgeon
Copy link
Owner

nalgeon commented Mar 17, 2023

Not sure I understand. What prevents you from using the same function from two different connections? How would they interfere?

@drjdpowell
Copy link
Author

An example might be a Distance() function that includes a conversion into desired display units (Miles versus km vs yards vs meters, say). Two connections to the same db might be set for different display units. Each connection would want to be able to define the distance() function differently, and be able to change it freely.

@nalgeon
Copy link
Owner

nalgeon commented Mar 20, 2023

I'm sure we can come up with a lot of hypothetical scenarios like the one you mentioned. But do you have a specific use case in your real work?

@nalgeon
Copy link
Owner

nalgeon commented Mar 28, 2023

I'll be happy to revisit this issue when there's a real use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants