DBKit Function PrimaryKeyColumn

Testing a Desktop DBKit app similar to the YouTube presentation by Geoff and am getting an error that the primary key could not be determined. The rowset from Connection.TableColumns(Table) is nil. The table is known and there are 8 variant BoundControls. DB Browser for Sqlite shows primary key. I have debugged both my app and the tutorial and am not seeing why there is a problem with the primary key. The DBKit.DBkItConnector shows the PrimaryKeyValue to be nil. Thanks for any help.

what is the name of your primarykey column ?
and the database engine you’re using ?

The primary key column is flight_record_ID and the database engine is sqlite.

is it an integer autoincrement type ?
you could try to lowercase the column name, it is important in postgres, but usually sqlite don’t care

Found the problem. The app will have another relational table and I had included the other table name in the window DBKit table property. Thanks

Hi dear, I have the same issue, using MariaDB, I’ve tried different types for primary key, Int(11) with and without autoincrement, varchar(5), lower case, mixt case, upper case… same result. Funny enough it fills one line in my listbox.

My problem was that I was getting ahead of myself and included another related table in the DBKitConnector DBKit property. Geoff has a brief description of what you need to do for related tables.

Geoff states that you need a DBKitConnector for each table.

Hi Bill, to cut multiple sources of problems away, I now use a local SQLite DB… with the same problem. I’ve created a single table with its primary key… then - and this might be an additional source of trouble - I’ve gone to the DBeaver utility to populate the database, and bingo, I get an exception of a missing primary key, and my Xojo IDE cannot edit the table structure anymore, whereas the IDE clearly shows the key symbol.

New Update… in this dbkit method, Table points to “Customers”, whereas I don’t use such a table.

Now the question is how can I change this, I am rather sure that no customers assignment is in the code.

Function PrimaryKeyColumn() As String
If Table = “” Then
Var e As New DatabaseException
e.Message = “The primary key cannot be found without a Table.”
Raise e
Else
Try
Var rs As RowSet
rs = Connection.TableColumns(Table)
For Each column As DatabaseRow In rs
If rs.Column(“IsPrimary”).BooleanValue Then
Return rs.Column(“ColumnName”).StringValue
End If
Next

  Var e As New DatabaseException
  e.Message = "The " + Table + " table has no primary key column."
  Raise e
  
Catch error As DatabaseException
  MessageBox("Error: The primary key for " + Table + " could not be determined.")
End Try

End If
End Function

I do not understand why you write that.

To understand why, look SQLiteDatabase.LastRowID

This call returns the Row ID for rs (if I understand correctly what you want to do).

this is not MY code but it’s a DBKit method.

Gary, Yon need to check the inspector for your DBKitConnector you dragged on to your window. Make sure DBKit table has the correct table name. You can only use one table name per DBKitConnector.

→ All is good now ←
I’m an absolute freshman with Xojo (and its DBKit). There are traps around, and I didn’t miss single one. For instance the absolute sensitivity for upper and lower characters in a variable name is such a source of trouble. In a future release, the IDE could check for those “errors” and not delegate this to the run-time.

Thanks for the support. gary

Xojo is not case sensitive on variable names. Columns names in SQL are case sensitive, Xojo (the IDE) has no access to your database and thus cannot tell you if you’ve got the case right or wrong. It’s a programming language not a database management application.

Not in SQLite.

Yes, but if you end up porting the code to another engine it isn’t worth relying on that.

1 Like