xsharp.eu • Modify DBF Structure Programmatically
Page 1 of 1

Modify DBF Structure Programmatically

Posted: Wed Dec 20, 2023 9:37 pm
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

Re: Modify DBF Structure Programmatically

Posted: Wed Dec 20, 2023 9:44 pm
by robert
Jeff,
We're working on the support for "Embedded SQL".
This is one of the statements that is part of this.

Robert

Re: Modify DBF Structure Programmatically

Posted: Wed Dec 20, 2023 10:46 pm
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

Re: Modify DBF Structure Programmatically

Posted: Thu Dec 21, 2023 4:22 am
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

Re: Modify DBF Structure Programmatically

Posted: Thu Dec 21, 2023 6:49 am
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

Re: Modify DBF Structure Programmatically

Posted: Thu Dec 21, 2023 2:42 pm
by Jeff Stone
Thanks, Robert. Your logic parallels mine.

Regards,

Jeff

Re: Modify DBF Structure Programmatically

Posted: Thu Dec 21, 2023 4:07 pm
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