# INSERT hexadecimal in SQLITE

**URL:** https://discourse.nodered.org/t/insert-hexadecimal-in-sqlite/5884
**Category:** General
**Created:** [17 December 2018 13:45 UTC](https://discourse.nodered.org/t/insert-hexadecimal-in-sqlite/5884 "2018-12-17T13:45:43Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Andre](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andre/32/4554_2.png) [@Andre](https://discourse.nodered.org/u/Andre)
#### Post date: [17 December 2018 13:45 UTC](https://discourse.nodered.org/t/insert-hexadecimal-in-sqlite/5884/1 "2018-12-17T13:45:43Z")

</div>

I would like to add a hexidecimal key of an RFID tag like 3D433FF4A in SQlite

This is my code to create a table in Sqlite:

> CREATE TABLE userlist\_9(currentdate DATE, rfid TEXT, number INTEGER)

This is my code to add something to Sqlite:

> ```
> var timestamp = Date.now();
> var rfid = global.get("rfid_key")
> var counter_locker = global.get("counter_locker")
> var newMsg = {
> "topic": "INSERT INTO userlist_9 VALUES ( " + timestamp + "," + rfid + ", " + counter_locker + ")"
> }
> 
> return newMsg;
> 
> ```

**With normal numbers it works fine, but with hexidecimal numbers I get the following error:**

> "Error: SQLITE\_ERROR: unrecognized token: "2b334f""

---

<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: [17 December 2018 14:05 UTC](https://discourse.nodered.org/t/insert-hexadecimal-in-sqlite/5884/2 "2018-12-17T14:05:42Z")

</div>

Put a debug node showing complete message on the output of the function node and show us what it says.  
[Edit] also what data types are the fields in the table?

---

<div class="post-metadata">

### Author: ![Andre](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andre/32/4554_2.png) [@Andre](https://discourse.nodered.org/u/Andre)
#### Post date: [17 December 2018 15:24 UTC](https://discourse.nodered.org/t/insert-hexadecimal-in-sqlite/5884/3 "2018-12-17T15:24:23Z")

</div>

> 17-12-2018 16:21:56[node: 7466966b.94f148](http://127.0.0.1:1880/#)INSERT INTO userlist\_9 VALUES ( 1545060116109,2b334f, 1) : msg : Object
> 
> object
> 
> topic: "INSERT INTO userlist\_9 VALUES ( 1545060116109,2b334f, 1)"
> 
> \_msgid: "12917f9e.727e4"!

 ![Knipsel](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/1ee69624bfa69ef39ac40c68e76a02ff9c8b966b.png)

![Knipsel](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/034ffb99049729aee715fafb2d505a10d46ac033.png)

---

<div class="post-metadata">

### Author: ![Andre](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andre/32/4554_2.png) [@Andre](https://discourse.nodered.org/u/Andre)
#### Post date: [17 December 2018 15:28 UTC](https://discourse.nodered.org/t/insert-hexadecimal-in-sqlite/5884/4 "2018-12-17T15:28:49Z")

</div>

With normal numeric value: No error

![Knipsel](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/ca1182f4c9d36326d3ff2b993b00459260c25a29.png)

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [17 December 2018 15:38 UTC](https://discourse.nodered.org/t/insert-hexadecimal-in-sqlite/5884/5 "2018-12-17T15:38:21Z")

</div>

If you want to insert text into the table you need to wrap it in quotes.

```auto
INSERT INTO userlist_9 VALUES ( 1545060116109,"2b334f", 1)

```

It works when you try inserting a number because it can be parsed without the quotes around it.

---

<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: [17 December 2018 15:43 UTC](https://discourse.nodered.org/t/insert-hexadecimal-in-sqlite/5884/6 "2018-12-17T15:43:14Z")

</div>

> [@knolleary](#):
>
> INSERT INTO userlist\_9 VALUES ( 1545060116109,"2b334f", 1)

I think you can (should?) use single quotes in sqlite, which makes it a bit simpler coding the string.

---

<div class="post-metadata">

### Author: ![Andre](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andre/32/4554_2.png) [@Andre](https://discourse.nodered.org/u/Andre)
#### Post date: [17 December 2018 17:44 UTC](https://discourse.nodered.org/t/insert-hexadecimal-in-sqlite/5884/7 "2018-12-17T17:44:56Z")

</div>

Thank you, it works  
The user (RFID KEY) is added to the system if he does not appear in the database.

> var timestamp = Date.now();  
> var rfid = global.get("rfid\_key")  
> var rfid2 = ('"' + rfid + '"');
> 
> var counter\_locker = global.get("counter\_locker")
> 
> var newMsg = {  
> "topic": "INSERT INTO userlist\_9 VALUES ( " + timestamp + "," + rfid2 + ", " + counter\_locker + ")"  
> }
> 
> return newMsg;

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a321ec01202a1eed0bd619347325a7d006aa150d.png)
