sqlite database confusion

  1. 4 months ago

    Perry P

    Feb 18 Pre-Release Testers, Xojo Pro Boston, MA
    Edited 4 months ago

    First, I'm on Xojo 2017r3. I'm following the instructions here to set up a simple 1-table database to store information from a dictionary. This tutorial was clearly made with a different version of the IDE, but I was able to figure it out and make the database. I see it in the left column of the IDE. Note that I don't care if this database is persistent - it's meant to be a temporary place to compile the records before exporting a report. It'd be fine as an in-memory database (which is what I've just set up, right?)

    I have a Module with a single property: db as database so that it's global.

    In my App, I have an Open Event Handler that opens the database, ManifestReports:

    db = ManifestReports
    if db = Nil then
      MsgBox "Manifest Report DB not found"
    end if

    This works - or at least, it doesn't fail.

    My app traverses a folder and gathers metadata about the files it contains, putting each file's metadata into a dictionary (mediaItem) . When that's done, it's supposed to add a row to the database, one for each file:

    dim r as DatabaseRecord
    r = new DatabaseRecord 
    
    //loop through the dictionary that holds the metadata for this file
    //and set it up to be added to the database
    for each key As Variant In mediaItem.Keys
      dim field as string = key
      r.column(field) = mediaItem.value(key)
    next
    
    //connect to and add the metadata to the database
    If db.Connect Then
      db.InsertRecord("mediaInfo", r)
    else
      msgBox db.errormessage
    end if
    
    //display any errors
    if db.error then
      msgBox db.errormessage
    end if

    However, it's never connecting to the database. The error message it's giving is that there is no error message, but db.Connect is somehow failing.

    Am I missing something fundamental here?

  2. Derk J

    Feb 18 Pre-Release Testers, Xojo Pro
    Edited 4 months ago

    I have a Module with a single property: db as database so that it's global.

    Shouldn't that be db As SQLiteDatabase (or any other)?

    You might wanna try the "examples" instead of old documentation, they will show you how it's done instead of how to do it.

  3. Perry P

    Feb 18 Pre-Release Testers, Xojo Pro Boston, MA

    @Derk J Shouldn't that be db As SQLiteDatabase (or any other)?

    Hmm. When I change the property to db as SQLiteDatabase, I get the following error in my App's Open event handler:

    App.Open, line 16
    Type mismatch error.  Expected class SQLiteDatabase, but got class Database
    db =  ManifestReportsDB

    Has that tutorial sent me barking up the wrong (outdated) tree?

  4. Paul L

    Feb 18 Xojo Inc http://docs.xojo.com

    The Connecting to Databases video might be helpful:

    https://youtu.be/Cshtk7VmEqw

  5. Derk J

    Feb 18 Pre-Release Testers, Xojo Pro

    @PerryPaolantonio Hmm. When I change the property to db as SQLiteDatabase, I get the following error in my App's Open event handler:

    App.Open, line 16
    Type mismatch error.  Expected class SQLiteDatabase, but got class Database
    db =  ManifestReportsDB

    Has that tutorial sent me barking up the wrong (outdated) tree?

    In app.open do db = New SqliteDatabase tomake an instance of the “db” property

  6. Emile S

    Feb 18 Europe (France, Strasbourg)

    Perry:

    Part of the link to the project is:
    ReallyBasicRB/Sits/SimpleDB.sit

    This (IMHO) an old (very old) project. The sit extension (StuffIt) dates from the early 200x…

    This is the complete link: "file:///ReallyBasicRB/Sits/SimpleDB.sit" and is not currently downloadable.

    My conclusion: Kill that project and forget all about it,

    Advice:
    Create a brand new Project,
    Take the current language reference code examples,
    Put these together,
    And you will get a fully worked db example (with a bit of work).

    Using a totally outdated project with a recent (2 years old) IDE is a really bad idea.

  7. Perry P

    Feb 19 Pre-Release Testers, Xojo Pro Boston, MA

    I got it working this morning. Thanks everyone

or Sign Up to reply!