Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Primary Key

  1. #1
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    624

    Primary Key

    I am testing by creating an app from scratch rather than importing a VFP project as I have tried in the past.

    I have added a database and added a table to it called dsighting

    I have added a field cpk_dsighting which is a C6 field

    I want to mark this as the tables primary key.

    How do I do that as I cannot find anything in the table console to allow me to do that.

  2. #2
    Lianja Team chris.mavin's Avatar
    Join Date
    Feb 2012
    Location
    London UK
    Posts
    29
    Hi Avianmanagement,

    If you set your cpk_dsighting field to be the search field it will be master index tag order when you open that page, in addition Lianja will automatically build the index.

    Chris.

  3. #3
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    624
    Hi Chris,

    The field for the PK would not appear on forms as the PK's only purpose in life it to uniquely identify the row in the table, so I would not allow the user to do anything with it.

    David

  4. #4
    Lianja Team chris.mavin's Avatar
    Join Date
    Feb 2012
    Location
    London UK
    Posts
    29
    David,

    OK I see.

    You have a few options depending how you wish to identify the row.

    There is an automatically generated sequence number which uniquely identifies each row, you can return this using the SYNCNUM() function.
    You can find the documentation for this at http://www.lianja.com/doc/index.php/SYNCNUM()

    You could also create column with autoinc specified. If this is not on a form you would have to create the index yourself and set the order to it.

    To create the index:

    Using NoSQL syntax you would use

    http://www.lianja.com/doc/index.php/INDEX
    http://www.lianja.com/doc/index.php/SET_ORDER

    Using SQL

    http://www.lianja.com/doc/index.php/CREATE_INDEX

    Chris.

    Quote Originally Posted by avianmanagement View Post
    Hi Chris,

    The field for the PK would not appear on forms as the PK's only purpose in life it to uniquely identify the row in the table, so I would not allow the user to do anything with it.

    David

  5. #5
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    624
    Thanks Chris,

    What is the difference, if there is one, between seqno() and SYNCNUM()

    I currently have the default for the Pk set as strzero(seqno(),6)

    With SYNCNUM() is it unique each time it is generated, like GUID. So if I had two users using teh same app would all of their SYNCNUM() values be unique, so I could merge their data easily as one can do with GUIDs
    Last edited by avianmanagement; 2013-02-15 at 08:54.

  6. #6
    Lianja Team chris.mavin's Avatar
    Join Date
    Feb 2012
    Location
    London UK
    Posts
    29
    David,

    SEQNO is stored in table header, each time it is called it returns the next number, a zap of the table will reset the SEQNO to 0.

    SYNCNUM is used internally and is uniquely assigned, it is not effected by zap and will continue to increase.

    Also SEQNO is a numeric, SYNCNUM is a hexadecimal returned as a character.

    Chris.

    Quote Originally Posted by avianmanagement View Post
    Thanks Chris,

    What is the difference, if there is one, between seqno() and SYNCNUM()

    I currently have the default for the Pk set as strzero(seqno(),6)

    With SYNCNUM() is it unique each time it is generated, like GUID. So if I had two users using teh same app would all of their SYNCNUM() values be unique, so I could merge their data easily as one can do with GUIDs

  7. #7
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    624
    So for unique PK values one would probably be better off using SYNCNUM since it will ALWAYS remain unique for the table no matter what.

    Is it unique across apps in use same as a GUID is ? What i mean is that if I had two users, one in UK and one in USA with two of my apps not linked togetehr in any way and they both were adding records to a table dsighting would the syncnum be unique for them both so I could just merge their data if I wanted to without having to worry about duplicate PK values, as one can with GUIDs ?

  8. #8
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    624
    Hi Chris,

    Testing this and have come up with a few odd things.

    Add text box canvas from the Advanced tools and set it's data source to CURSYNCNUM(DSIGHTING) and I get a value of 00000000000000AF when adding a new record.

    Add text box canvas from the Advanced tools and set it's data source to SYNCNUM(DSIGHTING) and I get a value of 000000AF when adding a new record.

    Add a field to table and have it's default set to SYNCNUM(DSIGHTING). Drag filed onto canvas and when I add new record I get a value of 00000000

    I would have expected them to all be the same.

    The wikki says CURSYNCNUM() and SYNCNUM() both return the 8 digit hexadecimal sequence number as a character string, CURSYNCNUM() seems to be 16

    David

  9. #9
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    6,731
    Blog Entries
    18
    I'll look into that as they both shoud be 8 characters.

    I'll also look at adding a GUID() function which is unique to a machine. It will postfix the SYNCNUM. It will be a lot longer but will better server the purpose.

    please submit an ER for this so it gets added onto my todo list.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  10. #10
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    6,731
    Blog Entries
    18
    No need to submit an ER, I have added a new function in RC4 called GUID() that generates a 36 character unique GUID so you can use that for your primary keys. It is unique across all locations and operating systems; windows, mac and linux. See attached console output. (I like to test functions like this in the console to see what they produce)

    Name:  new_guid_function.jpg
Views: 113
Size:  37.9 KB
    Last edited by barrymavin; 2013-02-15 at 21:29.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

Bookmarks

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
  •  
Journey into the Cloud
Join us