|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Bonjour,
J'ai un champ TOTO de type alpha et de taille 7 dans une base paradox et je voudrais le redimensionner pour qu'il ait une taille de 10 Quelles commandes puis je utiliser pour cela ( ALTER ou autre)? Merci |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Creer une table temporaire avec tous les bons champs, la remplir avec les
données de la table à modifier. Detruire l'ancienne table et la remplacer par la table temporaire. Chiant mais efficace )e-0 J'aiJamaisAiméLesBasesDeDonnées )"Pascal" <pascal.derex@libertysurf.fr> a écrit dans le message de news: fouqhe$2mn$1@sd-6836.dedibox.fr... > Bonjour, > > J'ai un champ TOTO de type alpha et de taille 7 dans une base paradox et > je > voudrais le redimensionner pour qu'il ait une taille de 10 > Quelles commandes puis je utiliser pour cela ( ALTER ou autre)? > > Merci > > |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Salut
Ou peut-être plus simple par du SQL standard avec ALTER et la création d'un champ temporaire Une recherche dans ngscan ou ... www.delphinaute.com te donnera de nombreux exemples. "Pascal" <pascal.derex@libertysurf.fr> a écrit dans le message de news: fouqhe$2mn$1@sd-6836.dedibox.fr... > Bonjour, > > J'ai un champ TOTO de type alpha et de taille 7 dans une base paradox et je > voudrais le redimensionner pour qu'il ait une taille de 10 > Quelles commandes puis je utiliser pour cela ( ALTER ou autre)? > > Merci > > |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Pascal wrote:
> Bonjour, > > J'ai un champ TOTO de type alpha et de taille 7 dans une base paradox et je > voudrais le redimensionner pour qu'il ait une taille de 10 > Quelles commandes puis je utiliser pour cela ( ALTER ou autre)? > > Merci > > en passant par l'api du BDE ? plus bas dans ChangeFieldLength eLion uses dbiTypes, dbiProcs; type TChangeRec = packed record szName: DBINAME; iType: word; iSubType: word; iLength: word; iPrecision: byte; end; function GetFieldInfo(const aPath, aTablename, aFieldName: string; var FieldType: TFieldType; var FieldSize: Word): boolean; var aTable: TTable; i: Integer; begin Result:=False; // field not found FieldType := ftUnknown; FieldSize := 0; aTable:=TTable.Create(nil); try aTable.DatabaseName := aPath; aTable.TableName:=aTableName; aTable.FieldDefs.Update; i:=aTable.FieldDefs.IndexOf(aFieldName); if i<>-1 then begin Result:=True; // field found FieldType:=aTable.FieldDefs.Items[i].DataType; FieldSize:=aTable.FieldDefs.Items[i].Size; end; finally aTable.Free; end; end; function GetFieldSize(const aPath, aTablename, aFieldName: string): Word; var FieldType: TFieldType; begin GetFieldInfo(aPath, ATableName, aFieldName, FieldType, Result); end; function GetFieldType(const aPath, aTablename, aFieldName: string): TFieldType; var FieldSize: word; begin GetFieldInfo(aPath, ATableName, aFieldName, Result, FieldSize); end; procedure ChangeField(aPath, aTablename, aFieldName: string; Rec: TChangeRec); var Props: CURProps; hDb: hDBIDb; TableDesc: CRTblDesc; pFields: pFLDDesc; pOp: pCROpType; B: byte; aTable : TTable; aField :TField; s: string; begin aTableName:=IncludeTrailingPathDelimiter(aPath) + aTableName; aTable:=TTable.Create(nil); aTable.TableName:=aTableName; aTable.Exclusive:=True; {Set Exclusive open} aTable.Open; aField:=aTable.FieldbyName(aFieldName); {// Initialize the pointers...} //pFields := nil; pOp := nil; Check(DbiSetProp(hDBIObj(aTable.Handle), curxltMODE, integer(xltNONE))); {// Get the table properties to determine table type...} Check(DbiGetCursorProps(aTable.Handle, Props)); {// Make sure the table is either Paradox or dBASE...} {// Allocate memory for the field descriptor...} pFields := AllocMem(aTable.FieldCount * sizeof(FLDDesc)); {// Allocate memory for the operation descriptor...} pOp := AllocMem(aTable.FieldCount * sizeof(CROpType)); try {// Set the pointer to the index in the operation descriptor to put // crMODIFY (This means a modification to the record is going to happen)...} Inc(pOp, aField.Index); {Inc(pOp, Field.Index);} pOp^ := crMODIFY; Dec(pOp, aField.Index); {Dec(pOp, Field.Index);} {// Fill the field descriptor with the existing field information...} Check(DbiGetFieldDescs(aTable.Handle, pFields)); {// Set the pointer to the index in the field descriptor to make the // midifications to the field} Inc(pFields, aField.Index); {Inc(pFields, Field.Index);} {// If the szName portion of the ChangeRec has something in it, change it...} {if Length(Rec.szName) > 0 then}{Erroneus, original BORLAND line} if StrLen(Rec.szName) > 0 then {Mne 7.5.98} pFields^.szName := Rec.szName; {// If the iType portion of the ChangeRec has something in it, change it...} if Rec.iType > 0 then pFields^.iFldType := Rec.iType; {// If the iSubType portion of the ChangeRec has something in it, change it...} if Rec.iSubType > 0 then pFields^.iSubType := Rec.iSubType; {// If the iLength portion of the ChangeRec has something in it, change it...} if Rec.iLength > 0 then pFields^.iUnits1 := Rec.iLength; {// If the iPrecision portion of the ChangeRec has something in it, change it...} if Rec.iPrecision > 0 then pFields^.iUnits2 := Rec.iPrecision; Dec(pFields, aField.Index); {Dec(pFields, Field.Index);} for B := 1 to aTable.FieldCount do begin pFields^.iFldNum := B; Inc(pFields, 1); end; Dec(pFields, aTable.FieldCount); {// Blank out the structure...} FillChar(TableDesc, sizeof(TableDesc), 0); {// Get the database handle from the table's cursor handle...} Check(DbiGetObjFromObj(hDBIObj(aTable.Handle), objDATABASE, hDBIObj(hDb))); {// Put the table name in the table descriptor...} StrPCopy(TableDesc.szTblName, aTable.TableName); {// Put the table type in the table descriptor...} StrPCopy(TableDesc.szTblType, Props.szTableType); {// The following three lines are necessary when doing any field restructure operations on a table...} {// Set the field count for the table} TableDesc.iFldCount := aTable.FieldCount; {// Link the operation descriptor to the table descriptor...} TableDesc.pecrFldOp := pOp; {// Link the field descriptor to the table descriptor...} TableDesc.pFldDesc := pFields; {// Close the table so the restructure can complete...} aTable.Close; // transform the name from Ansi to in Ascii char s:=aTableName; CharToOem(PChar(s), PChar(s)); // DbiDoRestrucure need a Ascii name, not an ansi name ! StrPCopy(TableDesc.szTblName, s); {// Call DbiDoRestructure...} Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, FALSE)); finally if pFields <> nil then FreeMem(pFields, aTable.FieldCount * sizeof(FLDDesc)); if pOp <> nil then FreeMem(pOp, aTable.FieldCount * sizeof(CROpType)); aTable.Free; end; end; function ChangeFieldLength(const DPath, aTable, aField: string; OldLength, NewLength: Integer): boolean; { Procedure to change one Field Length } var aChangeRec: TChangeRec; begin Result:=False; if GetFieldSize(Dpath, aTable, aField) = OldLength then begin Fillchar(aChangeRec, sizeof(aChangeRec), 0); {Fill rec with zeros} aChangeRec.iLength:=NewLength; ChangeField(Dpath, aTable, aField, aChangeRec); Result:=True; end; end; function ChangeFieldType(const DPath, aTable, aField: string; OldFieldType, NewFieldType: TFieldType; NewLength: integer = 0): boolean; { Procedure to change one Field type. } var aChangeRec: TChangeRec; begin Result:=False; if GetFieldType(Dpath, aTable, aField) = OldFieldType then begin Fillchar(aChangeRec, sizeof(aChangeRec), 0); {Fill rec with zeros} aChangeRec.iType := FldTypeMap[NewFieldType]; aChangeRec.iSubType := FldSubTypeMap[NewFieldType]; aChangeRec.iLength:=NewLength; ChangeField(Dpath, aTable, aField, aChangeRec); Result:=True; end; end; function ChangeFieldName(const DPath, aTable, aField, NewFieldName: string): boolean; { Procedure to change one field name. } var aChangeRec: TChangeRec; begin Result:=False; if NewFieldName='' then Exit; Fillchar(aChangeRec, sizeof(aChangeRec), 0); {Fill rec with zeros} Move(NewFieldName[1], aChangeRec.szName, Length(NewFieldName)+1); // + 1 to have the terminal zero ChangeField(Dpath, aTable, aField, aChangeRec); Result:=True; end; |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Merci pour vos conseils
![]() |
|
![]() |
| Outils de la discussion | |
|
|