从node.js中获取结果multipleStatements查询?

时间:2017-04-03 05:34:46

标签: mysql node.js node-mysql

我有以下node.js代码通过SQL模块执行其下面的mysql代码,但即使是null,它也会向console打印SQL MySQL本身在同一let wipeSQL = fs.readFileSync('./inc/sql/wipedb.sql', 'utf8').replace('%%DATABASE_NAME%%', conf['databasedatabase']); conn.query(wipeSQL, (err, results, fields) => { if (err) { conn.destroy(); reject (false); return; } console.log(results[results.length - 1][0]['@procedures'], fields[fields.length - 1]); resolve(); }); 用户帐户下手动执行会返回预期值。在执行此操作时是否缺少某些内容来检索相应的结果?

USE `%%DATABASE_NAME%%`;
SET FOREIGN_KEY_CHECKS = 0;

SET @procedures = '';
SELECT
    GROUP_CONCAT(CONCAT('DROP PROCEDURE IF EXISTS `', routine_schema, '`.`', routine_name, '`') SEPARATOR ';')
INTO
    @procedures
FROM
    information_schema.ROUTINES R
WHERE
    R.ROUTINE_TYPE = "PROCEDURE" AND
    R.ROUTINE_SCHEMA = '%%DATABASE_NAME%%';

SET @procedures = CONCAT(@procedures, ';');

SET @functions = '';
SELECT
    GROUP_CONCAT(CONCAT('DROP FUNCTION IF EXISTS `', routine_schema, '`.`', routine_name, '`') SEPARATOR ';')
INTO
    @functions
FROM
    information_schema.ROUTINES R
WHERE
    R.ROUTINE_TYPE = "FUNCTION" AND
    R.ROUTINE_SCHEMA = '%%DATABASE_NAME%%';

SET @functions = CONCAT(@functions, ';');
SET @procedures = CONCAT(@procedures, @functions);

SET @tables = '';
SELECT
    GROUP_CONCAT(CONCAT('`', table_schema, '`.`', table_name, '`'))
INTO
    @tables
FROM
    information_schema.tables
WHERE
    table_schema = '%%DATABASE_NAME%%';

SET @tables = IF(@tables IS NULL, 'SET @tables = NULL;', CONCAT('DROP TABLE ', @tables, ';'));

PREPARE stmt FROM @tables;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET FOREIGN_KEY_CHECKS = 1;

SELECT @procedures;
MySQL

目的是解决functions中的问题,阻止从动态stored procedures和其他SQL中删除stored procedurefunctions,从而要求我返回要删除的东西,然后将它们作为单独的语句执行。放弃那些stored proceduresPHP的解决方案也可以正常工作,但我不希望它存在(这是来自null [ FieldPacket { catalog: 'def', db: '', table: '', orgTable: '', name: '@procedures', orgName: '', charsetNr: 33, length: 50331645, type: 250, flags: 0, decimals: 31, default: undefined, zeroFill: false, protocol41: true } ] 的端口,其中包含多个语句返回工作正常。控制台输出,如果它有帮助:

git fetch

1 个答案:

答案 0 :(得分:1)

在conn.query之前执行console.log(wipeSQL)并检查正在构建什么查询并传递给conn.query。然后在mysql查询浏览器上手动触发此查询以查看结果。