The Devart company released UniDAC with support for Linux 64-bit platform. UniDAC makes application development and maintenance easier and simpler because the use of the 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 the Direct mode:
- ASE
- DBF
- MongoDB
- 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 on the main menu, click New, then click Other
In the appeared dialog box, click Console Application.
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
MongoDBUniProvider, // add this unit for MongoDB
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 the Direct mode
The Deployment tab contains only the application file – there are no additional libraries or files:
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:
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:
Delphi-code for MongoDB:
UniConnection.ProviderName := 'MongoDB';
UniConnection.Server := 'MongoDBServer';
UniConnection.Port := 27017;
UniConnection.SpecificOptions.Values['BSONLibrary'] := '/usr/lib64/libbson-1.0.so';
UniConnection.SpecificOptions.Values['ClientLibrary'] := '/usr/lib64/libmongoc-1.0.so';
UniConnection.Database := 'demo';
UniConnection.Connect;
Writeln(#13#10+'--== UniDAC MongoDB Provider ==--'+#13#10);
Writeln(UniConnection.ServerVersionFull);
MongoDB_Insert_EMP(UniQuery);
WritelnQuery(UniQuery, '{"find":"emp", projection:{_id:0, empno:1, ename:1, job:1, hiredate:1}}');
MongoDB execution result:
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:
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:
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:
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:
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:
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:
Here is the complete project source code: UniDAC_Linux
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.
When you refer to DBF – does that mean dbase compatible files ?
Thanks
Hello, Peter!
Thank you for the comment. The list of supported DBF formats you can find by the link: https://www.devart.com/unidac/compatibility.html
Hi,
thanks for great products!,
where can we found our PostgreSQL dabase located in Windows 7?
Hello, Kerbadou!
The question about DB administration is not related to UniDAC functionality. Please contact your DB administrator or PostgreSQL provider to get an answer to this question.
Will you support Informix in the near future?
Regards.
Hur
Hello, Hur!
If you have an ODBC driver for Informix, you can work with Informix using UniDAC and this driver. A possibility of working with Informix without ODBC is not on our roadmap.