SQLite Can't Connect

I am trying to connect to an SQLite database. In the examples in this forum (@Andrew_Hannell) the Slingshot Query Node FilePath is linked to a file with a .sqlite extension. How is this file generated? (I have SQLite Studio - I can export to .sql but not .sqlite).

Thanks

Hi Ben

It has been a while- so I can’t quite remember.
Try this:
https://wiki.sqlitestudio.pl/index.php/User_Manual#Creating_new_database

Andrew

Thanks Andrew. I had a look through it but couldn’t see how to export to .sqlite…

Hi Ben

If you provide a sample of data you want (in Excel or a format of rows & columns) I will take a look & explain how it is done

Andrew

Data.xlsx (11.1 KB)
Hi Andrew

I’ve attached a very simple spreadsheet with 2 items. I would like to lookup the ID (Column A) using a value from Dynamo and retrieve the Description (Column B) from the database back into Dynamo.

Ben,

there are a number of tutorials on how to create a table in SQLiteStudio- so I won’t repeat them here. Basically the steps are:

  1. Create a database.

  2. Create a table to contain your data, and columns in the table. You can do this via the UI, or with a query. To run a query, open the SQL editor and paste in the below, then hit the go button (F9)

     CREATE TABLE TBL (
         ID                    INTEGER (10) PRIMARY KEY,
         Description           TEXT (255),
         Category_Abbreviation TEXT (255),
         Notes                 TEXT (255),
         Model                 TEXT (255),
         K_Coefficient         TEXT (255),
         Specific_Loss         TEXT (255),
         Dimension_Image       TEXT (255) 
     )
    
  3. Populate the table. You can do this by importing a CSV file using the GUI, or another query:

     INSERT INTO TBL (ID,Description,Category_Abbreviation) VALUES
     (1,'Gate Valve Flanged DN50','V'),
     (2,'Full Flow Valve DN25','V')
    

The SQL might look a bit cryptic, but is is the quickest & easiest way once you get used to it. But if you prefer, all this can be done via the GUI.

Refer


<a class=“attachment”
Remove the .txt file extension from the attached database file & you will be able to open & edit it
DB1.sqlite.txt (8 KB)

After that- you just need to update your model, as per your screenshot

hope this helps

Andrew

2 Likes

Thank you Andrew, that works very well!

Using a string as a File Path was where my code seemed to go wrong - changing this to the File Path node made it work.

The only thing I was never able to work out was how to get the database to a file with the extension x.sqlite? (the files I see when creating a new database are x.db, x.db.sqbpro, x.sql). I am able to open and manipulate your .sqlite file so it is easy for me to copy and edit it but I am still curious as to how it was first generated…

Hi Ben

these are the options I get in SQLiteStudio under ‘Add a database’

I’ve got this version

1 Like

Thanks Andrew.

Hi @Andrew_Hannell

I tried to import door-related parameters from my Revit model to SQLite database, but as shown in the attached pics, I couldn’t. I think something is wrong here, but I don’t know what it is. The parameters could be successfully extracted from my Revit model, but cannot be sent to the SQLite database. Would you please look at my graph and tell me where the problem is? Thanks

Isn’t this the same question that you already asked in a different post (and I’ve already answered) ?

In SQL syntax, column names with spaces need to be enclosed in square brackets. As I’ve said, the simple solution is to not use spaces in column names. Otherwise, put your column names in square brackets in Dynamo.

Put a watch node on your SQL.InsertInto node and you will see that it is not properly formed SQL
it needs to be:
Insert into TABLE([Field 1]) values ('xxxx1234')
not
Insert into TABLE(Field 1) values ('xxxx1234')