# Error while inserting uuid into sqlite3 in express

**URL:** <https://discourse.nodered.org/t/error-while-inserting-uuid-into-sqlite3-in-express/41302>\
**Category:** General\
**Created:** [19 February 2021 13:35 UTC](https://discourse.nodered.org/t/error-while-inserting-uuid-into-sqlite3-in-express/41302 "2021-02-19T13:35:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackcarver12](https://avatars.discourse-cdn.com/v4/letter/j/c5a1d2/32.png) [@jackcarver12](https://discourse.nodered.org/u/jackcarver12)\
**Post date:** [19 February 2021 13:35 UTC](https://discourse.nodered.org/t/error-while-inserting-uuid-into-sqlite3-in-express/41302/1 "2021-02-19T13:35:11Z")

</div>

I required an error while inserting this dataset in my database: I am programing on express/node.js

```auto
this.db.run("INSERT INTO bestellung(rid,bid,tableno,drink,price,validation) VALUES(`"+ridJSON.id+"`,`"+bidJSON.id+"`,"+tableno+","+ name+","+kpreis+","+validation+")", (err) =>
    {
        if (err)
        {
            return console.log(err.message);
        }
        console.log('Row was added to the table');
    });

```

This is my express.js code. And this is the error I am receiving:

```auto
Connected to the chinook database.
SQLITE_ERROR: no such column: 89ce87ff-3e55-4660-b958-bc0cfd108413

```

Here is basically what I am trying to do: I want to insert two types of uuid into my database. I am using BLOB to save the uuid. This seems to work fine with uuid.v1() but using uuid.v4() doesn´t seem to work out.

Since it is both almost the same data:

a3f7f1a0-72b3-11eb-80b9-835df2abaa17 = v1 89ce87ff-3e55-4660-b958-bc0cfd108413 = v4

I wonder why it wont work...

Please help me! I am really getting crazy about this error. I already googled the error and the usage of uuid. It seems fine the way I am using it. Thank you in advance!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 February 2021 13:52 UTC](https://discourse.nodered.org/t/error-while-inserting-uuid-into-sqlite3-in-express/41302/2 "2021-02-19T13:52:11Z")

</div>

Build the sql statement as a string before executing it, and log it, to check exactly what is in it.

---

<div class="post-metadata">

**Author:** ![jackcarver12](https://avatars.discourse-cdn.com/v4/letter/j/c5a1d2/32.png) [@jackcarver12](https://discourse.nodered.org/u/jackcarver12)\
**Post date:** [19 February 2021 14:42 UTC](https://discourse.nodered.org/t/error-while-inserting-uuid-into-sqlite3-in-express/41302/3 "2021-02-19T14:42:41Z")

</div>

Hey Colin!  
Thank you for your help!

```auto
bid
8f30eb80-72bf-11eb-989b-53bfe0c1cb7e
rid
47f7396e-899b-4ac4-b037-51edd97dbb1e
Thats my statement:
INSERT INTO bestellung(rid,bid,tableno,drink,price,validation) VALUES(`47f7396e-899b-4ac4-b037-51edd97dbb1e`,`8f30eb80-72bf-11eb-989b-53bfe0c1cb7e`,2,Testdrinkdb,12.90,pending)
Connected to the chinook database.
SQLITE_ERROR: no such column: 47f7396e-899b-4ac4-b037-51edd97dbb1e

```

It seems like it looks for a column that doesn't exists.  
I don`t know why it can insert the uuid.v1 but not the uuid.v4  
BLOB should just do fine.  
Thank you for the advice!

---

<div class="post-metadata">

**Author:** ![jackcarver12](https://avatars.discourse-cdn.com/v4/letter/j/c5a1d2/32.png) [@jackcarver12](https://discourse.nodered.org/u/jackcarver12)\
**Post date:** [19 February 2021 14:49 UTC](https://discourse.nodered.org/t/error-while-inserting-uuid-into-sqlite3-in-express/41302/4 "2021-02-19T14:49:15Z")

</div>

This is the db I visualized via sqlite viewer:

 ![BTable](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/0/c067d432df63273bfa387eeb436c853c15d1f811.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 February 2021 15:12 UTC](https://discourse.nodered.org/t/error-while-inserting-uuid-into-sqlite3-in-express/41302/5 "2021-02-19T15:12:35Z")

</div>

Sorry, I can't see anything wrong immediately, but I have not used that mode of operation.

---

<div class="post-metadata">

**Author:** ![jackcarver12](https://avatars.discourse-cdn.com/v4/letter/j/c5a1d2/32.png) [@jackcarver12](https://discourse.nodered.org/u/jackcarver12)\
**Post date:** [19 February 2021 15:13 UTC](https://discourse.nodered.org/t/error-while-inserting-uuid-into-sqlite3-in-express/41302/6 "2021-02-19T15:13:20Z")

</div>

well I guess I ll have to wait for someone else! 😉  
Thanks a lot for the help!

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [19 February 2021 19:04 UTC](https://discourse.nodered.org/t/error-while-inserting-uuid-into-sqlite3-in-express/41302/7 "2021-02-19T19:04:54Z")

</div>

```auto
this.db.run("INSERT INTO bestellung(rid,bid,tableno,drink,price,validation) VALUES(`"+ridJSON.id+"`,`"+bidJSON.id+"`,"+tableno+","+ name+","+kpreis+","+validation+")", (err) =>
   ...

```

I notice that when you construct your sql query some VALUES are also surrounded with ` (backticks) .. i guess the ones that are supposed to be strings but some are not.

What if you try to use backticks for **drink** and **validation** columns also ?  
for variables **name** and **validation**

```auto
this.db.run("INSERT INTO bestellung(rid,bid,tableno,drink,price,validation) VALUES(`"+ridJSON.id+"`,`"+bidJSON.id+"`,"+tableno+",`"+ name+"`,"+kpreis+",`"+validation+"`)", (err) =>

```

ps1. also it would be good to send your values in the sql run as parameters as to minimize the risk of sql injection. I dont know much about it but see an example of parameterized queries in this [article](https://www.sqlitetutorial.net/sqlite-nodejs/insert/)

ps2. is this Node-red related ? 😉 or has the Node-red forum started attracting people for any coding problem ? hehe

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 April 2021 19:05 UTC](https://discourse.nodered.org/t/error-while-inserting-uuid-into-sqlite3-in-express/41302/8 "2021-04-20T19:05:36Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
