I am using WebViewExtras2, and I can get the value returned by B4A using CallSub(subName As String, callUIThread As boolean, parameter1 As String) in JavaScript, but CallSub(subName As String, callUIThread As boolean, parameter1 As String, parameter2 As String) fails to do so.
Both methods can display the generated JSON content in B4A's Log(jsonString). This indicates that both methods can pass values to B4A and execute queries. However, method 2, which passes two parameters, encounters an error: java.lang.Exception: Sub getdata_forjs2 signature does not match expected signature. I don't know where the error lies?
Both methods can display the generated JSON content in B4A's Log(jsonString). This indicates that both methods can pass values to B4A and execute queries. However, method 2, which passes two parameters, encounters an error: java.lang.Exception: Sub getdata_forjs2 signature does not match expected signature. I don't know where the error lies?
CallSub(subName As String, callUIThread As boolean, parameter1 As String):
'B4A
public Sub getData_ForJs1(sqlQuery As String) As String
Dim gen_Json As Map = DBUtils.ExecuteJSONC(SQL_Book,sqlQuery,Null)
Dim jsonGenerator As JSONGenerator
jsonGenerator.Initialize(gen_Json)
Dim jsonString As Object = jsonGenerator.ToString
Log(jsonString)
Return jsonString
End Sub
'js
async function getResultSetAsRowJSON() {
let sqlQuery = 'SELECT ' + fieldsStr + ' FROM All_Book WHERE Book = ' + bookNum + ' AND Chapter = ' + _chapter + ' LIMIT';
let _resultset;
if (sql_wasm) {
_resultset = _db.exec(sqlQuery + " " + limit);
} else {
let b4x_result1 = B4X.CallSub('getData_ForJs1', false, sqlQuery + ' ' + limit);
console.log(b4x_result1);
const parsed = JSON.parse(b4x_result1);
_resultset = [
{
columns: Object.keys(parsed.root[0]),
values: parsed.root.map(item => Object.values(item))
}
];
}
}
CallSub(subName As String, callUIThread As boolean, parameter1 As String, parameter2 As String):
'b4a
public Sub getData_ForJs2(sqlQuery As String,style As String) As String
If style="KKK" Then
Dim gen_Json As Map = DBUtils.ExecuteJSONC(SQL_Book,sqlQuery,Null)
End If
Dim jsonGenerator As JSONGenerator
jsonGenerator.Initialize(gen_Json)
Dim jsonString As Object = jsonGenerator.ToString
Log(jsonString)
Return jsonString
End Sub
'js
async function getResultSetAsRowJSON() {
let sqlQuery = 'SELECT ' + fieldsStr + ' FROM All_Book WHERE Book = ' + bookNum + ' AND Chapter = ' + _chapter + ' LIMIT';
let _resultset;
if (sql_wasm) {
_resultset = _db.exec(sqlQuery + " " + limit);
} else {
let b4x_result2 = B4X.CallSub('getData_ForJs2', false, sqlQuery + ' ' + limit, 'KKK');
console.log(b4x_result2);
const parsed = JSON.parse(b4x_result2);
_resultset = [
{
columns: Object.keys(parsed.root[0]),
values: parsed.root.map(item => Object.values(item))
}
];
}
}