Skip to content

DELIMITER within conn.query() throws an Error #280

@avoidwork

Description

@avoidwork

The following sql statements are held in 1 (of many) .sql files which run against a database, to bootstrap the db.

DROP TABLE IF EXISTS `alerts`;
CREATE TABLE `alerts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `uuid` char(50) COLLATE utf8_bin NOT NULL DEFAULT '',
  `type` char(255) CHARACTER SET latin1 NOT NULL,
  `message` text COLLATE utf8_bin NOT NULL,
  `timestamp` bigint(20) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `type` (`type`) USING BTREE,
  KEY `timestamp` (`timestamp`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
delimiter ;;
CREATE TRIGGER `beforeInsert_alerts` BEFORE INSERT ON `alerts` FOR EACH ROW SET new.uuid = uuid();
 ;;
delimiter ;

When I execute that from conn.query(), with mutlipleStatements: true, I get the following error:

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delimiter $$                      
CREATE TRIGGER `beforeInsert_alerts` BEFORE INSERT ON `alerts` FOR ' at line 1                                                                                                                  
    at Function.Sequence.packetToError (/Users/jason/Projects/FileTrek/Dashboard/node_modules/mysql/lib/protocol/sequences/Sequence.js:30:14)                                                   
    at Query.ErrorPacket (/Users/jason/Projects/FileTrek/Dashboard/node_modules/mysql/lib/protocol/sequences/Query.js:59:22)                                                                    
    at Protocol._parsePacket (/Users/jason/Projects/FileTrek/Dashboard/node_modules/mysql/lib/protocol/Protocol.js:143:24)                                                                      
    at Parser.write (/Users/jason/Projects/FileTrek/Dashboard/node_modules/mysql/lib/protocol/Parser.js:42:10)                                                                                  
    at Protocol.write (/Users/jason/Projects/FileTrek/Dashboard/node_modules/mysql/lib/protocol/Protocol.js:31:18)
    at Socket.ondata (stream.js:38:26)
    at Socket.EventEmitter.emit (events.js:88:17)
    at TCP.onread (net.js:395:14)

Changing the delimiter to $$, or any other character(s) doesn't change the result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions