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

describeTable() with SQLite does not quote table name #13268

Closed
2 tasks done
jlherren opened this issue May 11, 2021 · 4 comments
Closed
2 tasks done

describeTable() with SQLite does not quote table name #13268

jlherren opened this issue May 11, 2021 · 4 comments

Comments

@jlherren
Copy link

Issue Description

When using SQLite and calling queryInterface.describeTable('transaction') it fails because it does not properly quote transaction which is a reserved word.

What are you doing?

Here's a small example to reproduce the issue:

const {Sequelize, Model, DataTypes} = require('sequelize');

class Transaction extends Model {}

async function main() {
    let sequelize = new Sequelize({
        logging: console.log,
        dialect: 'sqlite',
        storage: ':memory:',
        define:  {
            freezeTableName: true,
        },
    });

    Transaction.init({
        amount: {type: DataTypes.FLOAT},
    }, {sequelize, modelName: 'transaction'});

    await sequelize.sync();

    console.log(await sequelize.getQueryInterface().describeTable('transaction'));
}

main();

What do you expect to happen?

The table transaction should be correctly queried for its structure.

What is actually happening?

I get this output:

Executing (default): CREATE TABLE IF NOT EXISTS `transaction` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `amount` FLOAT, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL);
Executing (default): PRAGMA INDEX_LIST(`transaction`)
Executing (default): SELECT name FROM `sqlite_master` WHERE type='table' and name!='sqlite_sequence';
Executing (default): PRAGMA TABLE_INFO(`transaction`);
Executing (default): PRAGMA INDEX_LIST(`transaction`)
Executing (default): PRAGMA foreign_key_list(transaction)
(node:15343) UnhandledPromiseRejectionWarning: SequelizeDatabaseError: SQLITE_ERROR: near "transaction": syntax error
    at Query.formatError (/path/node_modules/sequelize/lib/dialects/sqlite/query.js:403:16)
    at Query._handleQueryResponse (/path/node_modules/sequelize/lib/dialects/sqlite/query.js:72:18)
    at afterExecute (/path/node_modules/sequelize/lib/dialects/sqlite/query.js:238:27)
    at Statement.errBack (/path/node_modules/sqlite3/lib/sqlite3.js:14:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:15343) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:15343) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Note how the table name is properly quoted on the first few queries, but not on the last one, which causes it to fail.

Environment

  • Sequelize version: 6.6.2
  • Node.js version: 14.16.1
  • Operating System: Debian Buster

Issue Template Checklist

How does this problem relate to dialects?

  • I think this problem happens only for the following dialect(s): sqlite

Would you be willing to resolve this issue by submitting a Pull Request?

  • Maybe, when I'll have some time. But probably it's such an easy fix that someone familiar with the code can do it in 5 minutes.
@steveschmitt
Copy link
Contributor

Fixed by PR #12752 , which has never been merged.

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@github-actions github-actions bot added the stale label Oct 27, 2021
@steveschmitt
Copy link
Contributor

Fixed by PR #13587 that was recently merged.

@github-actions github-actions bot removed the stale label Oct 28, 2021
@jlherren
Copy link
Author

Awesome, thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants