Recent

Author Topic: ODBC Question  (Read 19289 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
ODBC Question
« on: June 15, 2010, 08:56:15 am »
How do I see what I odbc active on the machine? Let me explain, how do I know the names of ODBC installed on the machine? Thanks
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1946
Re: ODBC Question
« Reply #1 on: June 15, 2010, 09:06:25 am »
What do you mean?
Drivers list, DSN, ... ?

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: ODBC Question
« Reply #2 on: June 15, 2010, 09:14:28 am »
Dsn is the list that the driver list
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1946
Re: ODBC Question
« Reply #3 on: June 15, 2010, 03:12:49 pm »
?

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: ODBC Question
« Reply #4 on: June 16, 2010, 12:50:08 am »
the other is the unche
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: ODBC Question
« Reply #5 on: June 21, 2010, 05:46:19 am »
What do you mean?
Drivers list, DSN, ... ?

Driver List and DSN List!  :)
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

spitofland

  • New Member
  • *
  • Posts: 26
Re: ODBC Question
« Reply #6 on: June 21, 2010, 06:21:57 am »
If I understand your question correctly, then I had the same question.
http://www.lazarus.freepascal.org/index.php/topic,9563.0.html

The answer I received was very helpful. It led me to this website:
http://www.delphi3000.com/articles/article_3584.asp

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: ODBC Question
« Reply #7 on: June 21, 2010, 06:27:45 am »
If I understand your question correctly, then I had the same question.
http://www.lazarus.freepascal.org/index.php/topic,9563.0.html

The answer I received was very helpful. It led me to this website:
http://www.delphi3000.com/articles/article_3584.asp

I had already tried to connect to that link, but will not let me open. You open it and do a copy paste here the content? Thanks
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

spitofland

  • New Member
  • *
  • Posts: 26
Re: ODBC Question
« Reply #8 on: June 21, 2010, 09:23:30 am »
I'm sorry that link does appear to be broken now. Here is the function that I created based on the information from that link. It retrieves the information from the registry. I hope this helps you.

This function fills a ComboBox with a list of ODBC DSNs availiable on the system. It should get the User DSNs and the System DSNs. You need to include the 'Registry' Unit in the Uses section.

Code: [Select]
procedure TLoginPrompt.GetDSNList;
var
  aStringList : TStringlist;
  aStrings1   : TStrings;
  aStrings2   : Tstrings;

  aRegistry   : TRegistry;
  aInt        : Integer;
  tempInt     : Integer;
Begin
  aStringlist:=TStringlist.Create;
  aStrings1:=TStringlist.Create;
  aStrings2:=TStringlist.Create;

  aRegistry:= Tregistry.Create;
  With aRegistry do Begin
    RootKey:=HKEY_CURRENT_USER;
    OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources',False);
    GetValueNames(aStrings1);
  End;
  aRegistry.Free;

  aRegistry:= Tregistry.Create;
  With aRegistry do Begin
    RootKey:=HKEY_LOCAL_MACHINE;
    OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources',False);
    GetValueNames(aStrings2);
  End;
  aRegistry.Free;

  aStringlist.AddStrings(aStrings1);
  aStrings1.Free;
  aStringlist.AddStrings(aStrings2);
  aStrings2.Free;
  aStringlist.Sort;
  ComboBox1.Clear;
  tempInt := 0;
  for aInt:=0 to aStringList.Count-1 do begin
    if Trim(aStringList[aInt]) <> '' then begin
      ComboBox1.Items.Add(Trim(aStringList[aInt]));
      INC(tempInt);
    end;
  end;
End;

Lacak2

  • Guest
Re: ODBC Question
« Reply #9 on: June 21, 2010, 09:27:56 pm »
Another approach is using ODBC32 API:
SQLDataSources()
SQLDrivers()

See here: http://www.delphipages.com/forum/showthread.php?t=107542

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: ODBC Question
« Reply #10 on: June 21, 2010, 09:38:30 pm »
I'm sorry that link does appear to be broken now. Here is the function that I created based on the information from that link. It retrieves the information from the registry. I hope this helps you.

This function fills a ComboBox with a list of ODBC DSNs availiable on the system. It should get the User DSNs and the System DSNs. You need to include the 'Registry' Unit in the Uses section.

Code: [Select]
procedure TLoginPrompt.GetDSNList;
var
  aStringList : TStringlist;
  aStrings1   : TStrings;
  aStrings2   : Tstrings;

  aRegistry   : TRegistry;
  aInt        : Integer;
  tempInt     : Integer;
Begin
  aStringlist:=TStringlist.Create;
  aStrings1:=TStringlist.Create;
  aStrings2:=TStringlist.Create;

  aRegistry:= Tregistry.Create;
  With aRegistry do Begin
    RootKey:=HKEY_CURRENT_USER;
    OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources',False);
    GetValueNames(aStrings1);
  End;
  aRegistry.Free;

  aRegistry:= Tregistry.Create;
  With aRegistry do Begin
    RootKey:=HKEY_LOCAL_MACHINE;
    OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources',False);
    GetValueNames(aStrings2);
  End;
  aRegistry.Free;

  aStringlist.AddStrings(aStrings1);
  aStrings1.Free;
  aStringlist.AddStrings(aStrings2);
  aStrings2.Free;
  aStringlist.Sort;
  ComboBox1.Clear;
  tempInt := 0;
  for aInt:=0 to aStringList.Count-1 do begin
    if Trim(aStringList[aInt]) <> '' then begin
      ComboBox1.Items.Add(Trim(aStringList[aInt]));
      INC(tempInt);
    end;
  end;
End;

Is a multi-platform method?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: ODBC Question
« Reply #11 on: June 21, 2010, 11:06:36 pm »
And how do I get the list of tables after I connected to DB via ODBC?

TODBCConnection.GetTableNames();

 function always returns an error!
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Lacak2

  • Guest
Re: ODBC Question
« Reply #12 on: June 22, 2010, 03:45:58 am »
TODBCConnection.GetTableNames();

 function always returns an error!
Which error ? Which DB ?
(for me it works ok)

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: ODBC Question
« Reply #13 on: June 22, 2010, 04:53:41 am »
TODBCConnection.GetTableNames();

 function always returns an error!
Which error ? Which DB ?
(for me it works ok)

Error: The metadata is not available for this type of database.
DB: MySql 5.1.41-community via tcp/ip
OS: Windows Xp SP3
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Lacak2

  • Guest
Re: ODBC Question
« Reply #14 on: June 23, 2010, 02:05:31 am »
Do you call GetTableNames(..., true); with second argument "SystemTables"=true ?
If yes, then this is missing feature in TODBCConnection ... see: http://bugs.freepascal.org/view.php?id=13893#bugnotes
« Last Edit: June 23, 2010, 09:01:15 pm by Lacak2 »

 

TinyPortal © 2005-2018