AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Datenbanken Delphi Primärindex löschen
Thema durchsuchen
Ansicht
Themen-Optionen

Primärindex löschen

Ein Thema von Texas · begonnen am 23. Mär 2009 · letzter Beitrag vom 26. Mär 2009
Antwort Antwort
Texas

Registriert seit: 15. Jul 2005
Ort: Laatzen
56 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#1

Primärindex löschen

  Alt 23. Mär 2009, 20:58
Datenbank: Paradox • Version: 5 • Zugriff über: BDE ADO
Hallo DPler's,

hatte kürzlich nachgefragt wie man einen Primärindex von einer Paradox 5 DB entfernen kann und wurde auf den BDE Befehl DbiDoRestructure hingewiesen. Dort bin ich auch fündig geworden und bin schon so weit das der Index nur noch auf das Erste Feld gesetzt wird. Auch das mit dem Unique klappt. Ich bekomme es aber nicht gebacken den Primäindex vollkommen zu entfernen

Hier noch mal der Code

Delphi-Quellcode:
unit Haupt;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, DB, DBTables, BDE;

type
  TForm1 = class(TForm)
    SpeedButton1: TSpeedButton;
    Table1: TTable;
    OpenDialog1: TOpenDialog;
    procedure SpeedButton1Click(Sender: TObject);
    procedure ChangePIdx(Table: TTable; Fields: word);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  if opendialog1.Execute then begin
    Table1.DatabaseName := ExtractFilePath(opendialog1.FileName);
    Table1.TableName := ExtractFileName(opendialog1.FileName);
    table1.Active := true;
    ChangePIdx(Table1, 1);
  end;
end;

procedure TForm1.ChangePIdx(Table: TTable; Fields: word);
var
  Props: CURProps;
  hDb: hDBIDb;
  TableDesc: CRTblDesc;
  Index: IDXDesc;
  OP: CROpType;
  W: word;
{
Example 12: Change the amount of fields in the primary index (Paradox and dBASE 7 only).
This example uses the following input:
ChangePIdx(Table1, 2);
This input will take an existing primary index and change it to apply to the first 2 fields in the table.
NOTE: If you define an index that is more restrictive on the table's data (usually by removing fields from the index) all records that violate the new primary index will be removed from the table. In other words data will be lost!
The function is defined as follows: }


begin
  // Make sure that at least one field is specified...
  if Fields < 1 then
    raise EDatabaseError.Create('Field count must be greater than 0');
  // Make sure the table is open exclusively so we can get the db handle...
  if Table.Active = False then
    raise EDatabaseError.Create('Table must be opened to change the index');
  if Table.Exclusive = False then
    raise EDatabaseError.Create('Table must be opened exclusively to change the index');

  // Get the table properties to determine table type...
  Check(DbiGetCursorProps(Table.Handle, Props));
  // Make sure that enough fields exist to create the index...
  if Props.iFields < Fields then
    raise EDatabaseError.Create('Cannot specify more fields in an index than existing fields');
  // If the table is a Paradox table, you must call DbiDoRestructure...
  if (Props.szTableType <> szPARADOX) and (Props.szTableType <> szDBASE) then
    raise EDatabaseError.Create('Table must be of type Paradox or dBASE 7');


  // Blank out the structure...
  FillChar(TableDesc, sizeof(TableDesc), 0);
  // Get the database handle from the table's cursor handle...
  Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));
  // Put the table name in the table descriptor...
  StrPCopy(TableDesc.szTblName, Table.TableName);
  // Put the table type in the table descriptor...
  StrPCopy(TableDesc.szTblType, Props.szTableType);
  // Fill in index descriptor...
  FillChar(Index, sizeof(IDXDesc), 0);
  Index.bPrimary := TRUE;
  Index.bUnique := FALSE; //TRUE;
  Index.bMaintained := TRUE;
  Index.iFldsInKey := Fields;
  for W := 1 to Fields do
    Index.aiKeyFld[W - 1] := W;
  // Modify an existing index only...
  OP := crMODIFY;
  // Only one index to change...
  TableDesc.iIdxCount := 1;
  TableDesc.pecrIdxOp := @OP;
  TableDesc.pidxDesc := @Index;
  // Close the table so the restructure can complete...
  Table.Close;
  try
    // Call DbiDoRestructure...
    Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, FALSE));
  finally
    Table.Open;
  end;
end;

end.
Ein Form mit einem Speedbutton TTable und einem Opendialog. Die Procedure ChangePIdx
habe ich von der BDE Beispiele kopiert.
Wenn ich den Parameter Fields mit 0 übergebe und die Abfrage if Fields < 1 then raus nehme oder
Index.bPrimary := FALSE; setze
wird die Fehlermeldung bei
Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, FALSE));
kein Primärindex ausgegeben.
Vielleicht kann mir jemand sagen was ich wo ändern muss um den kompletten Index zu löschen

Besten Dank schon mal

Texas
Michael
  Mit Zitat antworten Zitat
hoika

Registriert seit: 5. Jul 2006
Ort: Magdeburg
8.270 Beiträge
 
Delphi 10.4 Sydney
 
#2

Re: Primärindex löschen

  Alt 25. Mär 2009, 14:42
Hallo,

*meld*

Hast dich ja schön durchgekämpft ...

Nun will ich dich mal nicht im Regen stehen lassen.

http://www.sqlexamples.info/SQL/bsc_sqlddl2.htm

Gesetzt dem Fall die Tabelle heisst MyEmp.db

Dann nimm ne Query und

DROP INDEX "MyEmp.db".PRIMARY
Zum Neuanlegen kannst du ja DbiDoRestructrure benutzen.



(Wusste ich vorher auch nicht.)


Heiko
Heiko
  Mit Zitat antworten Zitat
Texas

Registriert seit: 15. Jul 2005
Ort: Laatzen
56 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#3

Re: Primärindex löschen

  Alt 26. Mär 2009, 04:58
Super

BDE

gruß Texas
Michael
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:50 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz