Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite dumpiter dumps invalid script when virtual tables are used #64662

Closed
RonnyPfannschmidt mannequin opened this issue Jan 31, 2014 · 14 comments
Closed

sqlite dumpiter dumps invalid script when virtual tables are used #64662

RonnyPfannschmidt mannequin opened this issue Jan 31, 2014 · 14 comments
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes extension-modules C modules in the Modules dir topic-sqlite3 triaged The issue has been accepted as valid by a triager. type-bug An unexpected behavior, bug, or error

Comments

@RonnyPfannschmidt
Copy link
Mannequin

RonnyPfannschmidt mannequin commented Jan 31, 2014

BPO 20463
Nosy @bitdancer, @RonnyPfannschmidt, @palaviv, @tirkarthi
Files
  • 20463.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2014-01-31.19:57:36.445>
    labels = ['extension-modules', 'type-bug']
    title = 'sqlite dumpiter dumps invalid script when virtual tables are used'
    updated_at = <Date 2018-09-23.16:16:06.541>
    user = 'https://github.com/RonnyPfannschmidt'

    bugs.python.org fields:

    activity = <Date 2018-09-23.16:16:06.541>
    actor = 'xtreak'
    assignee = 'ghaering'
    closed = False
    closed_date = None
    closer = None
    components = ['Extension Modules']
    creation = <Date 2014-01-31.19:57:36.445>
    creator = 'Ronny.Pfannschmidt'
    dependencies = []
    files = ['45049']
    hgrepos = []
    issue_num = 20463
    keywords = ['patch']
    message_count = 3.0
    messages = ['209825', '248823', '278437']
    nosy_count = 5.0
    nosy_names = ['ghaering', 'r.david.murray', 'Ronny.Pfannschmidt', 'palaviv', 'xtreak']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue20463'
    versions = ['Python 2.7']

    Linked PRs

    @RonnyPfannschmidt
    Copy link
    Mannequin Author

    RonnyPfannschmidt mannequin commented Jan 31, 2014

    when using virtual tables, dumpiter generates a broken db script
    virtual table entries must be created as master table entries
    the sqlite tools dump does that correctly
    however pythons iterdump seems to do that rather different and wrong

    sqlite3 test.db "create virtual table test using fts4(example);"
    -------------------------------
    sqlite dump
    PRAGMA foreign_keys=OFF;
    BEGIN TRANSACTION;
    PRAGMA writable_schema=ON;
    INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)VALUES('table','test','test',0,'CREATE VIRTUAL TABLE test using fts4(example)');
    CREATE TABLE 'test_content'(docid INTEGER PRIMARY KEY, 'c0example');
    CREATE TABLE 'test_segments'(blockid INTEGER PRIMARY KEY, block BLOB);
    CREATE TABLE 'test_segdir'(level INTEGER,idx INTEGER,start_block INTEGER,leaves_end_block INTEGER,end_block INTEGER,root BLOB,PRIMARY KEY(level, idx));
    CREATE TABLE 'test_docsize'(docid INTEGER PRIMARY KEY, size BLOB);
    CREATE TABLE 'test_stat'(id INTEGER PRIMARY KEY, value BLOB);
    PRAGMA writable_schema=OFF;
    COMMIT;
    ------------------------------
    python iterdump "import sqlite3;
    c=sqlite3.connect("test.db");
    print("\n".join(c.iterdump()))"
    BEGIN TRANSACTION;
    CREATE VIRTUAL TABLE test using fts4(example);
    CREATE TABLE 'test_content'(docid INTEGER PRIMARY KEY, 'c0example');
    CREATE TABLE 'test_docsize'(docid INTEGER PRIMARY KEY, size BLOB);
    CREATE TABLE 'test_segdir'(level INTEGER,idx INTEGER,start_block INTEGER,leaves_end_block INTEGER,end_block INTEGER,root BLOB,PRIMARY KEY(level, idx));
    CREATE TABLE 'test_segments'(blockid INTEGER PRIMARY KEY, block BLOB);
    CREATE TABLE 'test_stat'(id INTEGER PRIMARY KEY, value BLOB);
    COMMIT;

    @RonnyPfannschmidt RonnyPfannschmidt mannequin added extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Jan 31, 2014
    @ghaering ghaering mannequin self-assigned this Jan 11, 2015
    @ghaering
    Copy link
    Mannequin

    ghaering mannequin commented Aug 19, 2015

    apsw contains code that handles the issues with dumping SQLite databases very well. I plan to integrate this code into pysqlite. We can then later port the fix to the sqlite3 module.

    See ghaering/pysqlite#10 for the tasks and
    https://github.com/rogerbinns/apsw/blob/master/tools/shell.py#L1012 for the apsw code.

    @palaviv
    Copy link
    Mannequin

    palaviv mannequin commented Oct 10, 2016

    Attached is patch with a fix for this issue. This is not as comprehensive as the solution in apsw but I think this should cover most of the cases. The result for Ronny dump after this fix is:

    BEGIN TRANSACTION;
    PRAGMA writable_schema=ON;
    INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)VALUES('table','test','test',0,'CREATE VIRTUAL TABLE test using fts4(example)');
    CREATE TABLE 'test_content'(docid INTEGER PRIMARY KEY, 'c0example');
    CREATE TABLE 'test_docsize'(docid INTEGER PRIMARY KEY, size BLOB);
    CREATE TABLE 'test_segdir'(level INTEGER,idx INTEGER,start_block INTEGER,leaves_end_block INTEGER,end_block INTEGER,root BLOB,PRIMARY KEY(level, idx));
    CREATE TABLE 'test_segments'(blockid INTEGER PRIMARY KEY, block BLOB);
    CREATE TABLE 'test_stat'(id INTEGER PRIMARY KEY, value BLOB);
    PRAGMA writable_schema=OFF;
    COMMIT;

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @erlend-aasland erlend-aasland moved this from TODO: Docs to TODO: Bugs in sqlite3 issues May 21, 2022
    @erlend-aasland erlend-aasland moved this from TODO: Bugs to In Progress in sqlite3 issues Jun 14, 2022
    @erlend-aasland erlend-aasland moved this from In Progress to TODO: Bugs in sqlite3 issues Jun 14, 2022
    @erlend-aasland erlend-aasland added the triaged The issue has been accepted as valid by a triager. label Jul 25, 2022
    @erlend-aasland
    Copy link
    Contributor

    My plan for iterdump is to align it with the implementation in the SQLite shell, but I haven't gotten around to it yet. I think @palaviv's patch is a step in the right direction, and I don't think we should block that patch, just because iterdump also has other problems.

    @erlend-aasland
    Copy link
    Contributor

    Hm, bug or feature; this issue was originally labeled as a "bug". But, the source code clearly included the comment:

    # NOTE: Virtual table support not implemented

    In this case, I believe the correct label should have been "feature", not "bug", so I'm inclined not to backport it.

    @erlend-aasland
    Copy link
    Contributor

    erlend-aasland commented Aug 28, 2023

    I'm going to close this as resolved. Virtual table support has been added to Python 3.13. If you disagree, please ping me, or re-open. cc. @palaviv @RonnyPfannschmidt @ghaering

    @github-project-automation github-project-automation bot moved this from In Progress to Done in sqlite3 issues Aug 28, 2023
    @RonnyPfannschmidt
    Copy link

    I consider it a bug as the output wasn't valid,it should error if it cant make it,

    @erlend-aasland
    Copy link
    Contributor

    I consider it a bug as the output wasn't valid,it should error if it cant make it,

    Hm, yeah, that is a valid point that weighs heavier than the comment.

    @erlend-aasland
    Copy link
    Contributor

    OTOH, this changes the behaviour, which is an argument not to backport it.

    @RonnyPfannschmidt
    Copy link

    @erlend-aasland personally i prefer people see a error when they dump rather than when they later load that dump

    this bug in the worst case makes a broken backup silently appear working - not failing early causes more damage

    silent breakage/invalid datagen is imho worse than adding a error where else people have hidden broken data until they test again

    @RonnyPfannschmidt
    Copy link

    ftr - imho its fine to have a backport that just finally raises a NotImplementedError rather than silently dumping broken data

    @erlend-aasland
    Copy link
    Contributor

    ftr - imho its fine to have a backport that just finally raises a NotImplementedError rather than silently dumping broken data

    I'd rather backport the fix. Anyway, you've convinced me; I agree that this is more a bugfix than a new feature. I'll prepare backports through 3.11.

    @erlend-aasland
    Copy link
    Contributor

    Thanks for you input, @RonnyPfannschmidt.

    erlend-aasland added a commit that referenced this issue Aug 28, 2023
    …dump (#108340) (#108564)
    
    (cherry picked from commit d0160c7)
    
    Co-authored-by: Aviv Palivoda <[email protected]>
    @erlend-aasland
    Copy link
    Contributor

    Backports are queued; marking this as resolved.

    Aug 28, 2023
    …dump (#108340) (#108563)
    
    * [3.12] gh-64662: Add virtual table support to sqlite3.Connection.iterdump (#108340)
    
    (cherry picked from commit d0160c7)
    
    Co-authored-by: Aviv Palivoda <[email protected]>
    
    * The _quote_value helper is not part of 3.12; spell out the replacement
    
    * With quotes
    
    * Ok, let's use explicit quoting
    
    ---------
    
    Co-authored-by: Aviv Palivoda <[email protected]>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes extension-modules C modules in the Modules dir topic-sqlite3 triaged The issue has been accepted as valid by a triager. type-bug An unexpected behavior, bug, or error
    Projects
    Status: Done
    Development

    No branches or pull requests

    2 participants