![]() |
Datenbank: Paradox • Version: 5 • Zugriff über: BDE ADO
Primärindex löschen
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 :wall: Hier noch mal der Code
Delphi-Quellcode:
Ein Form mit einem Speedbutton TTable und einem Opendialog. Die Procedure ChangePIdx
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. 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 |
Re: Primärindex löschen
Hallo,
*meld* ;) Hast dich ja schön durchgekämpft ... ;) Nun will ich dich mal nicht im Regen stehen lassen. ![]() Gesetzt dem Fall die Tabelle heisst MyEmp.db Dann nimm ne Query und
SQL-Code:
DROP INDEX "MyEmp.db".PRIMARY
Zum Neuanlegen kannst du ja DbiDoRestructrure benutzen. (Wusste ich vorher auch nicht.) Heiko |
Re: Primärindex löschen
Super :cheers:
BDE :evil: :twisted: gruß Texas |
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:34 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz