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

[database] Handle NULL literal in params #6581

Merged
merged 1 commit into from Mar 30, 2023

Conversation

yois615
Copy link
Contributor

@yois615 yois615 commented Mar 17, 2023

No description provided.

@@ -41,6 +41,7 @@ local function apply_params(db, sql, params)

local str = string.gsub(sql, param_pattern, function(param)
local v, t = params[param], type(params[param])
if "NULL" == v then return 'NULL' end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done this way to not break what's currently on line 48, although I cannot find a scenario where that actually does anything

@markjcrane
Copy link
Contributor

I'm not sure of the purpose for this.

@yois615
Copy link
Contributor Author

yois615 commented Mar 17, 2023

Example:
I have a custom LUA script to collect information from a caller. Depending on their entries, they may not have any input for a specific value.

When INSERTing their responses into the database, because the param is nil it errors out with "cannot bind parameter". If I deliberately want to leave this "NULL" in the database there is no way to do so.

By not quoting the string literal NULL, it will actually set the value in the DB as NULL instead of "NULL" (which is a string).

@yois615
Copy link
Contributor Author

yois615 commented Mar 17, 2023

Usage:

local params = {
caller_id_name = caller_id_name,
caller_id_number = caller_id_number,
domain_uuid = domain_uuid,
gender = gender or 'NULL',
age = age or 'NULL',
zip_code = zip_code or 'NULL'
}

@markjcrane
Copy link
Contributor

Thanks for the explanation accepting your changes.

@markjcrane markjcrane merged commit d92c327 into fusionpbx:master Mar 30, 2023
@yois615 yois615 deleted the lua-db-patch branch March 30, 2023 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants