Alpha DevCon 2018
Results 1 to 4 of 4

Thread: how to promote added field as primary key

  1. #1
    Member
    Real Name
    Francis Dizon
    Join Date
    Jan 2006
    Location
    Philippines
    Posts
    404

    Default how to promote added field as primary key

    hi to all

    already added a field (TranID UUID)
    how to populate TranID Field with api_uuidcreate()

    i have come up with this script but alpha stops responding
    maybe something is wrong with the script

    dim lFound as l
    lFound = .f.

    tbl = table.current()

    search_name = ""
    tbl.fetch_first()
    while .not. tbl.fetch_eof()
    if (trim(tbl.TranID) = search_name) then
    lFound = .t.

    tbl.change_begin()
    tbl.TranID = API_UUIDCREATE()
    tbl.change_end()

    end if
    tbl.fetch_next()
    end while


    thanks
    Last edited by fddizon; 06-21-2017 at 10:40 PM.
    Francis

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

    Default Re: how to promote added field as primary key

    Entire table updates are generally performed in a script or operation with the table initially not open such as is the case running a script from a button on a form built on the table.

    Try this in the interactive window or a button on a form built on a different table or as a saved script on the code tab.

    Code:
    tbl = table.open("yourtablename") 'use actual table name
    
    search_name = ""
    tbl.fetch_first()
    tbl.batch_begin()
    while .not. tbl.fetch_eof()
    	if (trim(tbl.TranID) = search_name) then
    		tbl.change_begin()
    		tbl.TranID = API_UUIDCREATE()
    		tbl.change_end()
    	end if
    	tbl.fetch_next()
    end while
    tbl.batch_end()
    
    tbl.close()
    Also, this process could be done with an update operation filtering for records where trim(tranid) = "".
    Last edited by Stan Mathews; 06-22-2017 at 08:23 AM.
    There can be only one.

  3. #3
    "Certified" Alphaholic Mike Wilson's Avatar
    Real Name
    mike wilson
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    4,126

    Default Re: how to promote added field as primary key

    Wouldn't it have to be:

    Code:
    dim search_name as C=""
    dim tbl as p 
    tbl = table.open("yourtablename") 'use actual table name
    tbl.fetch_first()
    tbl.batch_begin()
    while .not. tbl.fetch_eof()
    	if (trim(tbl.TranID) =search_name then
    		tbl.change_begin()
    		tbl.TranID = API_UUIDCREATE()
    		tbl.change_end()
    	end if
    tbl.fetch_next()
    end while
    tbl.batch_end()
    tbl.close()
    Last edited by Mike Wilson; 06-22-2017 at 08:53 AM.
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

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

    Default Re: how to promote added field as primary key

    That would be the syntax if the expression was used in a filter. Actually it would be something like

    "trim(tbl.TranID) = "+quote(search_name)

    but in an xbasic script line, not.

    You can test in the interactive.

    search_name = ""
    tbl.tranid = "not blank"
    ? trim(tbl.TranID) = search_name
    = .F.

    There's really no reason I can see to even use search_name

    the line could be

    if (trim(tbl.TranID) = "") then
    There can be only one.

Similar Threads

  1. URL Link field has added characters
    By bbscop in forum Application Server Version 11 - Web/Browser Applications
    Replies: 0
    Last Post: 05-04-2012, 02:43 PM
  2. Added field to table - Web Component does not see it
    By AAVasaris in forum Application Server Version 9 - Web/Browser Applications
    Replies: 2
    Last Post: 08-05-2008, 02:03 PM
  3. working to promote what you have created with Alpha Five
    By Richard Rabins in forum Announcements
    Replies: 0
    Last Post: 06-18-2007, 05:06 PM
  4. Retro-enumerate an added index field?
    By Son of Shulzie in forum Alpha Five Version 5
    Replies: 4
    Last Post: 06-29-2006, 11:38 PM

Bookmarks

Posting Permissions

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