#1 2016-06-09 08:42:31

squirrel
Member
Registered: 2015-08-13
Posts: 155

Linux Odbc

Is it possible to use Mormot's Odbc connection in Linux?  It looks like TODBCLib.Create tries to load a Windows library, odbc32.dll which is not possible in linux.  Or is there a different directive which must be set to enable this on Linux FPC?

aConnection := TODBCConnectionProperties.Create('',ConnectionString,'',DBPassword); 

Offline

#2 2016-06-09 09:12:54

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Linux Odbc

I never tested ODBC in Linux, but I guess it should be possible.

What is the library name under Linux?
Try to modify/fix the SynODBC.pas unit, and send it to me (by email or via a dropbox link) so that I apply the changes.

Offline

#3 2016-06-09 10:00:06

squirrel
Member
Registered: 2015-08-13
Posts: 155

Re: Linux Odbc

I changed it like this and it seamed to work.  Not sure how different versions should be handled.  It is conceivable that someone might be using libodbc.so.2 and not the libodbc.so.1 that worked for me.

constructor TODBCLib.Create;
var P: PPointer;
    i: integer;
    dllname: string;
begin
  {$IFDEF LINUX}
    dllname := 'libodbc.so.1';
  {$ELSE}
    dllname := 'odbc32.dll';
  {$ENDIF}
  fHandle := SafeLoadLibrary(dllname);
  if fHandle=0 then
    raise EODBCException.Create('Unable to find ODBC Client Interface (' + dllname + ')');
  P := @@AllocEnv;
  for i := 0 to High(ODBC_ENTRIES) do begin
    P^ := GetProcAddress(fHandle,ODBC_ENTRIES[i]);
    if P^=nil then begin
      FreeLibrary(fHandle);
      fHandle := 0;
      raise EODBCException.CreateFmt('Invalid ' + dllname + ': missing %s',[ODBC_ENTRIES[i]]);
    end;
    inc(P);
  end;
end;   

Last edited by squirrel (2016-06-09 10:35:54)

Offline

#4 2016-06-09 10:35:19

squirrel
Member
Registered: 2015-08-13
Posts: 155

Re: Linux Odbc

Would it be possible to do a Linux implimentation of ODBCInstalledDriversList?  The odbc drivers are listed in /etc/odbcinst.ini and the odbc dsns are listed in /etc/odbc.ini

Example drivers ini file:

[MySql 5.1]
Description		= MySql 5.1
Driver			= /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
Driver64		= /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
Setup		= /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
Setup64		= /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so

I did a very basic implimentation of ODBCInstalledDriversList for Linux, but getting the correct version numbers might be tricky:

function ODBCInstalledDriversList(const aIncludeVersion: Boolean; out aDrivers: TStrings): Boolean;
const
  OdbcInstLocation = '/etc/odbcinst.ini';
var
  Ini: TIniFile;
begin
  Result := FileExists(OdbcInstLocation);
  if Result then begin
    Ini := TIniFile.Create(OdbcInstLocation);
    if not Assigned(aDrivers) then
      aDrivers := TStringList.Create;
    Ini.ReadSections(aDrivers);
    Ini.Free;
  end;
end;

I found a problem using the ODBCInstalledDriversList function in Windows 10.  The OpenKey would always return false even when running as administrator, however replacing it with OpenKeyReadOnly works 100%:

    result := OpenKeyReadOnly('Software\ODBC\ODBCINST.INI\ODBC Drivers') or
              OpenKeyReadOnly('Software\ODBC\ODBCINST.INI');

Last edited by squirrel (2016-06-09 11:23:07)

Offline

#5 2016-06-09 12:44:43

d.ioannidis
Member
From: Greece
Registered: 2016-06-03
Posts: 20

Re: Linux Odbc

Hi,

  IMO, you should check the FPC's odbcconnection and
odbcsql unit's for hint's on linux .

regards,


Dimitrios Chr. Ioannidis

Offline

#6 2016-06-09 15:23:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Linux Odbc

See http://synopse.info/fossil/info/e31f89e2f8
and http://synopse.info/fossil/info/a31e792fc3

Still more modifications are needed for full Linux support.

Offline

Board footer

Powered by FluxBB