How to connect your app to a Data Base
Paradise allows you to use database as a data source for the screens. It can work with the following db engines:
- Sql Server
- Sql Lite (Local)
Except in the case of SQL Lite, the database must be visible from the Paradise server.
Sql Lite allows a local database on Android and Iphone. This functionality is not available on Windows Phone and Blackberry.
Note that when your app is running it will not connect directly to the database (except for Sql Lite), it will connect to a Paradise server and this will execute the statement in the database, process the result and send it to the phone.
The first thing you need to do to start using a database in your application is to create the connection string. On the tab "Project", click on "Databases" and then on "Create New Connection":
On this screen you must give a name to identify the connection, a provider and the value of the connection string. Once set, you must click "Test Connection" to verify connectivity between the Paradise server and the database.
In case you want to use the provider "Local" should enter the commands to create and populate the local database in the browser. You must enter one statement per line For example:
DROP TABLE IF EXISTS MediaTypes CREATE TABLE MediaTypes(MediaTypeId int NOT NULL, MediaType varchar(50) NOT NULL) INSERT INTO MediaTypes (MediaTypeId, MediaType) VALUES (0, 'None') INSERT INTO MediaTypes (MediaTypeId, MediaType) VALUES (1, 'Audio') INSERT INTO MediaTypes (MediaTypeId, MediaType) VALUES (2, 'Video') DROP TABLE IF EXISTS Users CREATE TABLE Users...
For a local connection the "Test Connection" button will create the database in the browser.
Once the setup is complete, click "Save".
After the connection is created we can use it in our screens. To add a data source to the screen drag a component of type "Database Data Source" to your screen:
This will add the component below the footer of your application. Click the database and then click the "Configure" in the panel "Control (DataSource)" to open the configuration screen.
This is where you define the query to execute against the database. First you must select the connection on the Drop Down named "Source". Then you should write the query to execute. Once set, you must click "Preview" to get the resulting structure and be able to bind it to the screen controls.
In case your query has parameters should define them as "@parameterName", for example:
Select * From Products Where ProductName = @productName
By losing the focus of the text box "Query", if you have parameters, they will be created in a table so that you can map these parameters to the current screen controls or previous screens controls. In case that the parameter does not have any mapping added, it will use the default value to execute the query.
To see how to map datasource values to controls, please check the section "Mapping controls to data" in the Help Section.