Code Monkey home page Code Monkey logo

Comments (4)

DallasHoff avatar DallasHoff commented on May 26, 2024

From a cursory glance, I think the issue is this limitation of sqlite-wasm: "[Bindings] are only applied to the first non-empty statement in the SQL which has any bindable parameters. (Empty statements are skipped entirely.)". Since your third statement is the second statement with bindings, sqlite-wasm errors on that third statement ("index 3").

Does it work if you remove the bindings from the other 2 statements?

from sqlocal.

MigFerreira avatar MigFerreira commented on May 26, 2024

Yes, I tried in multiple orders. It seems to only allow bindings in one statement.

from sqlocal.

DallasHoff avatar DallasHoff commented on May 26, 2024

Ok, that tracks. I'm not sure why sqlite-wasm has that limitation, but it means you should separate each statement. Your example is a perfect use-case for SQLocal's transaction method.

from sqlocal.

DallasHoff avatar DallasHoff commented on May 26, 2024

I've added a paragraph noting this to the docs page for sql:


Multiple statements can be passed in the query, but note that the results returned will only include results from the first value-returning statement. Also, only one statement in the query can have parameter bindings. Because of these restrictions, it is recommended to pass only one SQL statement per call to sql.

// Warning: only returns the row with id 1.
const result = await sql`
	SELECT * FROM foo WHERE id = 1; 
	SELECT * FROM foo WHERE id = 2;
`;

// Recommended: one statement per query
const result1 = await sql`SELECT * FROM foo WHERE id = 1;`;
const result2 = await sql`SELECT * FROM foo WHERE id = 2;`;

from sqlocal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.