Skip to content

Foreign Key Pragma doesn't persists between connections #848

Closed

Description

@navdeepmahajan

Details for the issue

We are using sqllitedb browser to maintain a local db on the device. The issue is everytime we close and reopen the device the foreign key constraint/pragma is unchecked and as a part user is able to insert corrupt content in the DB. Please resolve.

Useful extra information

I'm opening this issue because:

  • DB4S is crashing
  • DB4S has a bug
  • DB4S needs a feature
  • DB4S has another problem

I'm using DB4S on:

  • Windows: ( version: ___ )
  • Linux: ( distro: ___ )
  • Mac OS: ( version: ___ )
  • Other: ___

I'm using DB4S version:

  • 3.9.1
  • 3.9.0
  • Other: ___

I have also:

Activity

  1. justinclift commented on Oct 27, 2016

    @justinclift
    Member

    Ouch, that doesn't sound good. 😦

    Does it happen even when you save using a project file?

    1. Open database

    2. Change Pragma setting

    3. File → Save Project (then pick a filename to save as)

      screen shot 2016-10-27 at 12 21 06

    4. Close the database

    5. File → Open Project

      screen shot 2016-10-27 at 12 22 01

    In theory, settings are supposed to be saved ok when using project files. They're a way to wrap "meta" information about a database in a safe way.

    But, it's definitely possible that's not working properly for this. 😦

  2. tomcumming commented on Jan 8, 2017

    @tomcumming

    Same issue on windows portable build. Also seems to ignore the pragma after I turn it on (i can still insert invalid rows)

    Still seems broken in nightly

  3. MKleusberg commented on Jan 8, 2017

    @MKleusberg
    Member

    As a first thought: is the check box in View -> Preferences, Database, Foreign keys checked or unchecked?

  4. tomcumming commented on Jan 8, 2017

    @tomcumming

    Yes, it is checked. I'm sorry I can't build myself and check what's going on for you but I don't do any dev on windows

  5. MKleusberg commented on Jan 8, 2017

    @MKleusberg
    Member

    That's odd. You said it's also ignoring the pragma after manually turning it on. I assume you did click the Save button at the bottom of the window? Sounds like a stupid question but I sometimes forget that button 😉 If you're sure you saved the modified pragma settings. it seems like we have a general problem with foreign keys in your case. Not sure yet what to do then 😃

  6. tomcumming commented on Jan 8, 2017

    @tomcumming

    yes I am :) i also tried PRAGMA foreign_keys = on; in the sql box and write changes after running that. Still no luck

  7. MKleusberg commented on Jan 14, 2017

    @MKleusberg
    Member

    I did some further research: you can't edit the foreign keys pragma inside a transaction (https://www.sqlite.org/pragma.html#pragma_foreign_keys). That makes it impossible to set that pragma from inside the SQL editor. Also, unlike other pragmas, it is not stored in the database file but must be set again each time a new connection is built (https://stackoverflow.com/a/15303742). This makes it impossible to set the foreign keys pragma in the Pragma editor and expect it to stay with that value. That's pretty stupid but we can't do much about that 😦

    The only question is why the the check box in the Preferences dialog doesn't work for you. However, I've just changed the settings handling a bit, so tomorrow's nightly build might be worth checking out. Can you give that a try? 😃

  8. justinclift commented on Jan 14, 2017

    @justinclift
    Member

    If it's really needed to kept, we could store that pragma setting in the (per database) project file.

  9. MKleusberg commented on Jan 22, 2017

    @MKleusberg
    Member

    Just added the foreign keys settings to the project file 😃 I think that's all we can do at the moment.

  10. justinclift commented on Jan 22, 2017

    @justinclift
    Member

    Awesome. 😄

    @tomcumming Would you have time to try out the nightly build (tomorrow), and check that the pragma setting works for you when the database is saved & loaded via project file?

  11. tomcumming commented on Jan 22, 2017

    @tomcumming

    Sorry @justinclift , I won't have access to a windows PC for a while !

  12. justinclift commented on Jan 22, 2017

    @justinclift
    Member

    No worries, was a thought. 😄

  13. justinclift commented on Jan 22, 2017

    @justinclift
    Member

    Oops. Sorry, wrong button. 😉

    @tomcumming Our automatic nightlies get built for OSX too if that helps?

  14. MKleusberg commented on Oct 3, 2018

    @MKleusberg
    Member

    Any update here? 😄

  15. self-assigned this
    on Oct 3, 2018
  16. chrisjlocke commented on Jan 8, 2019

    @chrisjlocke
    Member

    I've created two project files - one with the 'Foreign Keys' checked and one unchecked. When loading, the 'Foreign Keys' option is checked/unchecked, so I'll close this as it has been resolved.
    @tomcumming - I appreciate its been a while since you opened this issue, but if you still use DB4S, you'd be recommended to try the latest nightly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions