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.
{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:
Text field which you can use to enter device name
In case it exists in the table, you'll get count column value (you can update it with link column name)
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.
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}
Change both ...space_id... occurrences with id of the space that you're using.
Replace all occurrences of Name with column name that you're using for storing device name (I assume it is samsung-model)
Replace all occurrences of count with column name that you're using for storing URL.
Replace all occurrences of Table with your table name.
If you still have problems, share your resulting snippet. You can find instruction here.
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.