Results 1 to 8 of 8

Thread: Help required with SQLite syntax (attached db)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    760

    Question Help required with SQLite syntax (attached db)

    Code:
        Dim cOld As cConnection
        Set cOld = New cConnection
        m_CN.AttachDataBase "D:\backup.db", "old"
        
        m_CN.Execute "UPDATE main.stuff SET " & _
        "main.resultsfrombatchaligner=old.resultsfrombatchaligner," & _
        "main.acatranscriptionforbatchaligner=old.acatranscriptionforbatchaligner," & _
        "main.f0text=old.f0text," & _
        "main.pmtext=old.pmtext " & _
        "WHERE main.rowid=old.rowid"
        
        Debug.Assert m_CN.AffectedRows > 0
        m_CN.DetachDataBase "old"
    I am getting the error "Cannot compile SQL-Statement: near ".": syntax error".

    What I want to do it restore the value of the columns resultsfrombatchaligner, acatranscriptionforbatchaligner, f0text and pmtext as I had accidentally set them to ''.
    No other harm was done to the db, so I wanted to just restore these values using an older backup db.

    Thank you for any help as I don't see my mistake.

    Thank you.
    Last edited by tmighty2; May 11th, 2024 at 10:36 AM.

  2. #2
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: Help required with SQLite syntax (attached db)

    You have to take care with the explicit naming of columns.
    The prefixed namespaces "main" and "old" refer to DBs (not Tables).

    A full name-referenc to a column needs to be given via DBName.TableName.ColumnName -
    and not (as currently) DBName.ColumnName.

    Olaf

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help required with SQLite syntax (attached db)

    Thread moved from VB6 CodeBank, which is for sharing working VB6 code snippets, to the Database Development forum.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    760

    Re: Help required with SQLite syntax (attached db)

    Olaf, thank you, but the error message does not go away even with this code:

    Dim cOld As cConnection
    Set cOld = New cConnection
    m_CN.AttachDataBase "D:\backup.db", "old"

    m_CN.Execute "UPDATE main.stuff SET " & _
    "main.stuff.resultsfrombatchaligner=old.stuff.resultsfrombatchaligner," & _
    "main.stuff.acatranscriptionforbatchaligner=old.stuff.acatranscriptionforbatchaligner," & _
    "main.stuff.f0text=old.stuff.f0text," & _
    "main.stuff.pmtext=old.stuff.pmtext " & _
    " WHERE main.stuff.rowid=old.stuff.rowid"

    Debug.Assert m_CN.AffectedRows > 0
    m_CN.DetachDataBase "old"

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

    Re: Help required with SQLite syntax (attached db)

    Remove all main. Including the dot
    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

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    760

    Re: Help required with SQLite syntax (attached db)

    Thank you, but that doesn't work either.

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

    Re: Help required with SQLite syntax (attached db)

    Does the query work in a SQLite-client, e.g. DB Browser for SQLite?
    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

  8. #8
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,891

    Re: Help required with SQLite syntax (attached db)

    Is this SQL part of a TRIGGER? If so, try changing the "main." to "new.". If that doesn't work, please post a minimally reproducible code sample for us to work with.

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