duckdb / duckdb-wasm

WebAssembly version of DuckDB
https://shell.duckdb.org
MIT License
1.03k stars 113 forks source link

preparedStatement.query is not logged to console #1564

Open rpbouman opened 6 months ago

rpbouman commented 6 months ago

What happens?

I am using duckdb WASM in the browser. The instantiation and setup matches the recommendations found in the documentation here https://duckdb.org/docs/api/wasm/instantiation

When I use connection.query, I see a message in the console which contains useful information like timestamp and statement. When I prepare a statement and call query on the prepared statement, no such logging appears.

It was expected that calling query on a preparedStatement would result in a message being logged, just like happens for connection.query.

To Reproduce

This is the setup code adopted from https://duckdb.org/docs/api/wasm/instantiation:

      import * as duckdb from 'https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.28.0/+esm';

      const JSDELIVR_BUNDLES = duckdb.getJsDelivrBundles();
      const bundle = await duckdb.selectBundle(JSDELIVR_BUNDLES);

      const worker_url = URL.createObjectURL(
        new Blob([`importScripts("${bundle.mainWorker}");`], {type: 'text/javascript'})
      );
      const worker = new Worker(worker_url);
      const logger = new duckdb.ConsoleLogger();
      const db = new duckdb.AsyncDuckDB(logger, worker);

      await db.instantiate(bundle.mainModule, bundle.pthreadWorker);
      const connection = await db.connect();
      URL.revokeObjectURL(worker_url);    

The following snippet demonstrates the issue against the setup shown above:

      var columnName = 'bigintcolumn';
      var sql = `SELECT "${columnName}" AS "${columnName}" FROM (VALUES (CAST(1 AS BIGINT))) AS tab("${columnName}")`;

      console.log('Before connection.query');
      var result = await connection.query(sql);
      console.log('After connection.query');

      sql += ` WHERE "${columnName}" = ?`;
      var stmt = await connection.prepare(sql);

      console.log('Before preparedStatement.query');
      result = await stmt.query(1);
      console.log('After preparedStatement.query');

Browser/Environment:

Version 120.0.6099.130 (Official Build) (64-bit)

Device:

Windows 11 Desktop

DuckDB-Wasm Version:

1.28.0

DuckDB-Wasm Deployment:

https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.28.0/+esm

Full Name:

Roland Bouman

Affiliation:

EPAM Systems BV Netherlands

rpbouman commented 6 months ago

Attached is a screenshot to illustrate the output of the repro path snippet given above: As you can see, the connection.query call results in a log message, but the preparedStatement.query call does not.

Screenshot 2024-01-04 140634

carlopi commented 6 months ago

Thanks a lot for opening both issues and providing easy reproductions