Using String Replace() To Get A Value From A Db Query Result Leads To Problems
I am querying DB and want to validation my output. The result from DB is coming in the manner -> (('ABC',),) and I want to validate it with string 'ABC', but I am unable due to
Solution 1:
Do not do that - treat the response as a string, and try to get you data out through string replace.
The response is an object - a list of tuples, it actually looks like this:
[('ABC',),]
Every tuple in the list is a response row; every member of the tuple is a column in that row.
To get the first column of the first row, you just address them (their indices start from 0):
${value}= Set Variable ${the response object}[0][0]
If for example the query returnes 3 rows, each with 2 columns:
[('ABC', 'DEF'), ('GHI', 'JKL'), ('MNO', 'PQR')]
, you'd get the 3rd row's (index: 2) 2nd column (index: 1) - the string 'PQR' - with this:
${value}= Set Variable ${the response object}[2][1]
Now I hope you understand why using string replace (over the string representation of a two-dimensional list) is not a good idea.
Post a Comment for "Using String Replace() To Get A Value From A Db Query Result Leads To Problems"