SQL 在 Eclipse (rbfw) 中使用 DatabaseLibrary 的语句 return 乱码而不是只有准确的值

SQL statement with DatabaseLibrary in Eclipse (rbfw) return jibberish instead of only the exact value

我在 Eclipse 和 DatabaseLibrary 中使用 RobotFramework

(https://franz-see.github.io/Robotframework-Database-Library/api/0.5/DatabaseLibrary.html)


这是我使用的语句:

${test}=  DatabaseLibrary.Query    select Location from Devices where DeviceID = '2'
    Log to Console  ${test}  console=yes
    Should Be Equal As Strings    ${test}    Amsterdam

数据库中的值为Amsterdam

然而,我得到的是`(('Amsterdam',),)

为什么会这样,怎么会这样 return Amsterdam? (没有乱码的实际值)

查询关键字的文档说明如下:

Uses the input selectStatement to query for the values that will be returned as a list of tuples.

而您的 return 值为:

(('Amsterdam',),)

这是“元组列表”——所以一切都是它们应该的样子。

如果您需要访问列表元素,您可以使用 [] 的索引。这样的事情可能会奏效:

    ${test}=  DatabaseLibrary.Query    select Location from Devices where DeviceID = '2'
    Log to Console  ${test[0][0]}  console=yes
    Should Be Equal As Strings    ${test[0][0]}    Amsterdam

我也想出了一个解决方法:

Should Match Regexp    str${test}    ^\w*\W*Amsterdam*\w*\W*$