Gosub and odbc, and args

Hello,

I have a fairly simple dialplan:

[createcdr]
exten => s,1,Verbose(1,${STRFTIME(${EPOCH},GMT+4,%C%y-%m-%d %H:%M:%S)} - Ctx: ${CONTEXT} - Exten:     ${EXTEN} - Clid: ${CALLERID(all)} -- ${ARG1} -- ${ARG2})
same => n,Set(accntid=${ODBC_GETACCNTID(${ARG1})})
same => n,Verbose(2,Account id: ${accntid})
same => n,Set(ODBC_CREATECDR()=${accntid},${ARG2})

it is called from the dialplan:
same => n,Gosub(createcdr,s,1(${CALLERID(num)},${EXTEN}))

and the odbc is:
[CREATECDR]
dsn=mydb
; works: writesql=insert into call (dest, agent, ) values (’${ARG2}’, ${accntid}, 0)
writesql=insert into call (dest, agent, ) values (’${ARG2}’, ${ARG1}, 0)

Well, if I run the non commented statement, I get the ARG1 & ARG2 from the GOSUB, and NOT the one from the Set(ODBC_… statement, while if I run the commented statement, I get the expected values - in both cases, I see the same line in verbose:
– Executing [s@createcdr:4] Set(“SIP/13579-0000000d”, “ODBC_CREATECDR()=1,1000”) in new stack

Is this normal ?

A bit more details, which in my hpov, shows something wrong:

   -- Executing [s@createcdr:4] Set("SIP/13579-0000000e", "ODBC_CREATECDR()=1,1000") in new stack
[Jan 12 17:15:58] DEBUG[22409][C-0000000c]: pbx_variables.c:474 ast_str_substitute_variables_full: Evaluating 'ARG2' (from 'ARG2}', now(), now(), 40, ${ARG1}, 0)' len 4)
[Jan 12 17:15:58] DEBUG[22409][C-0000000c]: pbx_variables.c:381 ast_str_retrieve_variable: Result of 'ARG2' is '1000'
[Jan 12 17:15:58] DEBUG[22409][C-0000000c]: pbx_variables.c:474 ast_str_substitute_variables_full: Evaluating 'ARG1' (from 'ARG1}, 0)' len 4)
[Jan 12 17:15:58] DEBUG[22409][C-0000000c]: pbx_variables.c:381 ast_str_retrieve_variable: Result of 'ARG1' is '13579'
[Jan 12 17:15:58] DEBUG[22409][C-0000000c]: res_odbc.c:864 _ast_odbc_request_obj2: Reusing ODBC handle 0x2171d48 from class 'mycc'
[Jan 12 17:15:58] DEBUG[22409][C-0000000c]: res_odbc.c:713 ast_odbc_release_obj: Releasing ODBC handle 0x2171d48 into pool
[Jan 12 17:15:58] DEBUG[22409][C-0000000c]: pbx.c:2825 pbx_extension_helper: Launching 'Return'
    -- Executing [s@createcdr:5] Return("SIP/13579-0000000e", "") in new stack

Anyone ? just upping the thread !