我有以下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 procedure
和functions
,从而要求我返回要删除的东西,然后将它们作为单独的语句执行。放弃那些stored procedures
和PHP
的解决方案也可以正常工作,但我不希望它存在(这是来自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
答案 0 :(得分:1)