Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Database App Development and Deployment to Linux in RAD Studio

DZone's Guide to

Database App Development and Deployment to Linux in RAD Studio

Learn how to create apps for Linux without deploying anything additional. You only need to install UniDAC and write a few code lines.

· Database Zone ·
Free Resource

MariaDB TX, proven in production and driven by the community, is a complete database solution for any and every enterprise — a modern database for modern applications.

The Devart company recently released UniDAC with support for Linux 64-bit platform. UniDAC makes application development and maintenance easier and simpler because the use of Direct mode in a custom application does not require the installation of client libraries, additional drivers, etc. This helps to avoid the overhead when accessing a DBMS, hence increasing performance.

So, in this article, we will demonstrate the capability of UniDAC to establish a connection to various DBMSs in Direct mode:

  • ASE
  • DBF
  • MySQL
  • Oracle
  • PostgreSQL
  • SQLite
  • SQL Azure
  • SQL Server

Creating a Console Application

Let’s create a new UniDAC application for Linux 64-bit in RAD Studio 10.2 Tokyo.

Go to File > New > Other:

Image title

In the dialog box that appears, click Console Application.

Image title

Configuring UniDAC to Connect in the Direct Mode

To use UniDAC in a console application, you should add the Uni unit in the uses section, as well as the unit with the UniDAC provider for each DBMS. Let’s add providers for all DBMSs which are mentioned at the beginning of the article:

program UniDAC_Linux;
{$APPTYPE CONSOLE}
{$R *.res}
uses
  SysUtils,
  Uni,
  ASEUniProvider,         // add this unit for ASE
  DBFUniProvider,         // add this unit for DBF 
  MySQLUniProvider,       // add this unit for MySQL 
  OracleUniProvider,      // add this unit for Oracle 
  PostgreSQLUniProvider,  // add this unit for PostgreSQL 
  SQLiteUniProvider,      // add this unit for SQLite 
  SQLServerUniProvider;   // add this unit for SQL Server & SQL Azure 

Creating connection and dataset instances, as well as executing SQL queries and data fetching are similar for all UniDAC providers:

var
  UniConnection: TUniConnection;
  UniQuery: TUniQuery;
begin
  UniConnection := TUniConnection.Create(nil);
  UniQuery := TUniQuery.Create(nil);
  UniQuery.Connection := UniConnection;

Establishing Connection and Data Fetching in Direct Mode

The Deployment tab contains only the application file; there are no additional libraries or files:

Image title

Delphi-code for ASE:

