Autor Beitrag
alexschultze
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 317



BeitragVerfasst: Di 03.12.02 15:25 
hiho

ich habe eine kleine Datenbank, welche die aktuell angemeldeten User registriert. Da beim Start keine User angemeldet sind, soll die Tabelle jedes mal komplett geleert werden, aber nicht gelöscht.

Ich hab diverses probiert, aber irgendwie gabs immer Probleme. Was ist die 'saubere' Leerung einer Datenbank?

ausblenden Quelltext
1:
2:
3:
4:
5:
table2.Edit;
//table2.ClearFields;
datasource2.Enabled:=false;
table2.Exclusive:=true;
table2.EmptyTable;


alex
LCS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1305
Erhaltene Danke: 1

WIN 7, WIN 8
Delphi XE5, Delphi XE, Delphi 2007
BeitragVerfasst: Di 03.12.02 15:28 
Hi
die einfachste Lösung wäre mittels TQuery und dieser SQL-Anweisung.

ausblenden Quelltext
1:
DELETE FROM DeineTabelle					


Gruss Lothar

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Di 03.12.02 15:43 
Es geht sogar ohne Query. Einfach Database.Execute('delete from tabelle').
alexschultze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 317



BeitragVerfasst: Di 03.12.02 15:58 
gibts nicht noch ne einfachere Variante a la
table2.clear ?
LCS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1305
Erhaltene Danke: 1

WIN 7, WIN 8
Delphi XE5, Delphi XE, Delphi 2007
BeitragVerfasst: Di 03.12.02 15:59 
@Udontknow
Das ist ja mal ein typischer Fall von: Man lernt nie aus :mrgreen: TDatabase verwende ich nun wirklich schon seit Jahren, aber die Methode ist mir noch nie aufgefallen.
:think: Guter Tipp

Gruss Lothar

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...
Scrat
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 73



BeitragVerfasst: Mi 04.12.02 09:28 
Hallo zusammen,

ich habe das auch mal ausprobiert (Tabelle leeren).
Aber ich bekomme eine Fehlermeldung.

Mein Quelltext:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
if key = '1' then
 begin
  if MessageDlg('Sollen wirklich alle Bestellungen gelöscht werden?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
  begin
  Material_bestellung2.Richedit1.Lines.clear;
  Table1.DatabaseName:= 'c:\delphi\dynamische_infopost\';
  Table1.TableName := 'Bestell.dbf';
  Table1.open;
  Datsour1.Enabled:=false;
  Table1.Exclusive:=true;
  Table1.Database.Execute('delete from tabelle').
  MessageDlg('Alle Bestellungen wurden gelöscht.', mtInformation, [mbOk], 0);
  end;


Die Fehlermeldung:
[Fehler] Verwaltung.pas(144): Record, Objekt oder Klassentyp erforderlich

Danke im Vorraus

Gruß
Scrat

_________________
Wenn ein Programm nutzlos ist, muß es dokumentiert werden.
LCS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1305
Erhaltene Danke: 1

WIN 7, WIN 8
Delphi XE5, Delphi XE, Delphi 2007
BeitragVerfasst: Mi 04.12.02 09:39 
Hi
jetzt wärs natürlich noch ganz nett gewesen wenn du uns geschrieben hättest, welche Zeile Delphi da bemängelt :wink:. Zwei Fehlerchen hab ich aber gefunden.
1. Du versuchst eine Tabelle Exklusiv zu verwenden nachdem du sie geöffnet hast. Das funktioniert nicht. Die Tabelle muss dazu geschlossen sein.
2. Ich nehme mal an du möchtest den Inhalt von BESTELL.DBF löschen. Dann musst du das natürlich auch mit SQL formulieren:
ausblenden Quelltext
1:
DELETE FROM BESTELL					


Gruss Lothar

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...
Jagg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Mi 04.12.02 09:54 
und wie geht das ohne SQL !
Table1.Delete ???

Jagg !
LCS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1305
Erhaltene Danke: 1

WIN 7, WIN 8
Delphi XE5, Delphi XE, Delphi 2007
BeitragVerfasst: Mi 04.12.02 10:18 
TTable.EmptyTable (Einschränkungen beachten)

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...
Jagg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Mi 04.12.02 11:27 
aber bevor man das aufruft muss man doch die tabelle schließen oder nicht ?

Jagg !
neojones
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1206
Erhaltene Danke: 1



BeitragVerfasst: Mi 04.12.02 11:44 
Ob mans schließen muss oder nicht kommt auf die zu Grunde liegende Datenbank an. Meistens reicht es, wenn man sie Exclusive öffnet. Bei mySQL geht es auch mitten im Laufenden Betrieb, solange kein LOCK auf die Tabelle gesetzt ist und die GRANTS ausreichen.

_________________
Ha! Es compiliert! Wir können ausliefern!
Jagg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Mi 04.12.02 12:35 
wenn ich exclusive := true mache sagt er mir immer Tabelle in gebrauch !
dann muss ich sie doch schließen oder nicht,aber wenn ich es mache geht es dann auch nicht !
oder ist die tabelle noch woanders geöffnet !
alexschultze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 317



BeitragVerfasst: Mi 04.12.02 14:41 
vermutlich von der BDE?
alexschultze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 317



BeitragVerfasst: Mi 04.12.02 14:46 
also, soweit geht es bei mir (in dieser Reihenfolge):

Datasource2.Enabled:=false;

table2.close;
Table2.Exclusive:=true;

EmptyTable geht immer noch nicht
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Mi 04.12.02 21:39 
Hi!

Nun, wenn das alles nicht klappt, kann man es natürlich auch noch umständlich machen.

ausblenden Quelltext
1:
2:
3:
Table.First;
While not Table.eof do
  Table.Delete;


Cu, :)
Udontknow
LCS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1305
Erhaltene Danke: 1

WIN 7, WIN 8
Delphi XE5, Delphi XE, Delphi 2007
BeitragVerfasst: Do 05.12.02 09:12 
@alexschulte
Wenn's so wie du geschrieben hast nicht klappt, ist die Tabelle noch irgendwo anders geöffnet. Beispielsweise im Explorer der IDE. Zum Löschen mit EmptyTable muss die Tabelle Exklusiv zur Verfügung stehen. Ob sie beim Löschen geöffnet oder geschlossen ist spielt keine Rolle.

@Udontknow
Das funktioniert zwar, aber wenn du auf diese Art und Weise 10000 Datensätze löschen willst, die irgendwo auf einem Server liegen, hast du nen Bart bis er damit fertig ist.

Gruss Lothar

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Do 05.12.02 10:17 
LCS:

Klar ist das langsam. Ist ja auch nur eine Notlösung. Wenn halt nichts anderes klappt... :wink:

Cu,
Udontknow
alexschultze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 317



BeitragVerfasst: Do 05.12.02 15:39 
die eof Variante ist für mich voll und ganz in Ordnung ;) danke ;)

das ganze mit Exklusive etc.... mich nervt es auch *g*

Darum, danke UdOntKnow