Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / Win32

UniDAC - database's direct connection

2.09/5 (4 votes)
29 Sep 2015CPOL3 min read 18.7K  
UniDAC allows you to connect your cross-platform application directly with many database's types.

Introduction

UniDAC (Universal Data Access Component) is a powerfull library of nonvisual components developed by Devart, that provides direct access to multiple databases across many type of IDE on Windows, MAC OS X, iOS, Android, etc. UniDAC offers unified approach to the database-related applications development process like Oracle, MySQL, InterBase, Microsoft SQL Server, Firebird, Postgre SQL, etc.

The principal advantage of UniDAC technology is that it's easy to setup. 

Detailed description

With UniDAC you can easily switch between different databases in your projects without delving into their specifications. It is very convenient in setup and use, providing independent interface server to work with different databases.

UniDAC consists essentialy of two elements: The first is its engine, which provides the developer a common, unified programming interface, receptive to the various supported databases. The second element can be considered its most important part, which is your data access layer itself. Here it is made by providers access to data, which will provide interaction between the engine and the various database servers supported. Each provider is then responsible for working with a specific database server (eg TOracleUniProvider for Oracle, TInterBaseUniProvider for Postgre SQL).

Main features

  • Support the development of applications for Android;
  • Support the development of applications for iOS
  • Support NextGen compiler
  • Development support for Mac OS X
  • Development support for Win64
  • Universal access to different databases
  • Unicode support
  • Independent database storage with TVirtualTable component

Installation process

The UniDAC installation process is as natural as any other Windows application, provided by a Wizard which involves the traditional steps "Next-Next-Finish". Thus, at this moment, no further notice is necessary.

Just as a way to illustrate the installation itself, Figure 1 shows the initial stage of the process of version 5.0.2 of UniDAC in TrialVersion for Delphi XE4.

Image 1

The UniDAC is commercial product, however, as most commercial software, it provides an experimental free version, the TrialVersion, which allow unrestricted access to the product for a certain period, usually 30 days. In the case of UniDAC, this period is 60 days.

Using the code

To make examples of how to use, I gonna use MySQL database and Delphi language. We gonna use 2 components:

TUniConnection: allows to configure and manage the connection with the SGBD.

TUniQuery: allows to use SQL instructions to select, insert and update data in tables.

To configure the connection, lets change the properties like this:

Pascal
//
// Change properties to connection

//  provider name's property must be set to the database name you want to use
UniConnection1.providerName := 'MySQL';
// port must be set to the port that is use to connect, as default is 3306
UniConnection1.port := 3306;
// loginprompt defines if the prompt login must appear everytime that is tried to connect
UniConnection1.loginPrompt := False;
// server must be set to the connection address
UniConnection1.server := '192.168.0.5';
// username must be the user used to authenticate
UniConnection1.username := 'admin';
// password must be the pass used to authenticate
UniConnection1.password := 'pass';
// at finish, to set which database  must be connected, let's define the database name
UniConnection1.database := 'example_unidac';

With the code above, the connection can be done sucessfully, from any type of application, including Android and iOS application. To activate connection, we set connected property to true:

//
// To make connection activated, just have to be set "connected" property to True
UniConnection1.connected := True;

Well, here we finish the connection settings to make UniDAC works with MySQL. To use with another SGBD, the steps are the same, just adjusting the appropriate proprerties.

Now to use the query component, we must set the connection and the SQL statement:

//
// Set the connection method of query component
UniQuery1.connection := UniConnection1;
// set the SQL statement
UniQuery1.SQL.Text := 'SELECT * FROM cars';

In example, I'm using table named cars, just to show how to set the SQL statement. Doing that, query have to be activated to realize the select.

That' all! This is the initial tutorial to use UniDAC with any SGBD.

Points of Interest

To More Information, See the Page With https://www.devart.com/unidac Which Has All Support and Details of Component, in Addition to Several Other Interesting Components to Facilitate Your Development.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)