From 75c8cc0c8e1e1d326c1ba2154164173db97bfa4e Mon Sep 17 00:00:00 2001 From: Oskar Hane Date: Wed, 4 Dec 2019 10:28:57 +0100 Subject: [PATCH] Error message when declaring params on system db --- e2e_tests/integration/multi-db.spec.js | 9 ++++++ src/browser/documentation/help/param.jsx | 2 ++ src/browser/documentation/help/params.jsx | 4 ++- .../help/partials/params-on-systemdb.jsx | 31 +++++++++++++++++++ src/shared/modules/commands/helpers/params.js | 8 ++++- .../services/commandInterpreterHelper.js | 10 ++++-- 6 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 src/browser/documentation/help/partials/params-on-systemdb.jsx diff --git a/e2e_tests/integration/multi-db.spec.js b/e2e_tests/integration/multi-db.spec.js index 3d1acde3b4b..7097a34a6d7 100644 --- a/e2e_tests/integration/multi-db.spec.js +++ b/e2e_tests/integration/multi-db.spec.js @@ -130,5 +130,14 @@ describe('Multi database', () => { cy.connect('neo4j', Cypress.config('password')) cy.dropUser('noroles') }) + it('shows error message when trying to set a parameter on system db', () => { + cy.executeCommand(':clear') + cy.executeCommand(':use system') + cy.executeCommand(':param x => 1') + const resultFrame = cy + .get('[data-testid="frame"]', { timeout: 10000 }) + .first() + resultFrame.should('contain', 'cannot be declared') + }) } }) diff --git a/src/browser/documentation/help/param.jsx b/src/browser/documentation/help/param.jsx index 02348247063..5c9377a4dfa 100644 --- a/src/browser/documentation/help/param.jsx +++ b/src/browser/documentation/help/param.jsx @@ -19,6 +19,7 @@ */ import React from 'react' +import ParamsOnSystemDb from './partials/params-on-systemdb' const title = 'Set a parameter' const subtitle = 'Set a parameter to be sent with queries.' const category = 'cypherQueries' @@ -46,6 +47,7 @@ const content = ( Cypher query example with a param: MATCH (n:Person) WHERE n.name = $name

+

Related

diff --git a/src/browser/documentation/help/params.jsx b/src/browser/documentation/help/params.jsx index 315b93ec5a5..a05785f0496 100644 --- a/src/browser/documentation/help/params.jsx +++ b/src/browser/documentation/help/params.jsx @@ -19,6 +19,7 @@ */ import React from 'react' +import ParamsOnSystemDb from './partials/params-on-systemdb' const title = 'Parameters' const subtitle = 'View and set parameters to be sent with queries.' const category = 'cypherQueries' @@ -64,11 +65,12 @@ const content = ( {` `} {`MATCH (n:Person) WHERE n.name = $name`}

+ diff --git a/src/browser/documentation/help/partials/params-on-systemdb.jsx b/src/browser/documentation/help/partials/params-on-systemdb.jsx new file mode 100644 index 00000000000..211f24eaff7 --- /dev/null +++ b/src/browser/documentation/help/partials/params-on-systemdb.jsx @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2002-2019 "Neo4j," + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +import React from 'react' +export default function ParamsOnSystemDb () { + return ( +

+ A note on system database +
+ If you are using a multi-database DBMS, parameters cannot be declared when + using the system database. Switch to a different database and declare, + then switch back to system database and use them. +

+ ) +} diff --git a/src/shared/modules/commands/helpers/params.js b/src/shared/modules/commands/helpers/params.js index 496a8450812..570fb49fd07 100644 --- a/src/shared/modules/commands/helpers/params.js +++ b/src/shared/modules/commands/helpers/params.js @@ -21,6 +21,7 @@ import jsonic from 'jsonic' import { splitStringOnFirst } from 'services/commandUtils' import { update, replace } from 'shared/modules/params/paramsDuck' import { collectLambdaValues, parseLambdaStatement } from './lambdas' +import { SYSTEM_DB } from 'shared/modules/dbMeta/dbMetaDuck' export const extractParams = param => { // early bail, now handled by parser @@ -77,7 +78,12 @@ export const getParamName = (input, cmdchar) => { return parts[0].trim() } -export const handleParamsCommand = (action, cmdchar, put) => { +export const handleParamsCommand = (action, cmdchar, put, targetDb) => { + if (targetDb === SYSTEM_DB) { + return Promise.reject( + new Error('Parameters cannot be declared when using system database.') + ) + } const strippedCmd = action.cmd.substr(cmdchar.length) const parts = splitStringOnFirst(strippedCmd, ' ') const param = parts[1].trim() diff --git a/src/shared/services/commandInterpreterHelper.js b/src/shared/services/commandInterpreterHelper.js index 92bd9ec513e..27ea911a326 100644 --- a/src/shared/services/commandInterpreterHelper.js +++ b/src/shared/services/commandInterpreterHelper.js @@ -131,7 +131,12 @@ const availableCommands = [ name: 'set-params', match: cmd => /^params?\s/.test(cmd), exec: function (action, cmdchar, put, store) { - return handleParamsCommand(action, cmdchar, put) + return handleParamsCommand( + action, + cmdchar, + put, + getUseDb(store.getState()) + ) .then(res => { const params = res.type === 'param' ? res.result : getParams(store.getState()) @@ -152,10 +157,11 @@ const availableCommands = [ if (!action.parentId) { put( frames.add({ + useDb: getUseDb(store.getState()), ...action, error: { type: 'Syntax Error', - message: error.message.substring('Error: '.length) + message: error.message.replace(/^Error: /, '') }, showHelpForCmd: getParamName(action, cmdchar), type: 'error'