Modify DBF Structure Programmatically

This forum is meant for questions and discussions about the X# language and tools
Post Reply
Jeff Stone
Posts: 34
Joined: Fri Jun 07, 2019 4:16 pm

Modify DBF Structure Programmatically

Post by Jeff Stone »

Hi,

Please forgive me for posting this message here as it is partially included in a VFP post I made earlier. Does X# have a function to alter the structure of a .DBF file? When I enter VFP code such as:
ALTER TABLE (laliasname) ADD COLUMN (lfieldname) B(2)
I get the message: warning XS1030: #warning: ' This command is not (yet) supported:"ALTER TABLE (laliasname) ADD COLUMN (lfieldname) B(2)"'

I don't really care if the code is not VFP compliant, so does X# have a different function/command? Or, is there no such capability currently?

TIA,
Jeff
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Modify DBF Structure Programmatically

Post by robert »

Jeff,
We're working on the support for "Embedded SQL".
This is one of the statements that is part of this.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Jeff Stone
Posts: 34
Joined: Fri Jun 07, 2019 4:16 pm

Re: Modify DBF Structure Programmatically

Post by Jeff Stone »

Hi Robert,

Thanks for the information. So, I will assume X# currently has no add field or delete field capabilities and write my own functions to perform these tasks.

Regards,

Jeff
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Modify DBF Structure Programmatically

Post by wriedmann »

Hi Jeff,
I'm doing that manually for many years now: creating a new DBF with the desired structure, copy the data, and rename the file.
In my case the structure is read from a DBF based dictionary.
Unfortunately I need exclusive access to the DBF table.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Modify DBF Structure Programmatically

Post by robert »

Jeff
Jeff Stone wrote: Wed Dec 20, 2023 10:46 pm Hi Robert,

Thanks for the information. So, I will assume X# currently has no add field or delete field capabilities and write my own functions to perform these tasks.

Regards,

Jeff
Most things in X# (like in Clipper and Visual Objects) are not command based but function based.
Adding a field is done with:
- open the table: DbUseArea()
- get the structure : aStruct := DbStruct()
- close the table: DbCloseArea()
- add a field to the structure : AAdd(aStruct, {....})
- create a new temporary table : DbCreate()
- open the new temporary table: DbUseArea()
- Append rows from the existing table: DbApp()
- Close the temporary table: DbCloseArea()
- rename existing table and then rename new table: FRename()
- Maybe open the renamed table (I do not know if the table is open in FoxPro after the column is added)

Deleting a column uses the same approach, but then a field is deleted with ADel()
When you delete a column you have to verify of course if there are no indexes that depend on the column and handle that. I have no idea what FoxPro does in that situation, I'll have to check.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Jeff Stone
Posts: 34
Joined: Fri Jun 07, 2019 4:16 pm

Re: Modify DBF Structure Programmatically

Post by Jeff Stone »

Thanks, Robert. Your logic parallels mine.

Regards,

Jeff
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Modify DBF Structure Programmatically

Post by robert »

Jeff,

The ALTER TABLE command will be supported in the next build, as well as the CREATE TABLE and CREATE CURSOR commands and several other embedded SQL commands like INSERT INTO.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply