Recent

Author Topic: ODBC Question  (Read 19286 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: ODBC Question
« Reply #15 on: June 23, 2010, 10:52:53 pm »
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


Not working even with the second argument set to true, I pointed to the fact that I've reported bugreport!
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 #16 on: June 24, 2010, 12:30:41 am »
Now that aspect of knowing how to see the names of the tables, I assume that the table name that interests me, how do I know the name and type of fields that comprise it?
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 #17 on: June 24, 2010, 01:05:23 am »
I understand how you retrieve the field names and their data types! Assuming you use a TSQLQuey called Q_Query and TListBox List_Struttura name where the code will print the results:

 List_Struttura.Clear;
     for i:=0 to (Q_Query.FieldCount-1) do
     begin
          Tipo:=Q_Query.FieldDefs.Items.DataType;
          List_Struttura.Items.Add(Q_Query.FieldDefs.Items.Name + ' --> ' + GetEnumName(TypeInfo(TFieldType), Integer(Tipo)));
     end;

add uses typinf to GetEnumName function


I now only remains to figure out how to retrieve the name of the tables and if the way I was told to retrieve the name of the DSN is cross-platform!
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 #18 on: June 24, 2010, 01:52:10 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;

Ok, I understand that is not a platform, because Linux does not work! How do I find a list of dsn Linux / lazarus? It would be a better platform, but if there's enough for me to know how to retrieve it with Linux. Help me please!
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Lacak2

  • Guest
Re: ODBC Question
« Reply #19 on: June 24, 2010, 03:09:38 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


Not working even with the second argument set to true, I pointed to the fact that I've reported bugreport!
You must download Lazarus with FPC >= 2.3.1 (If you use 2.2.4 there is not implemented GetTableNames for TODBCCOnnection at all)

Lacak2

  • Guest
Re: ODBC Question
« Reply #20 on: June 24, 2010, 03:16:09 am »
How do I find a list of dsn Linux / lazarus? It would be a better platform, but if there's enough for me to know how to retrieve it with Linux. Help me please!

Have you tried ?:
SQLDataSources : http://msdn.microsoft.com/en-us/library/ms711004(VS.85).aspx

It should work under Linux as far as it support standard ODBC API
(but I can not confirm, because I do not work with Linux)

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: ODBC Question
« Reply #21 on: June 24, 2010, 05:35:41 am »
So I feel I wrote a C library that allows me to retrieve this data, both on Linux and Windows, the list of dsn that the list of tables! I just do not know how to create the file. Dll and filw. I do not know how to see Lazarus the dll you could help me?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1945
Re: ODBC Question
« Reply #22 on: June 24, 2010, 05:58:49 am »
I wrote something in this area. This one is with Linux *.so included.
It will probably work on win too if you have the dll.

http://www.theo.ch/lazarus/mdbtools.zip

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: ODBC Question
« Reply #23 on: June 24, 2010, 06:37:11 am »
I wrote something in this area. This one is with Linux *.so included.
It will probably work on win too if you have the dll.

http://www.theo.ch/lazarus/mdbtools.zip
You could not fill. So on. Dll?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1945
Re: ODBC Question
« Reply #24 on: June 24, 2010, 06:49:27 am »
You could not fill. So on. Dll?

I don't really understand you, but I guess you need the *.dll.
I don't know, I just neeeded the library on Linux.
It's this project, there you can get the source:
http://mdbtools.sourceforge.net/

EDIT: Sorry, I got that wrong. You don't need tools for mdb, you want MySql over ODBC.
« Last Edit: June 24, 2010, 07:06:04 am by theo »

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: ODBC Question
« Reply #25 on: June 24, 2010, 07:07:19 am »
You could not fill. So on. Dll?

I don't really understand you, but I guess you need the *.dll.
I don't know, I just neeeded the library on Linux.
It's this project, there you can get the source:
http://mdbtools.sourceforge.net/

EDIT: Sorry, I got that wrong. You don't need tools for mdb, you want MySql over ODBC.

Exact
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1945
Re: ODBC Question
« Reply #26 on: June 24, 2010, 07:10:59 am »
Btw: SVK-ITA: 2:0 !!
Ahh...

EDIT:
Buon viaggio azzurri !
« Last Edit: June 24, 2010, 07:40:35 am by theo »

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: ODBC Question
« Reply #27 on: June 24, 2010, 09:37:25 pm »
Btw: SVK-ITA: 2:0 !!
Ahh...

EDIT:
Buon viaggio azzurri !

Really SVK-ITA: 3-2 !!
Grazie
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

 

TinyPortal © 2005-2018