You are not logged in.
Pages: 1
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
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
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
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
Dimitrios Chr. Ioannidis
Offline
See http://synopse.info/fossil/info/e31f89e2f8
and http://synopse.info/fossil/info/a31e792fc3
Still more modifications are needed for full Linux support.
Offline
Pages: 1