UniConnection.ProviderName := 'ASE';
UniConnection.SpecificOptions.Values['Direct'] := 'True';
UniConnection.Server := 'ASE_DB';
UniConnection.Port := 5000;
UniConnection.Username := 'sa';
UniConnection.Password := '*****';
UniConnection.Database := 'DEMO';
UniConnection.Connect;
Writeln(#13#10+'--== UniDAC ASE Provider ==--'+#13#10);
WritelnQuery(UniQuery, 'select @@version');
WritelnQuery(UniQuery, 'select empno, ename, job, hiredate from emp');

ASE execution result:

Image title

Delphi-code for DBF:

UniConnection.ProviderName := 'DBF';
UniConnection.SpecificOptions.Values['DBFFormat'] := 'dfdBaseVII';
UniConnection.SpecificOptions.Values['Direct'] := 'True';
UniConnection.Database := '/home/test/Documents';
UniConnection.Connect;
Writeln(#13#10+'--== UniDAC DBF Provider ==--'+#13#10);
WritelnQuery(UniQuery, 'select empno, ename, job, hiredate from emp');

DBF execution result:

Image title

Delphi-code for MySQL:

UniConnection.ProviderName := 'MySQL';
UniConnection.Server := 'MySQL_db';
UniConnection.Port := 3312;
UniConnection.Username := 'root';
UniConnection.Password := '*****';
UniConnection.Database := 'demo';
UniConnection.Connect;
Writeln(#13#10+'--== UniDAC MySQL Provider ==--'+#13#10);
WritelnQuery(UniQuery, 'select @@version');
WritelnQuery(UniQuery, 'select empno, ename, job, hiredate from emp');

MySQL execution result:

Image title

Delphi-code for Oracle:

UniConnection.ProviderName := 'Oracle';
UniConnection.SpecificOptions.Values['Direct'] := 'True';
UniConnection.Server := 'ORCL12C:1521/pdborcl';
UniConnection.Username := 'scott';
UniConnection.Password := '******';
UniConnection.Connect;
Writeln(#13#10+'--== UniDAC Oracle Provider ==--'+#13#10);
WritelnQuery(UniQuery, 'select * from v$version');
WritelnQuery(UniQuery, 'select empno, ename, job, hiredate from emp');

Oracle execution result:

Image title

Delphi-code for PostgreSQL:

UniConnection.ProviderName := 'PostgreSQL'; 
UniConnection.Server := 'pg_db'; 
UniConnection.Database := 'demo'; 
UniConnection.Username := 'postgres'; 
UniConnection.Password := '******'; 
UniConnection.Port := 5432; 
UniConnection.Connect; 
Writeln(#13#10+'--== UniDAC PostgreSQL Provider ==--'+#13#10); 
WritelnQuery(UniQuery, 'select version()');
WritelnQuery(UniQuery, 'select empno, ename, job, hiredate from emp');

PostgreSQL execution result:

Image title

Delphi-code for SQLite:

UniConnection.ProviderName := 'SQLite';
UniConnection.SpecificOptions.Values['Direct'] := 'True';
UniConnection.SpecificOptions.Values['ForceCreateDatabase'] := 'True';
UniConnection.Database := ':memory:';
UniConnection.Connect;
Writeln(#13#10+'--== UniDAC SQLite Provider ==--'+#13#10);
Writeln(UniConnection.ServerVersionFull);
SQLite_Create_EMP(UniQuery);
SQLite_Insert_EMP(UniQuery);
WritelnQuery(UniQuery, 'select empno, ename, job, hiredate from emp');

SQLite execution result:

Image title

Delphi-code for SQL Azure:

UniConnection.Disconnect;
UniConnection.ProviderName := 'SQL Server';
UniConnection.SpecificOptions.Values['Provider'] := 'prDirect';
UniConnection.Server := 'qps1hrvdke.database.windows.net';
UniConnection.Database := 'DEMO';
UniConnection.Username := '****@qps1hrvdke';
UniConnection.Password := '*******';
UniConnection.Port := 1433;
UniConnection.Connect;
Writeln(#13#10+'--== UniDAC SQL Server(Azure) Provider ==--'+#13#10);
WritelnQuery(UniQuery, 'select @@version');
WritelnQuery(UniQuery, 'select empno, ename, job, hiredate from emp');

SQL Azure execution result:

Image title

Delphi-code for SQL Server:

UniConnection.Disconnect;
UniConnection.ProviderName := 'SQL Server';
UniConnection.SpecificOptions.Values['Provider'] := 'prDirect';
UniConnection.Server := '192.168.0.15\MSSQL2016';
UniConnection.Database := 'DEMO';
UniConnection.Username := 'sa';
UniConnection.Password := '*****';
UniConnection.Port := 1433;
UniConnection.Connect;
Writeln(#13#10+'--== UniDAC SQL Server Provider ==--'+#13#10);
WritelnQuery(UniQuery, 'select @@version');
WritelnQuery(UniQuery, 'select empno, ename, job, hiredate from emp');

SQL Server execution result:

Image title

Here is the complete project source code.

Conclusion

In this article, we showed how easily and simply you can create applications for Linux without deploying additional files, client libraries, or drivers. For this, you only need to install UniDAC, write a few code lines, and the application to work with databases on Linux is complete.

MariaDB AX is an open source database for modern analytics: distributed, columnar and easy to use.

Topics:
linux ,sql ,mysql ,sql server ,database ,database application ,tutorial ,data fetching

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}