Hi Przemek,
A code integration of a database managing utility by using only one function is not a new idea, at least for me. I saw that your code using an error handler is very compact and clean and I surely i will integrate it in mine, but is only part of the idea.
Database managers as dbase, fox and VFP changed trough their existance, but one thing is common for all and that is the way of how to create, manage and modify the dbf databases structure (using the MODIFY STRUCTURE command). Of course, trough time were added new field types and some visual options for managing the databases but the command itself does the same things all the way.
To be honest, at the time of my commit I didn't make the optimization of the final code yet, thing that you did for a part of the code.
A purpose of a "MODIFY STRUCTURE" command, or function, can be nearly defined as: "A command or function that provide the ability to the app developer to add and delete fields of an existing database, change their lengths and change their names and types.
The append command in my code called APPCONV is a part of my MODISTRU() function, but can be used separately as a standalone command with more options if we want only to append data and handling the possible errors.
It's not a problem to create a database but modify an existing one without using lot of code lines.
Examples of use of my MODISTRU() (a kind of MODIFY STRUCTURE command):
1. you need to create a temp database based on an existing database structure and need also some additional fields and maybe, after finished some operations on it, later, to flush it to replace a production database and maybe, without some unnecessary fields and, more worse, with a need to change some field name for some other app usage. All of this keeping the existing data.
2. you have some app a database update for the client, you need to alterate some database, by adding, deleting fields, etc.. Without some above mentioned command, for a databases structure update, you must use some updated temp bases and append the existing data to them without reported errors. For 1-2 databases we can do this manually, the problem emerge if we have bigger number of them multiplied by the number of clients.
With MODISTR() we, first, create an array where we define the actions for the database
aFields:={ { "MIKA" , "C", 30, 0, "#A" },; //field to add
{ "ZIKA" , "C", 13, 0, "#A" },; //field to add
{ "IME" , "N", 15, 0, "#C" },;//change field properties (in my example convert from "C" to "N"
{ "JEDINICA", , , , "#D" },; //field to delete
{ "ZA_MESEC", , , , "GMESEC" } }//field to be rename with
and then call, in my example
MODISTRU("arhiva",aFields)
so, in one pass with one function we add 2 fields, delete 1 and change 1 field name without losing of data.
As improvement using the standard MODIFY STRUCTURE VFP command, the renaming action must be a separate operation from the other actions. With the above function we achieve both in one function call.
If someone finds this idea useful, it's welcome to use it.
NOTE: This idea doesn't applies to VFP user only. It is supposed to bean utility that can be useful if integrated in a developer app to everyone who need it.
Best regards
Zoran