Skip to content

Commit

Permalink
Error message when declaring params on system db
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarhane authored and Neo Technology Build Agent committed Dec 4, 2019
1 parent 9b13ccf commit 75c8cc0
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
9 changes: 9 additions & 0 deletions e2e_tests/integration/multi-db.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
}
})
2 changes: 2 additions & 0 deletions src/browser/documentation/help/param.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -46,6 +47,7 @@ const content = (
Cypher query example with a param:
<code>MATCH (n:Person) WHERE n.name = $name</code>
</p>
<ParamsOnSystemDb />
<div className='links'>
<div className='link'>
<p className='title'>Related</p>
Expand Down
4 changes: 3 additions & 1 deletion src/browser/documentation/help/params.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -64,11 +65,12 @@ const content = (
{` `}
<code>{`MATCH (n:Person) WHERE n.name = $name`}</code>
</p>
<ParamsOnSystemDb />
<div className='links'>
<div className='link'>
<p className='title'>Related</p>
<p className='content'>
<a help-topic='params'>:help params</a>
<a help-topic='param'>:help param</a>
</p>
</div>
</div>
Expand Down
31 changes: 31 additions & 0 deletions src/browser/documentation/help/partials/params-on-systemdb.jsx
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
import React from 'react'
export default function ParamsOnSystemDb () {
return (
<p>
<strong>A note on system database</strong>
<br />
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.
</p>
)
}
8 changes: 7 additions & 1 deletion src/shared/modules/commands/helpers/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 8 additions & 2 deletions src/shared/services/commandInterpreterHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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'
Expand Down

0 comments on commit 75c8cc0

Please sign in to comment.