Autor Beitrag
Ratchet
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63

Windows7 x86
D5 Ent., D2006 Arch.
BeitragVerfasst: Mo 27.04.09 10:25 
Iich würde gerne die Namen aller Tabellen und wenn möglich auch deren Spalten aus einer Access Datenbank auslesen. Es geht mir nicht um die Daten selber sondern nur um die reinen Meta-Daten der Tabellen.
Suche, hier und google, ergaben noch nichts brauchbarens.

_________________
So long, and thank's for all the fish
<°))))><>
espen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90
Erhaltene Danke: 1


D6 Prof./D7 Prof. MSSQL, MySQL
BeitragVerfasst: Mo 27.04.09 12:20 
Hallo,

Solltest Du via ADOConnection auf die Access-DB zugreifen, empfehle ich:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
// ****
// **** Tabellen
// ****
Adoconnection1.GetTableNames(List: TStrings; [Systemtables :Boolean = False]);

// ****
// **** Felder einer Tabelle
// ****
Adoconnection1.GetFieldNames(const TableName, List: TStrings);


Gruss.
Ratchet Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63

Windows7 x86
D5 Ent., D2006 Arch.
BeitragVerfasst: Mo 27.04.09 13:01 
Wunderbar, vielen Dank!

_________________
So long, and thank's for all the fish
<°))))><>
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Mo 27.04.09 17:32 
Hallo,

wenn diese Frage damit für dich "beantwortet" ist, dann markier das Thema bitte auch als solches.

MfG
Regan
IHops
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26

Vista
Delphi 7, Delphi 2007
BeitragVerfasst: Sa 20.06.09 12:57 
hi, ich muss da nochmal nachfragen ...

Ich habe versucht, die Tabellennamen auszulesen und in eine Listbox einzutragen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TFrmMain.FormCreate(Sender: TObject);
var
  NameList : TStrings;
begin
  // Initialisierung
  DataModule2.ADOConnectionMain.GetTableNames(NameList);
  LBTables.Items := NameList;
end;


Beim Start des Programms erhalte ich aber eine Fehlermeldung: "Zugriffsverletzung beim Lesen ... DBDelphi.exe". Der Zugriff auf die DB ist allerdings da - in einem DBGrid wird eine Tabelle angezeigt.

Woran kann das liegen?
espen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90
Erhaltene Danke: 1


D6 Prof./D7 Prof. MSSQL, MySQL
BeitragVerfasst: Mo 22.06.09 11:39 
Hallo,

das liegt wohl daran, dass Du versuchst, die Tabellennamen während des FormCreate-Ereignisses zu ermitteln.
Versuche es mal mit FormActivate().

Grüßle.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 22.06.09 11:42 
NameList ist uninitialisiert. Bite zuerst eine TStringList erzeugen, dann diese übergeben und dann nicht an das Property zuweisen, sondern mit Items.Assign(NameList) kopieren.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 22.06.09 12:18 
Wozu die Stringliste, Du hast doch bereits eine?
ausblenden Delphi-Quelltext
1:
DataModule2.ADOConnectionMain.GetTableNames(LBTables.Items);					
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 22.06.09 12:22 
Bliebe immer noch als Alternative. Wollte hauptsächlich erstmal überhaupt auf den Fehler hinweisen, Optimieren kann man später immer noch ^^

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
ub60
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 764
Erhaltene Danke: 127



BeitragVerfasst: Mo 22.06.09 16:55 
Mal noch so für die Metadaten, hier ein Quelltext für die Feldtypen:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
var i : Integer;
    Felddefinition : TFieldDef;
    Feldname, FeldTypStr : String;
    Feldtyp : TFieldType;
    Feldgroesse : Integer;
