Add new device automatically in Data Blaze

Hello,

I want to make a table with names from devices in the left column and links to videos in the right column. In text blaze I want to choose the name of the device and then the URL should be pasted in the textfield. This works very well.

But now I need a solution in case the device I am looking for is not yet in the database. It would be ideal if in this case a window would open in which I could enter the device name and the link directly manually, so that the device is automatically added to the database and the entry is also displayed directly in the text window.

Is this possible?

Hi @kamuro,

Here is one way to do it:

{formtext: name=LookedName}
{dbselect: SELECT Name, Count FROM Table WHERE Name == {=LookedName}; space=...space_id...; menu=no; haserror=haserror}
{if: haserror}
{dbinsert: INSERT INTO Table SET name=@LookedName, count=@count; space=...space_id...}
{else}
{=count}
{endif}

It consists of a few commands:

  1. Text field which you can use to enter device name
  2. In case it exists in the table, you'll get count column value (you can update it with link column name)
  3. Otherwise it fails and you'll get into if condition block which will display another text field to enter the value for it. Once you fill that and click insert, it will trigger dbinsert command which will insert a new row to the table.
2 Likes

Hi @Mansur_Kutybayev

that sounds very good, but unfortunately I can't get it to work for me. I guess I'm being too stupid:

  1. Here is the command I shared with you above, but in plain text format (you can achieve the same result by double clicking every command chip in the dashboard).
{formtext: name=LookedName}
{dbselect: SELECT Name, Count FROM Table WHERE Name == {=LookedName}; space=...space_id...; menu=no; haserror=haserror}
{if: haserror}
{dbinsert: INSERT INTO Table SET name=@LookedName, count=@count; space=...space_id...}
{else}
{=count}
{endif}
  1. Change both ...space_id... occurrences with id of the space that you're using.
  2. Replace all occurrences of Name with column name that you're using for storing device name (I assume it is samsung-model)
  3. Replace all occurrences of count with column name that you're using for storing URL.
  4. Replace all occurrences of Table with your table name.

If you still have problems, share your resulting snippet. You can find instruction here.

1 Like

{dbselect: SELECT Samsung-Model FROM Samsung Hardreset Videos ORDER BY Samsung-Model ASC; space=0xJGk....; menu=no; haserror=haserror}
{if: haserror}
{dbinsert: INSERT INTO Samsung Hardreset Videos SET Samsung-Model=@LookedName, Link=@count; space=0xJGk....}
{else}
{=Link}
{endif}

Add your space id to both bsql queries:

{formtext: name=LookedName}
{dbselect: SELECT Samsung-Model, Link FROM Samsung Hardreset Videos WHERE Samsung-Model == {=LookedName}; space=; menu=no; haserror=haserror}
{if: haserror}
{formtext: name=newlink}
{dbinsert: INSERT INTO Samsung Hardreset Videos SET Samsung-Model=@LookedName, Link=@newlink; space=; autoaddfields=yes}
{else}
{=Link}
{endif}

I added my space-id, but it didn't work:

Added backticks, now it should work fine. Again, add space id to both BSQL queries.

{formtext: name=LookedName}
{dbselect: SELECT `Samsung-Model`, Link FROM `Samsung Hardreset Videos` WHERE `Samsung-Model` == {=LookedName}; space=; menu=no; haserror=haserror}
{if: haserror}
{formtext: name=newlink}
{dbinsert: INSERT INTO `Samsung Hardreset Videos` SET `Samsung-Model`=@LookedName, Link=@newlink; space=; autoaddfields=yes}
{else}
{=Link}
{endif}

Thank you for your efforts. There is no error message now, but entries are only found if the model name is entered completely. Is it possible to search for parts of the name, like you can search for snippets in textblaze?

What also doesn't work is adding new entries to the database. There is no error message, but no new entry is created either.

This should search for all names that start with what you provide. In case you want to find all models that has occurrence of what you are searching, replace startswith with contains.

{formtext: name=LookedName}
{dbselect: SELECT `Samsung-Model`, Link FROM `Samsung Hardreset Videos` WHERE startswith(`Samsung-Model`, {=LookedName}); space=; menu=no; haserror=haserror}
{if: haserror}
{formtext: name=newlink}
{dbinsert: INSERT INTO `Samsung Hardreset Videos` SET `Samsung-Model`=`@Samsung-Model`, Link=@newlink; space=}
{else}
{=Link}
{endif}

Also please take a look at your system notifications, in case dbinsert error, it should pop up there.