当使用nodejs mariadb控制器在datagrip中工作时创建索引时发生SQL语法错误

2w2cym1i  于 7个月前  发布在  其他
关注(0)|答案(1)|浏览(73)

我一直在努力寻找我的问题:
我用mariadb node module从我的节点代码中创建了一些表,代码如下:
dbConn.query(fs.readFileSync('<path to the sql file>').toString())dbConn来自pool.getConnection(),其中pool来自mariadb.createPool(...)
然而,在这样做的时候,我收到了一个SqlError: (conn=3, no: 1064, SQLState: 42000) You have an error in your SQL syntax。该错误还转储提供的SQL字符串,它与文件内容匹配。
最重要的是,当我用datagrip对完全相同的数据库执行完全相同的sql文件时,我没有收到这个错误!
文件看起来像这样:

create or replace table app.AuthenticatedUsers
(
    UserId varchar(255) not null comment 'email encodé',
    token  varchar(255) not null,
    salt   varchar(20)  not null,
    constraint primary key (UserId)
);

create or replace unique index AuthenticatedUsers_UserId_uindex
    on app.AuthenticatedUsers (UserId);

错误发生在这个命令上:create or replace unique index AuthenticatedUsers_UserId_uindex on app.AuthenticatedUsers (UserId);,每次我试图创建一个索引(唯一与否,也对整数)时都会得到这个错误,只从节点。
我如何让它在Node中也能工作?

y1aodyip

y1aodyip1#

出于安全原因,MariaDB服务器(和MariaDB连接器)默认情况下不支持执行多个语句。
要启用对多语句执行的支持,您必须在建立连接时指定一个选项。对于node.js,它是multipleStatements。

相关问题