Results 1 to 8 of 8

Thread: Handling Exclusion of "rowid" Column in RichClient Database Iterations

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    761

    Question Handling Exclusion of "rowid" Column in RichClient Database Iterations

    Hello!

    I am facing a persistent challenge where the "rowid" column is consistently excluded from the column iterations in RichClient. This exclusion forces me to use less straightforward methods to handle it, which complicates my code unnecessarily. Here’s how I currently iterate through the columns:

    Code:
    Public Sub TellCols(ByRef uCn As cConnection)
        Dim nDB As cDataBase
        Dim nTbl As cTable
        Dim nCol As cColumn
        
        For Each nDB In uCn.DataBases
            For Each nTbl In nDB.Tables
                Debug.Print "Table: " & quote(nTbl.Name)
                Debug.Print "Cols: "
                
                For Each nCol In nTbl.Columns
                    Debug.Print vbTab & quote(nCol.Name)
                    If IsEqual(nCol.Name, "rowid") Then
                        Debug.Assert False'This line is never hit
                    End If
                Next
            Next
        Next
    End Sub
    This setup omits "rowid" from the listing, making it difficult for me to handle database structure and field types as seamlessly as I'd like. To work around this, I have to "smuggle" "rowid" back into the mix, which overcomplicates what should be a straightforward task.

    Does anyone have insights on why "rowid" might be omitted or advice on how to include it in the iteration without resorting to cumbersome workarounds? Any suggestions for a more elegant solution would be greatly appreciated.

    Thank you!

  2. #2
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: Handling Exclusion of "rowid" Column in RichClient Database Iterations

    Is rowid part of your CREATE TABLE statement? I thought it was automagically created i.e. one can safely assume every table has rowid as first column which is not hard to account for in any DDL too I guess.

  3. #3
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,734

    Re: Handling Exclusion of "rowid" Column in RichClient Database Iterations

    The rowid is maybe physically a column of each table and can be used as one in queries.
    When you create a new table then it’s automatically there

    https://www.sqlite.org/autoinc.html

    https://www.sqlite.org/c3ref/last_insert_rowid.html

  4. #4
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    813

    Re: Handling Exclusion of "rowid" Column in RichClient Database Iterations

    Quote Originally Posted by tmighty2 View Post
    Does anyone have insights on why "rowid" might be omitted or advice on how to include it in the iteration without resorting to cumbersome workarounds? Any suggestions for a more elegant solution would be greatly appreciated.
    You don't mention which DBMS you're using, but I suspect it's Oracle Database.

    If so, then Our Friends in Redwood City probably don't want to messing with it!

    ROWID doesn't show up as a "column" in your table.
    It's more like "metadata" about the table (and, actually, the address of the row in the data block in the data file in the tablespace).

    ROWID can change (with ROW MOVEMENT ENABLED) so you probably shouldn't be trying to [store and] use them in your application code.
    Don't rely on updating rows based on their retrieved ROWID values. You might get away with it inside a single transaction, but you're sailing mighty close to wind even doing that.

    Regards, Phill W.

  5. #5
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,734

    Re: Handling Exclusion of "rowid" Column in RichClient Database Iterations

    TS is using vbRichClient which comes with SQLite

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    761

    Re: Handling Exclusion of "rowid" Column in RichClient Database Iterations

    No, rowid is not part of my CREATE TABLE statement.
    It is automatically added when I create a table using RC6.
    It is just not included in the for each...
    I have been using rowid as an identifier for UPDATE and DELETE statements ever since.

  7. #7
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,734

    Re: Handling Exclusion of "rowid" Column in RichClient Database Iterations

    No it’s an implicitly available column/field.
    What is you want to achieve?

  8. #8
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,262

    Re: Handling Exclusion of "rowid" Column in RichClient Database Iterations

    If you don't have an explicit Integer-PrimaryKey, the only way to access the Value of "rowid" is to explicitely SELECT it in a SELECT statement.

    rowid doesn't turn up in any calls to Metadata like sqlite_master or PRAGMA table_info('SomeTable')

    This begs the question: Why do you want to read it out?
    In that sense, rowid is NOT a column. Its values are stored in a BTree, with the rowid as Key (and probably the tablename).
    It's more like an Index

    Create an Integer Primary Key and be done with it.
    Because in that case, THAT Integer-PK becomes an ALIAS for rowid

    Code:
    CREATE TABLE t(ID INTEGER PRIMARY KEY, MyField TEXT);
    /*Add some Rows*/
    SELECT rowid, ID, MyField FROM t
    /*returns - NOTE THE COLUMN-NAMES!! */
    ID, ID, MyField
    EDIT: Forgot: This only works if you DON'T use AutoIncrement for the Integer-PK (and you don't need AutoIncrement in any case)
    Last edited by Zvoni; Oct 30th, 2024 at 02:21 AM.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width