neo4j delete nodey with children and without - graph

I have simple graph and i want to find category and delete it. If category has children, than delete category and all children. I've made deletion category with children with this command:
MATCH path = (c:Category)-[*]->(cc:Category)
WHERE c.id = "95bec604-5da2-4297-b792-5a866e292df4"
DETACH DELETE path
But this comamnd does not work for single node, without children. How i can achieve it?

Add a 0 as the lower bound for the variable-length pattern. By default it's 1, but when it's 0 (provided the label used for the end node is also on the start node) this will allow it to match even when there are no relationships from the start node.
MATCH path = (c:Category)-[*0..]->(cc:Category)
WHERE c.id = "95bec604-5da2-4297-b792-5a866e292df4"
DETACH DELETE path

In general, this approach would work if you want to delete the entire path:
MATCH path = ( some path )
FOREACH (node IN nodes(path) |
DETACH DELETE node
)

Related

How do I sort by names or postcodes using a drop-down list to determine what to sort by?

Currently, I am trying to create some software on Progress OpenEdge that sorts by customer's names or account codes.
So essentially, a box will open up when the program runs, the user will select "Name" from the drop-down list, and the program will display all the names in the database from alphabetical order.
Or, they will pick "Account" from the drop-down list, and it will display all the account codes in numeric order. I have attached a picture of the program here:
And this is currently the code I am using to print the results:
However, I'm not sure what I need to add for the others. Would I need IF statements, such as:
OR IF [drop down list] = "Account" THEN or something like that?
Any help would be appreciated.
While you can perform a static order by with a convulted set of if statements, it is a lot cleaner with a dynamic query.
To expand on Tom and Stefan's answers, you can use a query. The ABL lets you create a lot of things with static constructs and use them as dynamic. I think that in this case, you want to so something like the below.
Note that you can do build the query string either using OPEN QUERY qry FOR EACH ... or QUERY qry:QUERY-PREPARE('FOR EACH ... ') ; both will work equally well.
What I think you'd want is
(a) having a static definition of the query (ie DEFINE QUERY) since the cost of adding the buffer(s) to the query is done at compile time, not run time, and
(b) accessing the buffer fields statically (ie slmast.name rather than b::name )
define query qry for slmast.
define variable wc as character no-undo.
if condition eq true then
wc = "WHERE kco = s-kco AND warecode = lv-warecode AND pcode = fi-pcode AND name = fi-name BY name".
else
wc = "WHERE TRUE".
/* alternate
if condition then
open query qry for each slmast no-lock WHERE kco = s-kco AND warecode = lv-warecode AND pcode = fi-pcode AND name = fi-name BY name.
else
open query qry for each slmast no-lock.
*/
query qry:query-prepare(wc).
open query qry.
query qry:get-first().
do while available slmast:
/* do stuff with the buffer */
{&OUT} slmast.name.
query qry:get-next().
end.
query qry:query-close().
Using static constructs as far as possible means that you have less cleanup code to write and the code becomes more readable (IMO).
There are multiple ways to loop through the query results: using DO WHILE NOT QUERY qry:QUERY-OFF-END works as well as AVAILABLE slmast or b:AVAILABLE (if using a purely dynamic query).
As Stefan says, a dynamic query is what you want. This might help get you started:
define variable wc as character no-undo.
define variable q as handle no-undo.
define variable b as handle no-undo.
/* run your UI to get selection criteria amd then
* create a WHERE clause as appropriate
*/
wc = "WHERE kco = s-kco AND warecode = lv-warecode AND pcode = fi-pcode AND name = fi-name BY name".
create buffer b for table "slmast".
create query q.
q:set-buffers( b ).
q:query-prepare( substitute( "FOR EACH slmast NO-LOCK &1", wc )).
q:query-open().
do while q:get-next():
display
b:buffer-field( "name" ):buffer-value
b:buffer-field( "acode" ):buffer-value
b:buffer-field( "pcode" ):buffer-value
b:buffer-field( "trunmtd" ):buffer-value
b:buffer-field( "turnytd" ):buffer-value
.
end.

how to define Root member with PARENT_ID = NULL or PARENT_ID = ID for Parent/Child Dimenssion

I am getting an error
[BUILDER_UNEXPECTED_ERROR] Parent/Child View 'Dim_Parent_Child' without a single root member, at least one root member is mandatory. A Root member is defined with PARENT_ID = NULL or PARENT_ID = ID. location:
Please suggest me to how to define Root member with PARENT_ID = NULL or PARENT_ID = ID for Parent/Child Dimensions
One more thing, It is working fine with Full Load but raising error during incremental load.
The definition of this view (sorting Columns) is (ID, Parent).
I am using below table data as input to this "sort" view
ID,Name,Parent
0,Base,NULL
1,Customer Y,18
2,Funding Y,24
3,Credit Risk Sprd,22
4,Liquidity Sprd,24
5,Option Sprd,24
6,Funding Sprd,24
7,Custom Sprd,24
8,Early Termination Adjust,22
9,Risk Free Rate,19
18,Commercial ,22
19,Funding Center ,0
22,PC Contribution,0
23,Transfer Price PC,18
24,Transfer Price,19
25,Product Sprd,24
With incremental load this view does not work as it is not going to see all the rows: only new rows will are sent to the view and therefore the root will be missing.
Workaround: as it seems you're creating a dimension with this table (& view), you can set the incr. load strategy of this table to FULL_LOAD. Existing members won't be created.
Hope tha helps.

How to remove collection or edge document using for loop in ArangoDB?

