Autor Beitrag
TheHuette
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 81



BeitragVerfasst: Mo 05.12.05 11:52 
Hi!

Habe folgendes Problem:

Ich habe eine TADOQuery über eine TADOConnection zu einer Paradox Datenbank verbunden. Nun möchte ich den Tabellennamen quoten, weil er z.B. ein Leerzeichen enthält. Mit folgender Syntax sollte es funktionieren, dachte ich:

ausblenden Delphi-Quelltext
1:
2:
ADOQuery.SQL.Text := 'SELECT * FROM ''My Table'' ';
ADOQuery.ExecSQL;


Doch beim ExecSQL erhalte ich dann die Fehlermeldung: "Syntaxfehler in Abfrage. Die Abfrage ist unvollständig."

Wüsste nicht, wie ich das sonst angeben soll. Doppelte Anführungsstriche (") helfen auch nicht. Kann mir da jemand weiterhelfen? Was mache ich falsch?
mexx
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Mo 05.12.05 11:58 
Versuch es mal damit.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var TblName: string;
begin
 TblName := //Tabellenname
 ADOQuery.SQL.Text := 'SELECT * FROM ' + TblName + '';  
 ADOQuery.ExecSQL; 
end;


Viel Erfolg!
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Mo 05.12.05 12:48 
Hallo,

laut LocalSQL-Hilfe müsste folgendes funktionieren:
ausblenden Delphi-Quelltext
1:
ADOQuery.SQL.Text := 'SELECT * FROM "My Table.db"';					

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
TheHuette Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 81



BeitragVerfasst: Mo 05.12.05 12:49 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var TblName: string;
begin
 TblName := //Tabellenname
 ADOQuery.SQL.Text := 'SELECT * FROM ' + TblName + '';  
 ADOQuery.ExecSQL; 
end;



Danke für den Tip, aber trotzdem bleibt die Frage: Was schreib ich in TblName?

ausblenden Delphi-Quelltext
1:
TblName := 'My Table';					

und
ausblenden Delphi-Quelltext
1:
TblName := '''My Table''';					


führen beide nicht zum Erfolg. Habe mit einer anderen Software getestet: SELECT * FROM 'My Table' funktioniert. Help!
mexx
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Mo 05.12.05 12:52 
My Table ist der Name der Tabelle?
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Mo 05.12.05 12:53 
Hallo,

hats Du schon mein Beispiel ausprobiert?

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
TheHuette Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 81



BeitragVerfasst: Mo 05.12.05 12:56 
user profile iconsmiegel hat folgendes geschrieben:
Hallo,

hats Du schon mein Beispiel ausprobiert?



Ja, gerade eben:

"Das Datenbankmodul kann '"My Table.db"' nicht finden. Stellen Sie sicher, dass es sich um einen gültigen Parameter oder Alias-Namen handelt, der keine ungültigen Zeichen oder falsche Zeichensetzung enthält und dessen Name nicht zu lang ist."

Die Tabelle "My Table" ist definitiv in der Datenbank vorhanden. Mit einer anderen Software kann ich sie öffnen.
mexx
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Mo 05.12.05 12:58 
Welche SQL verwendest Du. D3? Unter D3 würde

select * from 'Tabelle'

nicht gehen
TheHuette Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 81



BeitragVerfasst: Mo 05.12.05 13:03 
user profile iconmexx hat folgendes geschrieben:
Welche SQL verwendest Du. D3?


Hmmm...benutze Delphi7. Oder was meinst du mit D3?
mexx
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Mo 05.12.05 13:05 
Ich spreche vom SQLDIALECT.
TheHuette Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 81



BeitragVerfasst: Mo 05.12.05 13:10 
Wie finde ich das denn raus?

Sorry, aber bin ziehmlicher SQL-Newbie.
mexx
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Mo 05.12.05 13:12 
Abgesehen von der SQL-Anweisung, bist Du Dir sicher, dass die Verbindung zur DB auch hergestellt wurde. Ich kenne die Komponenten jetzt nicht aber Alias korrekt, Session korrekt(wenn nötig).
Amiga-Fan
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 534



BeitragVerfasst: Mo 05.12.05 13:13 
Leerzeichen im Tabellennamen. aua...

_________________
- Leg dich nie mit einem Berufsprogrammierer an
- Wahre Profis akzeptieren keine einfachen Lösungen
mexx
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Mo 05.12.05 13:14 
BDE-Verwaltung!

Wenn dort nix über SQLDIALECT steht, ist es die 1 oder 2. Dann müsste eine Abfrage mit hochkomma gehen.
Denke mal über den erfolgreichen Verbindungsaufbau nach.
mexx
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Mo 05.12.05 13:15 
Das kommt noch erschwerend dazu @Amiga-Fan

PS: Amiga 600 rulz!
Amiga-Fan
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 534



BeitragVerfasst: Mo 05.12.05 13:19 
ich habe noch den A1200er :wink: aber wir kommen vom thema ab

_________________
- Leg dich nie mit einem Berufsprogrammierer an
- Wahre Profis akzeptieren keine einfachen Lösungen
TheHuette Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 81



BeitragVerfasst: Mo 05.12.05 13:25 
user profile iconAmiga-Fan hat folgendes geschrieben:
Leerzeichen im Tabellennamen. aua...


Das habe ich mir auch gedacht, als ich hörte "Wie kann ich mit deinem Tool denn Tabellen abfragen, die ein Leerzeichen enthalten?".

Würde eine Tabelle mit so einem Namen niemals anlegen. Aber möchte sie halt trotzdem öffnen können.

Ansonsten steht die Verbindung. Andere Tabellen kann ich öffnen. Aber wenn ich eine Tabelle, die ich vorher geöffnet habe mit " oder ' quote, geht's nicht.

Zu SQLDialect habe ich nix in der BDE-Verwaltung gefunden. Suche weiter.
mexx
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Mo 05.12.05 13:31 
Hast Du eine SQL-Console zur Verfügung? Damit könntest Du die SQL-Abfragen zunächst testen. Dann kannst Du Dir absolut sicher sein, dass die Tabelle in Ordnung ist.

Dann könntest Du den SQL-Monitor von Borland verwenden, um die SQL-Anfragen, welche gesendet werden zu überprüfen.

Als dritten Check empfehle ich Dir zu überprüfen, ob Du irgendwo eine Abhängigkeit referenziert hast. Mit einer anderen Komponete, die ein Abfrage macht, oder datensensitieven Steuerelementen, die die Inhalte der DB darstellen.

Werden mit ADO-Komponenten auch TFields verwendet. Wenn ja, dann check mal, ob die auch das richtige Format haben.


Viel Erfolg!
TheHuette Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 81



BeitragVerfasst: Mo 05.12.05 13:39 
Habe es mal vereinfacht nachgebaut:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Button1Click(Sender: TObject);
begin
  ADOConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DB_Test;Extended Properties=Paradox 5.x';
  ADOQuery1.Connection := ADOConnection1;
  ADOConnection1.Open;
[b]  ADOQuery1.SQL.Text := 'Select * from PE';[/b]
  ADOQuery1.ExecSQL;
  ADOQuery1.Open;
  ShowMessage(ADOQuery1.Fields.FieldByName('KontoID').AsString);
end;


Bringt mir einen Wert.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Button1Click(Sender: TObject);
begin
  ADOConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DB_Test;Extended Properties=Paradox 5.x';
  ADOQuery1.Connection := ADOConnection1;
  ADOConnection1.Open;
[b]  ADOQuery1.SQL.Text := 'Select * from ''PE'' ';[/b]
  ADOQuery1.ExecSQL;
  ADOQuery1.Open;
  ShowMessage(ADOQuery1.Fields.FieldByName('KontoID').AsString);
end;


Bringt "Syntaxfehler in Abfrage. Die Abfrage ist unvollständig.".

ADOQuery1.SQL.Text := 'Select * from "PE" ';

Bringt die gleiche Fehlermeldung.

Um es eindeutiger zu zeigen.
mexx
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Mo 05.12.05 14:15 
Wenn PE keine Variable ist, die zur Laufzeit einen Wert zugewiesen bekommt, verstehe ich nicht warum die Abfrage nicht so aussehen soll?!

Select * from PE