Alpha DevCon Engineering Roundtables
Results 1 to 10 of 10

Thread: Never make a field name = a table name

  1. #1
    "Certified" Alphaholic
    Real Name
    Raymond Lyons
    Join Date
    Apr 2000
    Location
    Carlsbad, CA
    Posts
    2,136

    Default Never make a field name = a table name

    Never have a field name be the same as the table name in which the field resides.

    Is doing so asking for all kinds of problems? Not in my experience. For 20+ years my breaking this rule in a large complex app never caused a single problem–until a few days ago when I used a Copy Records operation on a table named “Funded” to create a slimmed down temp table I named “Funded_tmp”. The problem arose because the Funded table has a date field also named Funded and the latter is used in a calculated field rule with another date field. The problem is that although “Funded” is a field in the new table, in the new copied field rules the field is named whatever the new table name is, e.g., “Funded_tmp” (or “Zztop” if I named the new table Zztop). The same thing happens if I simply duplicate the table via the A5 Duplicate operation. Sadly it is way too late to simply change the Funded table name or the Funded field name. In a large complex app doing so would be an enormous project, though possibly one of Cal Locklin’s utilities might help in such an endeavor (Cal’s utilities have saved me an enormous amount of time over the years–thanks Cal, if you are still lurking around).

    Of course it would be easy to correct the field name in the copied over field rules. However, I wanted the copied table to be a temporary table that would be recreated weekly with the saved copy records operation. Possibly a bad approach anyway, but that was my original thought. Obviously I don’t want to have to edit field rules every time the saved copy records operation is run.

    Although I have not done it yet, I assume one easy way to deal with this problem would be to use an append to produce my weekly version of the temp table, after fixing field name in the field rules of the initial copied table created by a copy records operation.

    Is this a bug? I suppose so. But Selwyn and Cian have looked at the code involved in a fix and determined that a fix would be “very risky”. So a fix is not going to happen, at least not in the near future. Since in Alpha Five there are lots of ways to skin a cat, I’m fine with cat skinning.

  2. #2
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    24,571

    Default Re: Never make a field name = a table name

    Obviously I don’t want to have to edit field rules every time the saved copy records operation is run.
    Can be done with xbasic so you don't have to remember/do it manually.
    There can be only one.

  3. #3
    Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,315

    Default Re: Never make a field name = a table name

    With xbasic you can rename by using the field name or field number.

    You should built a short function to do exactly what you want/need.

    Interesting to note the issue that you found.

    Further evidence that unique names help the readability of code for the user/developer and the application operation...
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.

  4. #4
    "Certified" Alphaholic
    Real Name
    Raymond Lyons
    Join Date
    Apr 2000
    Location
    Carlsbad, CA
    Posts
    2,136

    Default Re: Never make a field name = a table name

    Stan & Al,

    I have no idea how to change the name of a field that appears in a table field rule calculation using xbasic. I find the new Help file to be next to useless for this (and for most things). Just to be clear, we are not talking about changing the name of a field in a table. What would be needed is the xbasic to change the bogus name that appears in one of the calcs in the table's field rules. I am sure there is an xbasic way but unless someone wants to share a method, I'll just go about using a zap and an append after the temp table is created.

    Ray Lyons

  5. #5
    Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,315

    Default Re: Never make a field name = a table name

    Look at the Dictionary Functions and Methods
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.

  6. #6
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    24,571

    Default Re: Never make a field name = a table name

    Done in the interactive for demo purposes.

    Code:
    tbl = table.open("dest")'table pointer
    rul = tbl.rules_get() 'rules pointer
    ? rul.tst.Calc 'show the calculation set for the tst field, wouldn't do this in actual script
    = "UPPER(ST)"
    
    rul.change_begin()
    rul.tst.Calc = strtran(rul.tst.Calc,"ST","ST_new") 'change the field name from ST to ST_new
    rul.change_end()
    tbl.close()
    Last edited by Stan Mathews; 05-19-2017 at 06:46 PM. Reason: edited strtran expression
    There can be only one.

  7. #7
    "Certified" Alphaholic
    Real Name
    Raymond Lyons
    Join Date
    Apr 2000
    Location
    Carlsbad, CA
    Posts
    2,136

    Default Re: Never make a field name = a table name

    Stan,

    Thanks. A code snippet like yours in the help file for a calc field rule would have been a big help. Not sure how I'm going to deal with my issue yet but what you gave certainly works (of course!)

    Al,

    I did look at Dictionary Functions and Methods in the so-called Help file. I may have missed something but I didn't find anything that indicated that the key to making a change in a Calc field rule was the "Calc" in rul.fieldname.Calc. Of course if I were as smart as you and Stan, I probably would have guessed that and tried it. On the other hand my thought of going with an append to a table with the proper field rule already in it meant I could avoid the EXTREME frustration I have every time I open the so-called help file! For me the help files from 10 to 15 years ago were far more helpful. I believe they had many more example code snippets in them, though I could be wrong.

    Ray Lyons

  8. #8
    Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,315

    Default Re: Never make a field name = a table name

    Stan's the smart one.

    I'm just bullheaded and scratch until I come up with something and then ask Stan what I should have done.
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.

  9. #9
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    24,571

    Default Re: Never make a field name = a table name

    I just like to explore.

    Again from the interactive, in AlphaSports. I see the rules as something like a multilevel pointer variable.

    Code:
    tbl = table.open("invoice_items")
    rul = table.rules_get()
    ? rul 'methods and properties of the rul pointer
    = candidate_key as C()  'Returns a cr-lf delimited list columns that make up the best candidate for 'key column'.
    V Change_Begin()  'Begin changes to the field rules.
    V Change_End([L Commit])  'End changes to the field rules.
    C Class()  'Get the class name.
    Dependencies_Get as C(tableName as c,fieldName as c)  'Returns a cr-lf delimited list of dependencies in the field rules on a column on a foriegn table - list generate in format <tablename>|<fieldname>|<reason>.
    Field_Rule_Get as P(fieldName as c[,variableFrame as p])  'Get (or add) a rule for a field - includes variables of calc fields.
    V Mode_Get()  'Get change/view mode of field rules.
    Table_Dependencies_Get as C()  'Returns a cr-lf delimited list of all the external tables that are referenced by field rules for tables - of the form <tablename>|<reason>.
    L Tag_Add(C table,C order_expre,C filter_expr,L unique)  'Add a tag if it doesn't already exist.
    +Code.
    +EXTENSION.
    +INVOICE_NUMBER.
    +PRICE.
    +PRODUCT_ID.
    +QUANTITY.
    
    ? rul.EXTENSION 'methods and properties of the rul.extension pointer
    = C Class()  'Get the class name.
    constraints_get()
    constraints_types()
    data_type_get()
    from_string()
    fullname_get()
    generate_script()
    name_get()
    table_name_get()
    to_string()
    Auto_Advance = .F.
    Calc = "QUANTITY*PRICE"
    Case_Convert = "None"
    Case_Lookup_Word = "Entire"
    Check_Case_Exceptions = .F.
    +Code.
    +Cross_File.
    Cursor_Pos = "End Of Selected"
    Data_Type = "Calc"
    +Default.
    Description = "Quantity x Price"
    +Double_Entry.
    Long_Name = "Extension"
    +Lookup.
    +Mask.
    Maximum = ""
    Minimum = ""
    +Post.
    +Required.
    Skip = ""
    Template_Not_Stored = .F.
    +Unique.
    +Validation.
    There can be only one.

  10. #10
    "Certified" Alphaholic
    Real Name
    Raymond Lyons
    Join Date
    Apr 2000
    Location
    Carlsbad, CA
    Posts
    2,136

    Default Re: Never make a field name = a table name

    Stan,

    All I will say is, I think more of what you have shown in this thread should be accessible in the Help file. Yes, there is some stuff there related to all this, but not much, and what I found was not particularly helpful. But maybe that's just me.

    Thanks for sharing.

    Ray Lyons

Similar Threads

  1. when create new record, how to make a field initial value equal to another field just input value?
    By jennygong in forum Application Server Version 11 - Web/Browser Applications
    Replies: 3
    Last Post: 01-16-2014, 04:10 PM
  2. Cannot Make Mapped Table
    By reynolditpi in forum Alpha Five Version 9 - Desktop Applications
    Replies: 16
    Last Post: 04-02-2008, 11:28 AM
  3. Make Table query
    By MValentine in forum Alpha Five Version 8
    Replies: 9
    Last Post: 03-04-2008, 08:01 PM
  4. do I make my form from a "set table or from a simple table
    By Luc Pilon in forum Alpha Five Version 7
    Replies: 2
    Last Post: 10-18-2006, 05:59 PM
  5. Do I make a new table?
    By Elsie Beall in forum Alpha Five Version 4
    Replies: 2
    Last Post: 11-13-2001, 04:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •