Bug #112817 DB Notebook: runSql() complains function could not be cloned
Submitted: 24 Oct 2023 17:47 Modified: 2 Dec 9:57
Reporter: Kaiwang CHen (OCA) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Shell VSCode Extension Severity:S3 (Non-critical)
Version:1.13.5 OS:MacOS
Assigned to: CPU Architecture:Any

[24 Oct 2023 17:47] Kaiwang CHen
Description:
Example from manual does not work.

doc link: https://dev.mysql.com/doc/mysql-shell-gui/en/mysql-shell-vscode-notebook-select-javascript...

Example code:

runSql(
  "SELECT Name as name," +
  "District as district, Population as pop FROM world.city WHERE Name = 'Kabul' ",
  (ResultSetRows) => {
    print(ResultSetRows);
  }
);
ERROR: Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': (ResultSetRows) => {
    print(ResultSetRows);
  } could not be cloned. (Ln 1, Col 2)

How to repeat:
1. Open the Database Connections Browser
2. Connect to a MySQL instance (8.0.34) with world database installed
3. In the DB Notebook editor, switch to js mode
sql> \js
4. type
js> runSql("select name from world.city", function (rs) {});

ERROR: Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': function (rs) {} could not be cloned. (Ln 1, Col 2)
[25 Oct 2023 6:02] MySQL Verification Team
Hello Kaiwang,

Thank you for the report and feedback.

regards,
Umesh
[2 Dec 9:57] Mike Lischke
Posted by developer:
 
This is not a bug. The API which was used (runSQL) does not take a callback, but returns the values in a promise. The correct use is:

```
const result = await runSql(
  "SELECT Name as name," +
  "District as district, Population as pop FROM world.city WHERE Name = 'Kabul' "
);

print(result);
```

If you want to use a callback instead use "runSqlWithCallback". Both functions return the entire result set in one step. There's a third function "runSqlIterative", which works like "runSqlWithCallback" (same syntax), which calls the callback multiple times, for each batch of result rows (usually 1000).

I added a specific check for these methods to refuse execution with a better error message, in case parameters were used that are incompatible.
[2 Dec 10:08] Mike Lischke
In fact it is a bug - a documentation bug. I'll take care to get the web site updated.