How to update directory from "/Collections/" to "/CollectionsCount/" in Marklogic
for $each in xdmp:directory("/collections/", "infinity")
return xdmp:node-uri($each)
result found:
/collections/Count2017-08-25.xml
/collections/Count2017-08-27.xml
/collections/Count2017-08-26.xml
/collections/Count2017-08-28.xml
I would like to update directory to become "/collectionsCount/" what function do I use. Thanks in advance.
/collectionsCount/Count2017-08-25.xml
/collectionsCount/Count2017-08-26.xml
....
Directories are a construct based on a document's URI, so in order to change the directories, you will need to delete the old documents and insert new ones at new URIs (using the new directory prefix in place of the old one).
for $each in xdmp:directory("/collections/", "infinity")
let $old-uri := $each/xdmp:node-uri(.)
let $permissions := xdmp:document-get-permissions($old-uri)
let $collections := xdmp:document-get-collections($old-uri)
let $quality := xdmp:document-get-quality($old-uri)
let $properties := xdmp:document-properties($old-uri)
let $new-uri := concat('/collectionsCount/', substring-after($old-uri, '/collections/'))
return (
xdmp:document-insert($new-uri, $each, $permissions, $collections, $quality),
xdmp:document-set-properties($new-uri, $properties),
xdmp:document-delete($old-uri))
Edit: Updated to include #hunterhacker's suggestion to propagate document metadata. Note that I intentionally left out assigning the new document to the old document's forest, since in most cases I assume it's better to let the database decide.
Related
I'm trying to use SQL IN clause kind of feature in dynamoDB. I tried using withFilterExpression but I'm not sure how to do it. I looked at similar questions as they were too old. Is there a better method to do this? This is the segment of code I have got. I have used a static List as example but it is actually dynamic.
def getQuestionItems(conceptCode : String) = {
val qIds = List("1","2","3")
val querySpec = new QuerySpec()
.withKeyConditionExpression("concept_id = :c_id")
.withFilterExpression("question_id in :qIds") // obviously wrong
.withValueMap(new ValueMap()
.withString(":c_id", conceptCode));
questionsTable.query(querySpec);
}
I need to pass qID list to fetch results similar to IN clause in SQL Query.
Please refer to this answer. Basically you need to form key list/value list dynamically
.withFilterExpression("question_id in (:qId1, :qId2, ... , :qIdN)")
.withValueMap(new ValueMap()
.withString(":qId1", ..) // just do this for each element in the list in a loop programmatically
....
.withString(":qIdN", ..)
);
Mind there is a restriction on maxItems in 'IN'
In eXist-db I have hundreds of documents in /db/apps/foo/resources/documents like so:
...
BNF9992-J305-1.xml
BNF9992-J305-5.xml
BNF9992-J308-9.xml
BNF9992-J310-8.xml
BNF9992-J311-1.xml
BNF9992-J312-6.xml
BNF9992-J312-7.xml
BNF9992-J315-9.xml
BNF9992-J316-2.xml
BNF9992-J317-2.xml
BNF9992-J319-3.xml
...
Imagine I want to present to the user a list of 3 documents appearing before and after a specific document (based on alpha-numeric sort). So, my 'current document' is BNF9992-J312-7.xml, and I want to show the user something like:
BNF9992-J310-8.xml
BNF9992-J311-1.xml
BNF9992-J312-6.xml
BNF9992-J312-7.xml (current document)
BNF9992-J315-9.xml
BNF9992-J316-2.xml
BNF9992-J317-2.xml
Is there a function/method in Xquery 3.1 for iterating up/down a list of documents once they've been retrieved. The most I've been able to do is a simple retrieval of document names from a collection:
for $resource in collection("/db/apps/foo/resources/documents")
let $uri := base-uri($resource)
return util:unescape-uri(replace($uri, ".+/(.+)$","$1"), "UTF-8")
But I don't know how to iterate up and down the list from a given document.
Perhaps writing the list into nodes and applying a formula to node ordinals?
Many thanks.
If this were a list of strings $list, and the "current string" is $s, then I would do
let $i := index-of($list, $s)
return subsequence($list, $i - 3, 7)
I'm not sure whether the fact that you have a list of documents (rather than strings) changes this.
This is the xml file.
<?xml version="1.0" encoding="UTF-8"?>
<root>
<AtcoCode> System-Start-Date= 2018-05-16T12:35:48.6929328-04:00, " ", System-End-Date = 9999-12-31, " ", 150042010003</AtcoCode>
<NaptanCode>esxatgjd</NaptanCode>
<PlateCode>
</PlateCode>
<CleardownCode>
</CleardownCode>
<CommonName>Upper Park</CommonName>
<CommonNameLang>
</CommonNameLang>
<ShortCommonName>
</ShortCommonName>
<ShortCommonNameLang>
</ShortCommonNameLang>
<Landmark>Upper Park</Landmark>
<LandmarkLang>
</LandmarkLang>
<Street>High Road</Street>
<StreetLang>
</StreetLang>
<Crossing>
</Crossing>
<CrossingLang>
</CrossingLang>
<Indicator>adj</Indicator>
<IndicatorLang>
</IndicatorLang>
<Bearing>NE</Bearing>
<NptgLocalityCode>E0046286</NptgLocalityCode>
<LocalityName>Loughton</LocalityName>
<ParentLocalityName>
</ParentLocalityName>
<GrandParentLocalityName>
</GrandParentLocalityName>
<Town>Loughton</Town>
<TownLang>
</TownLang>
<Suburb>
</Suburb>
<SuburbLang>
</SuburbLang>
<LocalityCentre>1</LocalityCentre>
<GridType>U</GridType>
<Easting>541906</Easting>
<Northing>195737</Northing>
<Co-ordinates>51.64255,0.04944</Co-ordinates>
<StopType>BCT</StopType>
<BusStopType>MKD</BusStopType>
<TimingStatus>OTH</TimingStatus>
<DefaultWaitTime>
</DefaultWaitTime>
<Notes>
</Notes>
<NotesLang>
</NotesLang>
<AdministrativeAreaCode>080</AdministrativeAreaCode>
<CreationDateTime>2006-11-06T00:00:00</CreationDateTime>
<ModificationDateTime>2010-01-16T07:58:02</ModificationDateTime>
<RevisionNumber>5</RevisionNumber>
<Modification>rev</Modification>
<Status>act</Status>
</root>
How to achieve this?
Question: Create the path range index for the status element and fetch all the documents that has status del
after fetching all the documents, you need to create the new element called currentreservationnumber under RevisionNumber element.
The value of the currentrevisionnumber will be +1 to the RevisionNumber.
I think the warning about sequential numbers is related to system-wide unique numbers/ids (like Oracle sequence), so not a worry in this case?
If you only ever have one RevisionNumber, and you can find it without a path index, you can maybe get by with element-value query on the RevisionNumber since it's already indexed.
Given that you get the document somehow, it could be as simple as:
let $doc := fn:doc ('/foo.xml')
let $rev-node := $doc/root/RevisionNumber
return xdmp:node-insert-after ($rev-node, <currentreservationnumber>{$rev-node + 1}</currentreservationnumber>)
though remember to consider locking if you are doing a big query/update. And you might need to switch to node-replace if there is already a currentreservationnumber.
I need to isolate the file extension from a path in SQLite. I've read the post here (SQLite: How to select part of string?), which gets 99% there.
However, the solution:
select distinct replace(column_name, rtrim(column_name, replace(column_name, '.', '' ) ), '') from table_name;
fails if a file has no extension (i.e. no '.' in the filename), for which it should return an empty string. Is there any way to trap this please?
Note the filename in this context is the bit after the final '\'- it shouldn't be searching for'.'s in the full path, as it does at moment too.
I think it should be possible to do it using further nested rtrims and replaces.
Thanks. Yes, you can do it like this:
1) create a scalar function called "extension" in QtScript in SQLiteStudio
2) The code is as follows:
if ( arguments[0].substring(arguments[0].lastIndexOf('\u005C')).lastIndexOf('.') == -1 )
{
return ("");
}
else
{
return arguments[0].substring(arguments[0].lastIndexOf('.'));
}
3) Then, in the SQL query editor you can use
select distinct extension(PATH) from DATA
... to itemise the distinct file extensions from the column called PATH in the table called DATA.
Note that the PATH field must contain a backslash ('\') in this implementation - i.e. it must be a full path.
I am getting nil value when I tried to update the data for below code :
local update_statement =db:prepare[[ UPDATE list SET :name :icon WHERE :id]]
update_statement:bind_names{ name = aName, icon = aIcon, id = aId }
update_statement:step()
update_statement:reset()
And also I need the syntax for delete operation in lua program.
Please help me
Thank you,
Madan mohan.
You need to learn SQL's syntax.
Basically, you're not telling which columns you want to update, you're only giving their values.
local update_statement = db:prepare[[ UPDATE list SET name = :name, icon = :icon WHERE id = :id]]
Here's the syntax for the DELETE statement:
local delete_statement = db:prepare[[ DELETE FROM list WHERE id = :id]]