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
Modify DBF Structure Programmatically
Re: Modify DBF Structure Programmatically
Jeff,
We're working on the support for "Embedded SQL".
This is one of the statements that is part of this.
Robert
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
The Netherlands
robert@xsharp.eu
-
- Posts: 37
- Joined: Fri Jun 07, 2019 4:16 pm
Re: Modify DBF Structure Programmatically
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
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
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
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
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Re: Modify DBF Structure Programmatically
Jeff
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
Most things in X# (like in Clipper and Visual Objects) are not command based but function based.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
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
The Netherlands
robert@xsharp.eu
-
- Posts: 37
- Joined: Fri Jun 07, 2019 4:16 pm
Re: Modify DBF Structure Programmatically
Thanks, Robert. Your logic parallels mine.
Regards,
Jeff
Regards,
Jeff
Re: Modify DBF Structure Programmatically
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
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
The Netherlands
robert@xsharp.eu