Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: SQLite3 can only bind numbers, strings, bigints, buffers, and null #907

Closed
stuartambient opened this issue Nov 22, 2022 · 3 comments

Comments

@stuartambient
Copy link

stuartambient commented Nov 22, 2022

Help wanted please!

I have an array of objects, objects are in this form:

{
  afid: '57f9488f-3430-410e-9a0a-136887a9cf8a',
  audioFile: 'J:S_Music/AFX & LFO - AFX , LFO/A1 - LFO - Flu-Shot [Kringlan].mp3',
  year: 2005,
  title: 'Flu-Shot (Kringlan)',
  artist: 'LFO',
  album: 'AFX & LFO Split',
  genre1: 'Warp',
  imgData: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 02 01 00 48 00 48 00 00 ff e1 0e f4 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 07 01 12 00 03 00 00 00 01 00 01 ... 24523 more bytes>,
  lossless: false,
  bitrate: 320000,
  sampleRate: 44100
}

My statement:

  const insert = db.prepare(
      'INSERT INTO files (afid, audioFile, year, title, artist, album, genre, picture, lossless, bitrate, sample_rate) VALUES (@afid, @audioFile, @year, @title, @artist, @album, @genre1, @imgData, @lossless, @bitrate, @sampleRate)'
    );

I've attempted to even insert just one of the objects from the array arr[0]
but are constantly getting this error :

TypeError: SQLite3 can only bind numbers, strings, bigints, buffers, and null

I can successfully insert just the values like -

db.prepare(
  `INSERT INTO file VALUES ( 1234, 'J:S_Music/Andy Summers - The Golden Wire/6 - Blues For Snake.mp3', 1990,'Journey Through Blue Regions','Andy Summers', 'The Golden Wire',  'Rock',
 'ff d8 ff e1 00 bc 45 78 69 66 00 00 49 49 2a 00 08 00 00 00 06 00 12 01 03 00 01 00 00 00 01 00 00 00 1a 01 05 00 01 00 00 00 56 00 00 00 1b 01 05 00 ... 36606', false,256000,44100
  )`
).run();

So I'm not sure what is wrong with my object (or statement) that it's throwing the error.

@JoshuaWise
Copy link
Member

JoshuaWise commented Nov 23, 2022

If the object has a prototype of anything other than Object.prototype or null, then it is considered some kind of class instance rather than a plain object. The error you're receiving is to prevent you from trying to bind types that don't exist in SQLite, such as Date, etc.

@stuartambient
Copy link
Author

Turns out the field that was throwing the error was a boolean, which in my object is either true or false. I was under the impression (from the sqlite docs) that true would automatically equate to 1 and false to 0.

@JoshuaWise
Copy link
Member

JoshuaWise commented Nov 24, 2022

Ah yes, I didn't notice that you had booleans. This was was a conscious design choice so that inserting and selecting data from SQLite have a symmetrical interface. For example, we could convert booleans to 1 and 0, but then users might expect it to go the other way around too, which is impossible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants