tursodatabase / tursodatabase/libsql

Failing to parse double quote as strings in JS library.

Open
#1,489 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
17.2k
Forks
531
Avg merge
1h 12m
Merged PRs (30d)
1

Description

I'm using libsql package to run an introspection query, and it`s failing thinking "%AUTOINCREMENT%" is a column.

The SQL Standard defines "something" to be evaluated as strings, but SQLite is supposed to parse that a string since double-quoted strings are accepted. Ref: "8. Double-quoted String Literals Are Accepted" https://www.sqlite.org/quirks.html

Note that the same queries runs fine on Turso Dashboard's SQL runner.


const Database = require("libsql");

const syncUrl = "libsql://<something>.turso.io";
const authToken = "";

const queries = [
  // Original query
  'SELECT `name` from `sqlite_master` WHERE sql LIKE "%AUTOINCREMENT%"',

  // Test queries
  'SELECT `name` from `sqlite_master` WHERE sql LIKE "%AUTOINCREMENT%"', // Original, fails
  "SELECT `name` from `sqlite_master` WHERE sql LIKE '%AUTOINCREMENT%'", // Works
  'SELECT `name` from `sqlite_master` WHERE `sql` LIKE "%AUTOINCREMENT%"', // Fails
  "SELECT `name` from `sqlite_master` WHERE `sql` LIKE '%AUTOINCREMENT%'", // Works
  "SELECT name from sqlite_master WHERE sql = CONCAT('%AUTO', 'INCREMENT%')", // Works
  'SELECT name from sqlite_master WHERE sql = CONCAT("%AUTO", "INCREMENT%")', // Fails
];

const task = (async function run() {
  const db = new Database("./database.sqlite", {
    syncUrl,
    authToken,
  });

  db.sync();

  console.clear();
  for (const query of queries) {
    console.log("")
    try {
      console.log(`${query}\n`);
      const result = db.prepare(query).all();
      console.error(`  > OK`)
      //console.table(result);
    } catch (err) {
      console.error(`  > FAILED WITH: ${err.message}`)
    }
  }
})();

task.catch(console.error);

Error is thrown in databasePrepareSync call.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the JavaScript reproduction and the databasePrepareSync call, comparing the failing double-quoted LIKE and CONCAT queries with the single-quoted versions that work. Trace how the libsql package parses or prepares these SQLite statements, using SQLite's double-quoted string behavior as the reference. Done means the demonstrated double-quoted queries execute successfully without treating %AUTOINCREMENT% as a column.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, sqlite
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.