运行关键字如果使用SQL

时间:2017-07-11 16:33:23

标签: frameworks robotframework

我正在尝试从Restful Web服务中撤回数据。

如果我得到一个包含单词A的文本值,那么我需要运行此SQL来验证,如果它没有,则运行不同的SQL。

此运行关键字如果要运行关键字,但Query语句以变量开头。

这是我尝试过的:

const tls = require('tls');
const net = require('net');

var creations = 0;  // a running count of the number of open connections, when it becomes 0, the tunnel is closed.
var server;  // a server listening for certificate requests from the gateway server 

exports.create = function(port, options, callback) {
    if(creations == 0) {

        creations++;

        //server not currently running, create one
        server = net.createServer(function (conn) {
            connectFarside(conn, options, function(err, socket) {
                socket.pipe(conn);
                conn.pipe(socket);
            });
        });

        server.listen(port, function(){
            callback();
        });

    } else{
        //server already running
        creations++;
        callback()
    }
};

function connectFarside(conn, options, callback) {
    try {
        var socket = tls.connect(options, function() {
            callback(null, socket);
        });

        socket.on('error', function(err){
            console.log('Socket error: ' + JSON.stringify(err));
        });

    } catch(err) {
        callback(err);
    }
};

exports.close = function(){

    creations--;
    if(creations == 0){
        // close the server if this was 
        // the only connections running on it
        server.close();
    }
}

我刚收到此错误:

${typeA}    Set Variable    ${rowValues["TypeA"]}
${foundValue}    Get Lines Containing String  ${typeA}  Speical
${lineCount}    Get Line Count    ${foundValue}
${resultValue}  Set Variable If   ${lineCount} > 0   ${True}   ${False}
${idvalue}  Set Variable    test
Run Keyword If    ${resultValue}
...    ${idvalue}  Query  Select max(id) from test where 1 =1;    
...    ELSE
...    ${idValue}  Query  Select max(id) from table 2 where 1 = 1;

1 个答案:

答案 0 :(得分:0)

Run keyword if中的条件之后的第一个参数必须是关键字。您错误地给它一个变量(可能包含字符串“test”,基于您报告的错误)

要分配查询的值,您必须捕获Run keyword if的结果:

${idValue}=  Run keyword if  ${resultValue}
...  Query  Select max(id) from test where 1 =1;
...  ELSE
...  Query  Select max(id) from table 2 where i = 1;