Ok this is unbelievably weird.
When I run the updated query on the server’s CLI:
mysql -Ns asteriskcdrdb -e 'SELECT COUNT(*)+1 FROM cdr WHERE src="1xxxxxxxx67" AND (calldate > NOW() - INTERVAL 2 MINUTE)' |tr -d '\n'
I get an output of 1,2, or 3, etc. However many times I called in the last 2 minutes, plus 1, exactly as expected.
I so changed the operative part of dialplan to this:
exten => s,n,Set(NUMBEROFCALLS=${SHELL(mysql -Ns asteriskcdrdb -e 'SELECT COUNT(*)+1 FROM cdr WHERE src="1xxxxxxxx67" AND (calldate > NOW() - INTERVAL 2 MINUTE)' |tr -d '\n')})
exten => s,n,NoOp(${NUMBEROFCALLS})
exten => s,n,Set(NUMBEROFCALLS=$[${NUMBEROFCALLS} - 1])
exten => s,n,NoOp(${NUMBEROFCALLS})
And line by line as that part of dialplan code executes, this is the output:
3578391 [2022-01-18 16:36:53] VERBOSE[5119][C-0000442f] pbx.c: Executing [s@identify_repeat_caller:3] NoOp("PJSIP/fpbx-1-I2c7nuvRHnOq-0002eb66", "1xxxxxxxx67") in new stack
3578392 [2022-01-18 16:36:53] VERBOSE[5119][C-0000442f] pbx.c: Executing [s@identify_repeat_caller:4] Set("PJSIP/fpbx-1-I2c7nuvRHnOq-0002eb66", "NUMBEROFCALLS=") in new stack
3578393 [2022-01-18 16:36:53] VERBOSE[5119][C-0000442f] pbx.c: Executing [s@identify_repeat_caller:5] NoOp("PJSIP/fpbx-1-I2c7nuvRHnOq-0002eb66", "") in new stack
3578394 [2022-01-18 16:36:53] VERBOSE[5119][C-0000442f] pbx.c: Executing [s@identify_repeat_caller:6] Set("PJSIP/fpbx-1-I2c7nuvRHnOq-0002eb66", "NUMBEROFCALLS=-1") in new stack
3578395 [2022-01-18 16:36:53] VERBOSE[5119][C-0000442f] pbx.c: Executing [s@identify_repeat_caller:7] NoOp("PJSIP/fpbx-1-I2c7nuvRHnOq-0002eb66", "-1") in new stack
3578396 [2022-01-18 16:36:53] VERBOSE[5119][C-0000442f] pbx.c: Executing [s@identify_repeat_caller:8] GotoIf("PJSIP/fpbx-1-I2c7nuvRHnOq-0002eb66", "0?captcha:welcome") in new stack
The NUMBEROFCALLS variable is STILL empty despite adding 1 to the mysql query, and confirming the query yields expected output when run directly in the CLI!