0
我有以下node.js
代码经由mysql
模块执行它下面的SQL
,然而,打印null
到console
即使当同一MySQL
用户帐户下手动执行的SQL
本身返回预期的值。有没有什么我在执行这个检索合适的结果时失踪?获取结果来自node.js multipleStatements查询?
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
这样可防止内的另一stored procedure
删除从动态SQL
和functions
和stored procedures
,要求我归还的东西被丢弃,然后执行那些作为一个单独的声明。一种解决丢弃这些functions
和stored procedures
将工作一样好,但我不希望它存在(这是PHP
端口,其中多个语句return效果很好控制台输出,如果它可以帮助:
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 } ]
做的console.log( wipeSQL)之前conn.query并检查什么查询获取构建并传递给conn.query.Then在mysql查询浏览器上手动触发此查询以查看结果。 – AJS
@AJS那么,这是愚蠢的。可能是时间传递给晚上,问题归结为用'.split('%% DATABASE_NAME %%')替换'.replace('%% DATABASE_NAME %%',conf ['databasedatabase'])'。join(conf ['databasedatabase'] )'谢谢,如果你发布了这个效果的答案,我会接受它,因为你找到了它。 – CoryG
欢迎...添加为答案... – AJS