PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > nzn.fr.delphi > Paradox redimensionner champ
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Paradox redimensionner champ

Réponse
 
LinkBack Outils de la discussion
Vieux 13/02/2008, 13h15   #1
Pascal
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Paradox redimensionner champ

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


  Réponse avec citation
Vieux 13/02/2008, 14h45   #2
e-0
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Paradox redimensionner champ

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
>
>



  Réponse avec citation
Vieux 13/02/2008, 16h08   #3
Côme de Christen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Paradox redimensionner champ

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
>
>



  Réponse avec citation
Vieux 13/02/2008, 17h03   #4
eLion
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Paradox redimensionner champ

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;
  Réponse avec citation
Vieux 13/02/2008, 17h32   #5
Pascal
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Paradox redimensionner champ

Merci pour vos conseils


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 10h09.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15583 seconds with 13 queries