begin
  ADOConnection1.Open;
  Adoconnection1.GetTableNames(ListBox1.Items);
  Adoconnection1.GetFieldNames('Tabellenname', ListBox2.Items);
  for i:=1 to ADOTable1.FieldDefs.Count do
    begin
      Felddefinition:=ADOTable1.FieldDefs[i-1];
      Feldname:=Felddefinition.Name;
      Feldtyp:=Felddefinition.DataType;
      Feldgroesse:=Felddefinition.Size;
      case Feldtyp of
        ftString      : FeldTypStr:='String';
        ftDate        : FeldTypStr:='Datum';
        ftBoolean     : FeldTypStr:='Boolean';
        ftFloat       : FeldTypStr:='Float/Double';
        ftUnknown     : FeldTypStr:='Unbekannt oder nicht definiert';
        ftSmallint    : FeldTypStr:='16-Bit-Integer';
        ftInteger     : FeldTypStr:='32-Bit-Integer';
        ftWord        : FeldTypStr:='Vorzeichenloser 16-Bit-Integer';
        ftCurrency    : FeldTypStr:='Währungsfeld';
        ftBCD         : FeldTypStr:='Binärcodiertes Dezimalfeld, das ohne Präzisionsverlust in ein Währungsfeld konvertiert werden kann';
        ftTime        : FeldTypStr:='Zeitfeld';
        ftDateTime    : FeldTypStr:='Datums-/Zeitfeld';
        ftBytes       : FeldTypStr:='Feste Bytezahl (binäre Speicherung)';
        ftVarBytes    : FeldTypStr:='Variable Bytezahl (binäre Speicherung)';
        ftAutoInc     : FeldTypStr:='32-Bit-Integer-Zählerfeld';
        ftBlob        : FeldTypStr:='BLOB-Feld (Binary Large OBject)';
        ftMemo        : FeldTypStr:='Textmemofeld';
        ftGraphic     : FeldTypStr:='Bitmapfeld';
        ftFmtMemo     : FeldTypStr:='Memofeld für formatierten Text';
        ftParadoxOle  : FeldTypStr:='Paradox-OLE-Feld';
        ftDBaseOle    : FeldTypStr:='dBASE-OLE-Feld';
        ftTypedBinary : FeldTypStr:='Typisiertes Binärfeld';
        ftCursor      : FeldTypStr:='Ausgabecursor einer Stored Procedure von Oracle (nur TParam)';
        ftFixedChar   : FeldTypStr:='Zeichenfeld fester Länge';
        ftWideString  : FeldTypStr:='Langes Stringfeld';
        ftLargeint    : FeldTypStr:='Großes Integerfeld';
        ftADT         : FeldTypStr:='Feld für abstrakte Datentypen';
        ftArray       : FeldTypStr:='Arrayfeld';
        ftReference   : FeldTypStr:='REF-Feld';
        ftDataSet     : FeldTypStr:='Datenmengenfeld';
        ftOraBlob     : FeldTypStr:='BLOB-Felder in Oracle 8-Tabellen';
        ftOraClob     : FeldTypStr:='CLOB-Felder in Oracle 8-Tabellen';
        ftVariant     : FeldTypStr:='Daten eines unbekannten oder nicht definierten Typs';
        ftInterface   : FeldTypStr:='Schnittstellenreferenzen (IUnknown)';
        ftIDispatch   : FeldTypStr:='IDispatch-Schnittstellenreferenzen';
        ftGuid        : FeldTypStr:='GUID-Werte (Globally Unique IDentifier)';
        ftTimeStamp   : FeldTypStr:='Datums-/Zeitfeld, auf das über DBExpress zugegriffen wird';
        ftFMTBcd      : FeldTypStr:='Feld für binärcodierte Dezimalwerte, die für ftBCD zu groß sind';
      end;           
                     
      StringGrid1.Cells[0,i]:=Feldname;
      StringGrid1.Cells[1,i]:=FeldTypStr;
      StringGrid1.Cells[2,i]:=IntToStr(Feldgroesse);
    end;
end;

ub60
IHops
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26

Vista
Delphi 7, Delphi 2007
BeitragVerfasst: Mo 22.06.09 18:16 
Vielen Dank für die schnelle Hilfe ... es lag wohl daran, dass es in der FormCreate passieren sollte. Hab es nun in die Table.Open rein geschrieben - geht super ...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TDataModule2.ADOTable1AfterOpen(DataSet: TDataSet);
begin
  // alle Tabellen angeben
  ADOConnectionMain.GetTableNames(Unit1.FrmMain.LBTables.Items);
  // alle Felder der gewählten Tabelle angeben
  ADOTable1.GetFieldNames(Unit1.FrmMain.LBFields.Items);
end;