PDA

View Full Version : Solved problem with function A5_ADD_FIELDS_TO_TABLE


ABC123

WokingJon
11-16-2014, 09:32 AM
Thought I'd share the solution to a problem I hit with function A5_ADD_FIELDS_TO_TABLE on the desktop.

Rather than having to export records, modify structure, import records on a table when I add fields to a table, I have been using the AUTOEXEC script to add any missing fields to a table. This has been working well for several years until I hit an error trying to update the structure of a table on a network optimised workstation.

It seems obvious now, but you can't update the structure directly on a network optimised copy of the database as the fields don't actually exist!

Resolution was to recode the AUTOEXEC to use this syntax:

a5_add_fields_to_table(a5.Get_Master_Path()+"\<tablename>.dbf","<fieldname>,<type>,<length>")

instead of the standard:

a5_add_fields_to_table("<tablename>,"<fieldname>,<type>,<length>")

This works for both standard and network optimised databases (I assume the "\" before the tablename is discarded by Alpha) removing the need to test/code different solutions for local & networked implementations.

Hope this helps somebody some day.

MoGrace
11-16-2014, 11:54 AM
Hi Jon,
Why would the '\’ be discarded when it is a necessary part of the path statement? When working with local or server tables it is a good idea to test first if a5.get_master_path() returns blank or not, then construct the path accordingly.

WokingJon
11-17-2014, 03:01 AM
Robin, I get the impression that the '\' is ignored if at the beginning of the tablename e.g. a5.get_master_path() = "". This doesn't work in DOS - file not found, but appears to be valid in Alpha. If it's a bug, I hope Alpha don't fix it!

Stan Mathews
11-17-2014, 10:12 AM
Any of the path functions return the path without the final \

? a5.Get_Path()
= "H:\Buyers\Public\Grocery Merchandising\WklyChg"

So to have a valid path you have to add the backslash.

WokingJon
11-17-2014, 12:19 PM
Stan, my point was that if running on a standard database and a5.get_master_path() returns an empty string the leading "\" does not cause a problem for the subsequent (in this case) a5_add_fields_to_table call e.g. both a5_add_fields_to_table("<tablename>,"<fieldname>,<type>,<length>") AND a5_add_fields_to_table("\<tablename>,"<fieldname>,<type>,<length>") work.

MoGrace
11-17-2014, 12:42 PM
It only matters if you have to add the path since otherwise A5 is looking in the adb path.

Al Buchholz
11-17-2014, 01:08 PM
It only matters if you have to add the path since otherwise A5 is looking in the adb path.

Mostly true.

Except when I rely that it does and it doesn't.

So I tend to provide the path. Except when I forget.

:wink: