Skip to content

Query sqlite_master #1612

Closed
Closed

Description

@vincentbernat

Hi!

I would like to test if I get the same tables when running .sync({force: true}) and when using the migration process. I am using in-memory SQLite tables for that. I thought that I would be able to query sqlite_master special table and compare the sql column. However, since this table is schema-less, it seems that there is a bit of magic behind it.

SELECT * FROM sqlite_master will return names. SELECT sql FROM sqlite_master will return undefined for each row. SELECT 1 FROM sqlite_master will also return undefined for each row.

How should this table be queried?

Activity

  1. mickhansen commented on Apr 9, 2014

    @mickhansen
    Contributor

    I don't really know that much about sqlite, but googling gave me this: http://www.sqlite.org/faq.html#q7

    It appears you need to use multiple queries, one to get name from sqlite master, and then something like:

    SELECT sql FROM sqlite_master WHERE name = 'foo';

    But honestly i don't know, this is very sqlite specific - Not so much sequelize ;)

  2. mickhansen commented on Apr 9, 2014

    @mickhansen
    Contributor

    From what i'm reading SELECT * FROM sqlite_master; should give you sql as well, but again, i have no idea.

  3. vincentbernat commented on Apr 9, 2014

    @vincentbernat
    Author

    There is some code to handle this table in sequelize. See here:
    https://github.com/sequelize/sequelize/blob/b1f666e9663791f0fe7ec7e8335d472515731d69/lib/dialects/sqlite/query.js

    I said previously that this table was schema-less but it is not:

    sqlite> PRAGMA table_info(sqlite_master);
    0|type|text|0||0
    1|name|text|0||0
    2|tbl_name|text|0||0
    3|rootpage|integer|0||0
    4|sql|text|0||0
    

    So, why the special case?

  4. vincentbernat commented on Apr 9, 2014

    @vincentbernat
    Author

    After digging a bit, I can workaround the special case by using a view. This is fine for me but maybe this special case is not needed anymore. Remains from sqlite2?

  5. vincentbernat commented on Apr 9, 2014

    @vincentbernat
    Author

    For reference, here is my test: https://gist.github.com/vincentbernat/10239464

    While there is no guarantee for columns ordering, this currently works as expected.

  6. added a commit that references this issue on Apr 9, 2014
  7. janmeier commented on Apr 14, 2014

    @janmeier
    Member

    I believe the reason for skipping pragma if querying sqlite_master is that sqlite_master is used internally, so not querying pragma each time saves space. However, the current implementation queries other tables for pragma, each time a query is made to those tables, so I don't know how much we are really saving.

    The reason we are even using PRAGMA is to get the column types so we can parse the data correctly btw.

    @vincentbernat Do you want to take a stab at modifying sqlite/query and adding a couple of tests. The don't have to be migrator specific, perhaps just testing that you can query sqlite_master and get the expected result

  8. janmeier commented on Apr 8, 2015

    @janmeier
    Member

    Closing this issue, since it is neither a bug report nor a feature request.

    For general sequelize questions, please use StackOverflow or Google groups.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions