GithubHelp home page GithubHelp logo

Query parameters about sqlite3 HOT 9 CLOSED

denodrivers avatar denodrivers commented on June 7, 2024
Query parameters

from sqlite3.

Comments (9)

DjDeveloperr avatar DjDeveloperr commented on June 7, 2024 2

Found the problem. It was because the C string's null byte was being included in bind parameter. I'll land fix and make a patch release ASAP

from sqlite3.

iuioiua avatar iuioiua commented on June 7, 2024 2

It works! Thank you 🙏🏾

from sqlite3.

DjDeveloperr avatar DjDeveloperr commented on June 7, 2024 1

Tagged 0.2.4 with the fix

from sqlite3.

DjDeveloperr avatar DjDeveloperr commented on June 7, 2024

You can bind parameters to a query using the variadic arguments in queryArray/queryObject methods.
See: https://doc.deno.land/https://deno.land/x/[email protected]/mod.ts/~/Database#queryArray (the ...args parameter).
For example:

db.queryArray<[string]>("select name from users where id = ?", id);

I'll add some examples to docs and test cases for it 😄

from sqlite3.

iuioiua avatar iuioiua commented on June 7, 2024

Thanks for the new documentation!

I've attempted using .queryArray and .queryObject multiple times without and get empty results. My database is very simple and essentially lines up to the example you just added to the documentation for binding parameters. I've triple-checked my stuff and can't see what could be wrong. I've retried the same command in the CLI and do get results.

I ran deno test on your module and everything passes, including binding parameters. I don't know what the issue could be.

Deno version: 1.17.1 (release, x86_64-apple-darwin)
Module version: 0.2.3
macOS version: 12.1
SQLite version: 3.37.0

from sqlite3.

DjDeveloperr avatar DjDeveloperr commented on June 7, 2024

Could you provide a small reproduction for this case? I need something to look into to find out the issue.

It works fine for me:
image

from sqlite3.

iuioiua avatar iuioiua commented on June 7, 2024

I tried your the same code that for the users table and it worked fine. However, I'm still having issues with my database not showing any results. Here's the exact SQL and code I use.

import { Database } from "https://raw.githubusercontent.com/denodrivers/sqlite3/main/mod.ts";

const db = new Database("test");

db.execute("CREATE TABLE authors (author_name TEXT NOT NULL, author_username TEXT NOT NULL UNIQUE, author_bio TEXT, PRIMARY KEY (author_username));");
db.execute(`INSERT INTO authors(author_name, author_username, author_bio) VALUES ('John Doe', 'john_doe', "I'm John Doe.");`);

console.log(db.queryArray("SELECT * FROM authors"));
console.log(db.queryArray("SELECT * FROM authors WHERE author_username = ?", "john_doe"))

db.close();

Result:

> [ [ "John Doe", "john_doe", "I'm John Doe." ] ]
> []

from sqlite3.

DjDeveloperr avatar DjDeveloperr commented on June 7, 2024

Ah, it seems that string parameters are failing here. I will look into this right now.

from sqlite3.

iuioiua avatar iuioiua commented on June 7, 2024

Beautiful!

from sqlite3.

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.