🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.database
Article #2016

Re: Write Delphi code to restructure a table???

#2016
From: Owen Phelps
Date: Mon, 22 Mar 1999 00:00
95 lines
3782 bytes
Goossens Guy wrote:
> 
> What kind of restructuration do you want to do ?
> 
> You can use SQL statement "Alter table", you can also make call to dbi
> functions but this is much complex.
> 
> You can't restructure directly with Delphi code.

[I'm not the original poster, but I need the same info]

I need to restructure a table slightly via code. What I'm after is
pretty straightforward, but I've run into a brick wall with the dbi
approach. Unfortunately, I need this approach to work, so any help I can
get would be *most* appreciated.

I need to convert a single, named field in a given table from Integer to
Float.

If you have any sample code that does this or a similar thing, *please*
let me have it.

For reference, the following routine is as far as I've got. It all seems
to be correct as far as I can see, but when it gets to the actual
dbiDoRestructure call, it bombs out with an EDBEngineError ("Invalid
parameter").


Thanks in advance


Owen Phelps
--
Please note obvious spam avoidance in email address

procedure ModifyField(APath: string; ATableName: string; AFieldName:
string; AFieldType: TFieldType);
var
  hDb: hDbiDb;
  hCur: hDBICur;
  LTblDesc: CRTblDesc;
  LCurProps: CurProps;
  LpFldDescs, LpCurrentField: pFldDesc;
  LFieldIndex: Integer;
  LNeedsChanging: Boolean;
begin
  LNeedsChanging := False;
  Check(DbiOpenDatabase(nil, nil, dbiReadWrite, dbiOpenExcl, nil, 0,
nil, nil, hDb));
  try
    Check(DbiSetDirectory(hDb, PChar(APath)));
    Check(DbiOpenTable(hDb, PChar(ATableName), nil, nil, nil, 0,
dbiREADWRITE,
                   dbiOPENEXCL, xltFIELD, True, nil, hCur));
    try
      Check(DbiGetCursorProps(hCur, LCurProps));
      LpfldDescs := AllocMem(LCurProps.iFields*SizeOf(FldDesc));
      try
        Check(DbiGetFieldDescs(hCur, LpfldDescs));
        LpCurrentField := LpfldDescs;
        for LFieldIndex := 0 to LCurProps.iFields - 1 do
        begin
          if CompareText(AFieldName, LpCurrentField^.szName) = 0 then
          begin
            LNeedsChanging := (LpCurrentField^.iFldType <>
FldTypeMap[AFieldType]);
            if LNeedsChanging then
            begin
              LpCurrentField^.iFldType := FldTypeMap[AFieldType];
              LpCurrentField^.iSubType := FldSubTypeMap[AFieldType];
              Break;
            end;
          end;
          Inc(LpCurrentField);
        end;

        if LNeedsChanging then
        begin
          StrPCopy(LTblDesc.szTblName, ATableName);
          StrPCopy(LTblDesc.szTblType, szPARADOX);
          LTblDesc.pfldDesc := LpfldDescs;
          Check(DbiDoRestructure(hDB, 1, @LTblDesc, nil, nil, nil,
false));
        end;
      finally
        if Assigned(LpfldDescs) then
          FreeMem(LpfldDescs);
      end;
    finally
      Check(DbiCloseCursor(hCur));
    end;
  finally
    Check(DbiCloseDatabase(hDb));
  end;
end;
Technical Details
Message-ID: <36F6BBC3.78AD7FE1@nospamplease.bigfoot.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <ckJt2.1382$57.870@typhoon.mbnet.mb.ca> <36C99418.EDC39500@cds-nv.be> <7bjcv8$jmq$1@news3.Belgium.EU.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: ff75c,8ceb0924653668c0,start
X-Google-Attributes: gidff75c,public
X-Google-Thread: 115d96,4748c9d03c6807e7
X-Google-Attributes: gid115d96,public
From: Owen Phelps <owen.phelps@nospamplease.bigfoot.com>
Subject: Re: Write Delphi code to restructure a table???
Date: 1999/03/22
Message-ID: <36F6BBC3.78AD7FE1@nospamplease.bigfoot.com>
X-Deja-AN: 457714080
Content-Transfer-Encoding: 7bit
References: <ckJt2.1382$57.870@typhoon.mbnet.mb.ca> <36C99418.EDC39500@cds-nv.be> <7bjcv8$jmq$1@news3.Belgium.EU.net>
To: Goossens Guy <guy.goossens@bjl.be>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Trace: 22 Mar 1999 22:01:10 GMT, warp8-102.enta-net.co.uk
MIME-Version: 1.0
Newsgroups: borland.public.delphi.database,borland.public.delphi.database.desktop