Prev |  | Next

## 16.1. Parameters

Cypher supports querying with parameters. This allows developers to not to have to do string building to create a query, and it also makes caching of execution plans much easier for Cypher.

Parameters can be used for literals in the `WHERE` clause, for the index key and index value in the `START` clause, index queries, and finally for node/relationship ids.

Accepted names for parameter are letters and number, and any combination of these.

Here follows a few examples of how you can use parameters from Java.

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "id", 0 );
    ExecutionResult result = engine.execute( "start n=node({id}) return n.name", params );

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "id", 0 );
    ExecutionResult result = engine.execute( "start n=node({id}) return n.name", params );
    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "node", andreasNode );
    ExecutionResult result = engine.execute( "start n=node({node}) return n.name", params );

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "id", Arrays.asList( 0, 1, 2 ) );
    ExecutionResult result = engine.execute( "start n=node({id}) return n.name", params );

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "name", "Johan" );
    ExecutionResult result = engine.execute( "start n=node(0,1,2) where n.name = {name} return n", params );

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "key", "name" );
    params.put( "value", "Michaela" );
    ExecutionResult result = engine.execute( "start n=node:people({key} = {value}) return n", params );

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "query", "name:Andreas" );
    ExecutionResult result = engine.execute( "start n=node:people({query}) return n", params );

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "s", 1 );
    params.put( "l", 1 );
    ExecutionResult result = engine.execute( "start n=node(0,1,2) return n.name skip {s} limit {l}", params );

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "regex", ".*h.*" );
    ExecutionResult result = engine.execute( "start n=node(0,1,2) where n.name =~ {regex} return n.name", params );

Copyright © 2011 Neo Technology

Prev | Up | Next
| Home |