Magic XPA - SQlite #sqlite #xpa


Gustavo <gustavo.lima@...>
 

Good morning,

I would like to know how to configure an SQLite database within Magic XPA and import the existing tables from my database into Magic. Could you assist me in performing this action? Thank you!


Roberto Ramirez Cervantes
 

Hello Gustavo,

To use the SQLite database in Magic you will need:
1. The file "mgsqlite.dll" should exist in the folder {Magic installation folder}\Gateways\    
If the file is not there run the installation of Magic again and selected from the available Databases OR download it from the SQLite site (https://www.sqlite.org/download.html)
2. In the Magic.ini file, under the [MAGIC_GATEWAYS] section make sure the line to load this database is not commented out:
MGDB09=Gateways\mgSQLite.dll
3. When you open the Magic Studio and go to Help|About, you should be able to see a SQLite entry.

Then to import data from existing databases into SQLite you can take 3 different paths:
1. If your original database is SQL-like: generate the scripts to Create Tables and Insert Statements, then use a 3rd party tool (https://sqlitebrowser.org/) to create the Tables and Insert Statements into a new Database in SQLite you might need to change some statements to comply with SQLite requirements.
In Magic Studio go to Options|Settings|Databases and create a new entry that will use the SQLite DBMS and point it (Location) to the new database created in the previous step.
Open your application, go to the Data Repository, go to the top of the Data Repository, press F9, select the Database entry that you just created, set Tag data sources to "Several", press F5 on the Data sources, and select the tables that you want Magic to have access to.
Now you should have the definition of the selected tables in Magic and data available on those tables.

2. If your original database is NOT SQL-like: export the data from those tables into csv\text files.
In Magic Studio go to Options|Settings|Databases and create a new entry that will use the SQLite DBMS and point it (Location, ie. "MyNewDatabase.sqlite") to the to where this data will reside.
Open your application, go to the Data Repository, and create the definition for all the tables that you want to access.
Generate a program to import the data from the correspondent csv\text file.

2. If you have the definition of these tables in Magic already:
In Magic Studio go to Options|Settings|Databases and create a new entry that will use the SQLite DBMS and point it (Location, ie. "MyNewDatabase.sqlite") to the to where this data will reside.
Open your application that has the definition of the existing tables, go to the Data Repository, make a copy\duplicate (Ctrl+Shft+R) all the existing tables, go to each duplicated entry and make the required modifications so it will point to the new database created in the previous step.
Generate batch program to read all the record from the existing table and Link Write\Create to the duplicated table in SQLite.

I hope this helps you

Roberto