Replace String with Regexp for a value fetched from MySQL Query in Robot framework

258 views Asked by At

I am Working in Robot Framework with My SQL Database. I am struck up at a point where I need to Run a Query that returns only one value and use it in UI application.

Connect To Database    pymysql    Schema     Username    Password     localhost      portnumber
${result}=    DatabaseLibrary.Query     query
Disconnect From Database

In the Report I can see the variable ${result}= ((11111111,),)

I need that 11111111 and input in the UI application. I Have tried using Get Substring, Replace String with RegExp but it failing either it returns ((11111111,),) or string buffer error or typo error.

How can I rewrite to fetch the numeric value to reuse in my code?.

1

There are 1 answers

0
Todor Minakov On

The response from DB queries is list of tuples (that comes from the underlying python implementation) - a list member is a row in the response, the tuple members are the columns in it.

Thus, to get the value of the first column in the first response row, you could do this:

${value}=    Set Variable    ${result[0][0]}

The indices are 0-based, so if you want the 3rd column from the 2nd row, that would be

${value}=    Set Variable    ${result[1][2]}