How to Connect to SQLite 3


Purpose of this article

This article aims to show you how to download, install and connect SQLite 3 with ADISRA SmartView.

Downloading and Installing SQLite 3

SQLite is a library made with C language for the user to implement a database in a simple and fast way. It is usually used for small applications.

  1. Go to the website https://sqlitestudio.pl/ and download the latest version of SQLite Studio.
  1. Download the latest version of SQLite.

Note: After downloading SQLite Studio, it is not necessary to install it, as the executable file is already available in the folder.

  1. Then download the ODBC driver compatible with your processor (x64 or x86) available from the links below.

Link Driver(x86): https://guides.adisra.com/wp-content/uploads/2020/03/sqliteodbc_w32_Driver.zip
Link Driver(x64): https://guides.adisra.com/wp-content/uploads/2020/03/sqliteodbc_w64_Driver.zip

  1. Install the ODBC driver.
  1. Extract the SQLite Studio files and run the SQLiteStudio.exe file.
  1. Now, let’s create a “Database” as an example. So, click on the “Database” menu, then click on the “Add a database” option.
  1. In the “Database type” field, keep SQLite3 and in the “File” field, put the database name as “DB_Adisra”. Then click OK.
  1. In the navigation tree, expand the database and then right-click on the item “Tables” and then click on “Create a Table”.
  1. In the “Table name:” field, enter the name “Person” for the new table.
  1. Now let’s create a column inside the “Person” table. To do this, click on the “Add Columns” button as shown in the image below.
  1. In the “Column name” field, enter Name, in the “Data type:” field, enter VARCHAR and in the “Size:” field, enter the value 50 as shown in the image below and then click OK.
  1. Below the first column of the “Person” table created successfully.
  1. Validate the changes click on the “Commit Structure Changes” button. After clicking this button, a window will open. Click OK.
  1. Now, let’s insert data into our “Name” column. To do so, click on the “Data” tab and then click on the “Insert Row” button.
  1. Insert three lines with some names as shown in the image below and click on the “Commit” button to validate.

Adding DSN in ODBC Data Source

Now, we will add a DSN in the Windows ODBC Data Source.

  1. In the Windows start menu, search for “ODBC Data Source”. Click on ODBC Data Source x64 or x86 bits. It is also possible to access the “ODBC Data Source” configuration via the path (Control Panel -> Administrative Tools -> ODBC Data Sources).
  1. In the ODBC Data Source settings window, click on the “Add…” button to add a new source.
  1. Then select the Driver “SQLite3 ODBC Driver and then click Finish button.
  1. In the “Data Source Name:” field, enter the name of the new source. Put “DB_ADISRA”. In the “Databse Name:” field, click on the “Browse…” button and search for the path of the database created in SQLite Studio”.
  1. Probably the “DB_Adisra.db” file is in the SQLite Studio folder as shown in the image below. Select the file and click the “Open” button.
  1. Then click on the OK button.
  1. The new ODBC source was created successfully. Now click OK.

Configuring ADISRA SmartView

  1. Create a new application. In the top menu, click on the “Settings” tab and click on the “Database Connections” option.
  1. Click the “+” button to add a new connectivity.
  1. Select the “Microsoft ODBC Data Source” option and click OK.
  1. Select the option “Use user or system data source name:” and then in the list below click on the database “DB_ADISRA”, in which it was created previously.
  1. Test the communication by clicking the “Test Connection” button. Then click the OK button in the test window and then click OK to close the configuration window.
  1. Keep the database name as “ODBC001” and click OK.

Querying DB_ADISRA database information

  1. Create a new Graphic, insert a “Datagrid” object.
  1. In the property list of the datagrid object, in the “Datagrid Config” property, select the option “Table”, “ODBC001” and “Person”.
  1. In the list below, enter exactly the name of the column in which we will make the query, that is, the column “Name” created in SQL Studio. Also enter the width of the “Name” column of the datagrid object. Then click on the “Add” button. If you want, you can remove the blank column.
  1. Below the expected result.
  1. Now, save the application and set “Graphic1” as the initial Graphic of the Runtime and then start the RunTime. Below the expected result.