I'm using the latest ArangoDB 3.1 on Windows 10.
Here I want to remove the collection document and edge document using the for loop. But I'm getting an error like document not found (vName).
vName contains the many collection names. But I dunno how to use it in for loop.
This is the AQL I am using to remove the documents from the graph:
LET op = (FOR v, e IN 1..1 ANY 'User/588751454' GRAPH 'my_graph'
COLLECT vid = v._id, eid = e._id
RETURN { vid, eid }
)
FOR doc IN op
COLLECT vName = SPLIT(doc.vid,'/')[0],
vid = SPLIT(doc.vid,'/')[1],
eName = SPLIT(doc.eid,'/')[0],
eid = SPLIT(doc.eid,'/')[1]
REMOVE { _key: vid } in vName
Return output im getting from the AQL (Web UI screenshot)
vName is a variable introduced by COLLECT. It is a string with the collection name of a vertex (extracted from vid / v._id). You then try to use it in the removal operation REMOVE { ... } IN vName.
AQL does not support dynamic collection names however, collection names must be known at query compile time:
Each REMOVE operation is restricted to a single collection, and the collection name must not be dynamic.
Source: https://docs.arangodb.com/3.2/AQL/Operations/Remove.html
So, you either have to hardcode the collection into the query, e.g. REMOVE { ... } IN User, or use the special bind parameter syntax for collections, e.g. REMOVE { ... } IN ##coll and bind parameters: {"#coll": "User", ...}.
This also means that REMOVE can only delete documents in a single collection.
It's possible to workaround the limitation somewhat by using subqueries like this:
LET x1 = (FOR doc IN User REMOVE aa IN User)
LET x2 = (FOR doc IN relations REMOVE bb IN relations)
RETURN 1
The variables x1 and x2 are syntactically required and receive an empty array as subquery result. The query also requires a RETURN statement, even if we don't expect any result.
Do not attempt to remove from the same collection twice in the same query though, as it would raise a access after data-modification error.

SORT CRITERIA not working properly

Running drupal 7.22, I need to add an option to sort to a view - Content type Lecture which is associated with Curses.
In the Curse page I need to display the Lecture in a certain order.
The Lecture are dispayed in the following way
print views_embed_view('lecture_list_of_online_courses','block', $node->nid);
I tried the following simple solution -
added field 'my_wight' to the lecture content type
added values from 1 to 10 according to the necessary order.
add SORT CRITERIA to the lecture_list_of_online_courses view
result: the view displayed in a sort that seems to have nothing to do with the values I added to 'my_wight'
I've been working with drupal many times before, and did this sort of things more than once.
I can get whats wrong with this.
here is the resulting SQL query from the View -
SELECT node_field_data_field_oc_forum_reference.nid AS node_field_data_field_oc_forum_reference_nid, node_field_data_field_oc_forum_reference.title AS node_field_data_field_oc_forum_reference_title, node_field_data_field_oc_forum_reference.language AS node_field_data_field_oc_forum_reference_language, node_field_data_field_oc_forum_reference.type AS node_field_data_field_oc_forum_reference_type, node_field_data_field_oc_forum_reference.comment AS node_field_data_field_oc_forum_reference_comment, field_data_field_lecture_weight.field_lecture_weight_value AS field_data_field_lecture_weight_field_lecture_weight_value, 'node' AS field_data_body_node_entity_type
FROM
{node} node
LEFT JOIN {field_data_field_oc_forum_reference} field_data_field_oc_forum_reference ON node.nid = field_data_field_oc_forum_reference.entity_id AND (field_data_field_oc_forum_reference.entity_type = 'node' AND field_data_field_oc_forum_reference.deleted = '0')
INNER JOIN {node} node_field_data_field_oc_forum_reference ON field_data_field_oc_forum_reference.field_oc_forum_reference_nid = node_field_data_field_oc_forum_reference.nid
LEFT JOIN {field_data_field_lecture_weight} field_data_field_lecture_weight ON node.nid = field_data_field_lecture_weight.entity_id AND (field_data_field_lecture_weight.entity_type = 'node' AND field_data_field_lecture_weight.deleted = '0')
WHERE (( (node.nid = '175' ) )AND(( (node.status = '1') AND (node.type IN ('online_courses')) )))
ORDER BY field_data_field_lecture_weight_field_lecture_weight_value DESC
I cannot run this query - any idea why?
First - for the SQL to work you must remove '{' and '}' from the query
Second - When creating the SORT CRITERIA, u need to chose 'Relationship' in the settings of the SORT CRITERIA

Previous/next navigation that uses ordering/sorting different than node id (n.nid)

I am trying to create "previous/next node" navigation on my nodes in order to show 2 previous and 2 following nodes in the term currently being viewed. Here is the code that displays 2 prev and 2 next nodes, but it is not taxonomy aware, i. e. it sorts nodes according to their IDs:
Prev/Next node navigation with a thumbnail in a full node
If I add a node in the term after some time, it will display this node as the last one, not as a "neighbour" of a node uploaded e.g. 3 months ago.
I have tried with "n.title", but it doesn't change anything. Ideally, it should order them either by titles or url aliases.
Thank you in advance!
it's not querying the taxonomy tables in the database query. You probably want to add a variable to the function as such dad_prev_next($current_node = NULL, $op = 'p', $tid) to pass it the term ID and then add that to your query through an inner join
SELECT n.nid, n.title
FROM {node} n
INNER JOIN {taxonomy_index} t
ON n.nid = t.nid
WHERE n.nid $sql_op :nid
AND t.tid = :tid
AND type IN ('photos')
AND status = 1
ORDER BY n.nid $order
LIMIT 1
I think that should be pretty close, then just pass that at the end of db_query db_query($sql, array(':nid' => $current_node -> nid, ':tid' => $tid));
Newer version of Previous/Next module has multiple options for sorting prev/next nodes. You can use the workaround to get thumbnails too:
http://drupal.org/project/prev_next
http://drupal.org/node/1790290

Resources