PDA

View Full Version : Column Identifiers: A language suggestion.



Clive Richmond
14-Feb-2010, 05:20 AM
Using the keywords, FIELD and FILE_FIELD, outside the data-dictionary methods where they work well, has its limitations. For instance, they can only appear once and as the first argument of a method invocation and for some commands they’re not supported. See this post for our keyword extension to these commands. (http://support.dataaccess.com/forums/showthread.php?t=42264) Therefore if you wish to pass more than one column identifier you must break the statement down over multiple lines and use Get_Fieldnumber. E.g.


Get_Fieldnumber INVT.Item_Id To iKeyCol
Get_Fieldnumber INVT.Unit_Price To iValueCol
Get Something INVT.File_Number iKeyCol iValueCol “StkCode” To nPrice

Or

Get_Fieldnumber INVT.Unit_Price To iValueCol
Get Something FILE_FIELD INVT.Item_Id iValueCol “StkCode” To nPriceAs table and column identifiers are resolved during compilation why can’t there be an alternative means to addressing column identifiers in the language? I can think of one way how this might be achieved.


Extend the decorate symbols to handle column identifiers. E.g. (RefField(INVT.Item_Id)).


So the previous example could be written in a single statement as follows:


Get Something INVT.File_Number (RefField(INVT.Item_Id)) (RefField(INVT.Unit_Price)) “StkCode” To nPrice

Peter Crook
15-Feb-2010, 11:59 AM
Excellent idea, Clive

Anders Ohrt
16-Feb-2010, 03:03 AM
We generate our own .FD files, which contain a define for this. We also define the name and length for each field, which come in handy:


#Replace FILE123 MyTable

#Replace MyTable.Recnum |FN123,0
#Replace MyTable.MyColumn |FS123,1

Define MyTable.TableName for "MyTable"

Define MyTable.MyColumn.ColumnName for "MyColumn"

Define MyTable.MyColumn.ColumnNumber for 1

Define MyTable.MyColumn.ColumnLength for 20

Vincent Oorsprong
17-Feb-2010, 01:19 AM
Anders,

The downside of defining the length of the column is that a recompile is always needed (and not forget to recreate the ".AFD" (Anders FD) file) when the column length get changed. For your app not such a problem but in general the length determination at runtime is a power feature for (Visual) DataFlex.

Anders Ohrt
17-Feb-2010, 04:10 AM
The downside of defining the length of the column is that a recompile is always needed (and not forget to recreate the ".AFD" (Anders FD) file) when the column length get changed. For your app not such a problem but in general the length determination at runtime is a power feature for (Visual) DataFlex.

We never forget to recreate the file, since the DBBuilder recreates the usual FD so we always notice the change then checking in code. And, if it would somehow slip through, all the other developers would notice when they recreate the changes, so that's not a problem...

The main reason for including the column length is that we have lots of forms that are not DB-aware, but whose value will eventually be saved to the DB, so we need to set the Form_Margin manually. Before, we would hook into Activating, get the table and column number of the proper column, and get the length that way. But, that was many lines of code which we did not want to keep. Now we just do Set Form_Margin to MyTable.MyColumn.ColumnLength.

The main reason for using the custom FD in the first place was to get compile-time checking of the column names. Before we could have code like this:


If (sColumnName = "SomeColumn") Begin
// Do something here.
End
Then we went and renamed the field, and the code silently broke. Now we do this:


If (sColumnName = SomeTable.SomeColumn.ColumnName) Begin
// Do something here.
End
Renaming the field now will give a compile time error.

The only problem we have now is that the names are hard coded in the AJAX library, but we cannot get away from that problem.

Clive Richmond
19-Feb-2010, 05:08 AM
Hi Anders,


We generate our own .FD files, which contain a define for this. We also define the name and length for each field, which come in handy:


#Replace FILE123 MyTable

#Replace MyTable.Recnum |FN123,0
#Replace MyTable.MyColumn |FS123,1

Define MyTable.TableName for "MyTable"

Define MyTable.MyColumn.ColumnName for "MyColumn"

Define MyTable.MyColumn.ColumnNumber for 1

Define MyTable.MyColumn.ColumnLength for 20


You have taken this much further. Where we have needed more than one column identifier for a method we have taken a similar approach but on case by case basis. However column identifiers are something I do believe should be much easier to reference in the language than the are currently.

Michael Mullan
19-Feb-2010, 09:55 AM
Another 2cents worth.


Define MyTable.MyColumn.ColumnName for "MyColumn"
Define MyTable.MyColumn.ColumnNumber for 1
Define MyTable.MyColumn.ColumnLength for 20
these three defeat CodeSense because you have to type all of "column" before CodeSense can figure out what you really wanted.

I'd prefer


Define MyTable.MyColumn.cName for "MyColumn"
Define MyTable.MyColumn.cNumber for 1
Define MyTable.MyColumn.cLength for 20
or



Define MyTable.MyColumn.NameOfColumn for "MyColumn"
Define MyTable.MyColumn.NumberOfColumn for 1
Define MyTable.MyColumn.LengthOfColumn for 20

Anders Ohrt
19-Feb-2010, 11:27 AM
these three defeat CodeSense because you have to type all of "column" before CodeSense can figure out what you really wanted.


CodeSense doesn't pick them up at all, probably due to FD files not being parsed. But if they where, I still disagree with your choice. Code Sense as it is implemented right now it semi-broken. It should auto complete as long as it should, so once you write the "c" it auto completes "column" and wait for the next character. Other applications handle this better. You should _never_ degrade your code to fit the tools! I logged this as a suggestion a while ago.