tags:

views:

210

answers:

1

New to Tsung and Erlan and have run into an issue I haven't been able to find answer to. I'm using erlang-mysql-driver in a Tsung dynvars Erlang function and I seem to be having a problem with escaped quotes.

I'd like to do something like this:

      <setdynvars sourcetype="eval"
              code='fun({Pid,DynVars})->
                  mysql:start_link(p1, "localhost", "user", "pass", "db"), 
                  Result = mysql:fetch(p1, "SELECT * FROM consumers WHERE first_name=\'Doonley\'") end.'>
      <var name="myres" />
    </setdynvars>

but I get a whitespace error:

Douglas-Sparlings-MacBook-Pro:.tsung dsparling$ tsung start
Starting Tsung
"Log directory is: /Users/dsparling/.tsung/log/20091110-16:35"
3284- fatal: {whitespace_required_between_attributes}
["Config Error, aborting ! ",{fatal,{{whitespace_required_between_attributes},{file,"/Users/dsparling/.tsung/tsung.xml"},{line,72},{col,221}}}]

I actually need to use a variable for the select, but I'm not sure of the syntax. Something like the following is what I'm looking for:

      <setdynvars sourcetype="eval"
              code='fun({Pid,DynVars})->
                  Val='Doonley",
                  mysql:start_link(p1, "localhost", "user", "pass", "db"), 
                  Result = mysql:fetch(p1, "SELECT * FROM consumers WHERE first_name=?", Val) end.'>
      <var name="myres" />
    </setdynvars>
+2  A: 

Try escaping the single quotes as &apos;. E.g.:

  <setdynvars sourcetype="eval"
          code='fun({Pid,DynVars})->
              mysql:start_link(p1, "localhost", "user", "pass", "db"), 
              Result = mysql:fetch(p1, "SELECT * FROM consumers WHERE first_name=&apos;Doonley&apos;") end.'>
  <var name="myres" />
</setdynvars>
legoscia
I thought of that later, though that doesn't seem to be successful either: ["Config Error, aborting ! ",{function_clause,[{erl_scan,scan_string1,[["'",68,111,111,110,108,101,121,"'",34,41,32,101,110,100,46],1,no_col,34,"=eman_tsrif EREHW sremusnoc MORF * TCELES","=eman_tsrif EREHW sremusnoc MORF * TCELES",0]},{erl_scan,scan_string,6},{erl_scan,string1,5},{ts_utils,eval,1},{ts_config,parse,2},{lists,foldl,3},{ts_config,parse,2},{lists,foldl,3}]}]
scriptrunner
Hm, seems like the string turned into a deep list because of the apostrophes. My guess is that this is a bug in Tsung, which can be fixed by changing `erl_scan:string(Code)` to `erl_scan:string(lists:flatten(Code))` in the `eval` function in `ts_utils.erl`.
legoscia
Thank you, that seemed to do it. I've submitted a but report.
scriptrunner