我想通过将变量传递给where子句从表数据结构中检索记录。但是它仅在值经过硬编码时有效,而在作为参数给出时则无效。
public function getEmployeeEmail(string GITHUB_ID_VALUE) returns string{
string WSO2_EMAIL;
table<Employee> employeeTableCopyWithFilter = from tableEmployee where GITHUB_ID == GITHUB_ID_VALUE select *;
json jsonTable = check <json>employeeTableCopyWithFilter;
return jsonTable[0].WSO2_EMAIL.toString();
}
它会抛出这样的错误。
error: ballerina/runtime:CallFailedException, message: call failed
at org/wso2/org:0.0.1:GitHubStarsDetector.executeOperation(service.bal:40)
caused by ballerina/runtime:CallFailedException, message: call failed
at org/wso2/org:0.0.1:getMissingIds(github_repository_scanner.bal:54)
caused by error, message: error in executing statement : CREATE TABLE TABLE_EMPLOYEE_3 AS select * from (select * from TABLE_EMPLOYEE_1 where GITHUB_ID = id) error:Column "ID" not found; SQL statement:
CREATE FORCE VIEW PUBLIC._0 AS
SELECT
TABLE_EMPLOYEE_1.USER_ID,
TABLE_EMPLOYEE_1.NAME,
TABLE_EMPLOYEE_1.GITHUB_ID,
TABLE_EMPLOYEE_1.WSO2_EMAIL
FROM PUBLIC.TABLE_EMPLOYEE_1
WHERE GITHUB_ID = ID [42122-197]
at org/wso2/org:0.0.1:getEmployeeEmail(database_handler.bal:102)
但是,当我将值硬编码为GITHUB_ID_VALUE
参数时,它仍然可以正常工作。
public function getEmployeeEmail(string GITHUB_ID_VALUE) returns string{
string WSO2_EMAIL;
table<Employee> employeeTableCopyWithFilter = from tableEmployee where GITHUB_ID == "MadhukaHarith92" select *;
json jsonTable = check <json>employeeTableCopyWithFilter;
return jsonTable[0].WSO2_EMAIL.toString();
}
有人知道如何传递变量并从表结构中检索记录吗?