From cc09167986a48fdf7d8a4055758981dce991ae49 Mon Sep 17 00:00:00 2001 From: James Dingwall Date: Tue, 6 May 2025 20:46:55 +0100 Subject: [PATCH] Improve error message for unsupported named parameters: Previously just 'Illegal parameter number' was logged, make this a more helpful message. ``` [25-05-06 20:46:04.2629] Slim::Schema::Storage::throw_exception (122) Error: DBI Exception: DBD::mysql::st bind_param failed: named parameters are unsupported: :album [for Statement " SELECT contributor_album.role AS role, contributors.name AS name, contributors.id AS id FROM contributor_album JOIN contributors ON contributors.id = contributor_album.contributor WHERE contributor_album.album = :album AND contributor_album.role IN (5,1) ORDER BY contributor_album.role, contributors.namesort "] ``` --- dbdimp.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/dbdimp.c b/dbdimp.c index 39db0336..525dcf80 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -4209,6 +4209,23 @@ int dbd_bind_ph(SV *sth, imp_sth_t *imp_sth, SV *param, SV *value, if (param_num <= 0 || param_num > DBIc_NUM_PARAMS(imp_sth)) { + if (!looks_like_number(param)) + { + STRLEN len; + char *paramstring; + paramstring = SvPV(param, len); + if(paramstring[len] == 0 && strlen(paramstring) == len) + { + do_error(sth, JW_ERR_ILLEGAL_PARAM_NUM, form("named parameters are unsupported: %s", paramstring), NULL); + return FALSE; + } + else + { + do_error(sth, JW_ERR_ILLEGAL_PARAM_NUM, " could not be coerced to a C string", NULL); + return FALSE; + } + } + do_error(sth, JW_ERR_ILLEGAL_PARAM_NUM, "Illegal parameter number", NULL); return FALSE; }