Difference between revisions of "Commands"

From BaseX Documentation
Jump to navigation Jump to search
Line 23: Line 23:
 
Both database and user names must follow the same naming constraints. Valid names may contain letters, numbers, underscores and dashes. Names must have at least one character; they also should not be longer than 128 characters, although this is not enforced. A regular expression matching valid names is <code>[-_a-zA-Z0-9]{1,128}</code>.
 
Both database and user names must follow the same naming constraints. Valid names may contain letters, numbers, underscores and dashes. Names must have at least one character; they also should not be longer than 128 characters, although this is not enforced. A regular expression matching valid names is <code>[-_a-zA-Z0-9]{1,128}</code>.
  
=Commands=
+
=Database Operations=
  
==ADD==
+
==CREATE DATABASE==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>ADD (TO [path]) [input]</code>
+
|<code>CREATE DATABASE [name] ([input])</code>
|-
 
| valign='top' | '''Permission'''
 
|''WRITE''
 
|-
 
| valign='top' | '''Summary'''
 
|Adds the files, directory or XML string specified by <code>[input]</code> to the currently opened database at the specified <code>[path]</code>.<br/><code>[input]</code> may either be a single XML document, a directory, a remote URL or a plain XML string. If the path denotes a directory, it needs to be suffixed with a slash (<code>/</code>).
 
|-
 
| valign='top' | '''Errors'''
 
|The command fails if no database is opened, if one of the documents to be added is not well-formed, or if it could not be parsed for some other reason.
 
|-
 
| valign='top' | '''Examples'''
 
|
 
* <code>ADD input.xml</code><br/>adds the file <code>input.xml</code> to the database.
 
* <code>ADD TO temp/one.xml input.xml</code><br/>adds <code>input.xml</code> to the database and moves it to <code>temp/one.xml</code>.
 
* <code>ADD TO target/ xmldir</code><br/>adds all files from the <code>xmldir</code> directory to the database in the <code>target</code> path.
 
|}
 
 
 
==ALTER DATABASE==
 
{|
 
|-
 
| valign='top' width='90' | '''Signature'''
 
|<code>ALTER DATABASE [name] [newname]</code>
 
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
Line 57: Line 35:
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Renames the database specified by <code>[name]</code> to <code>[newname]</code>. <code>[newname]</code> must be a [[Valid Names|valid database name]].
+
|Creates the database <code>[name]</code> with an optional <code>[input]</code>.<br />The input may either be a single XML document, a directory, a remote URL or a plain XML string. <code>[name]</code> must be a [[Valid Names|valid database name]].
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if the target database already exists, if the source database does not exist or is currently locked, or if it could not be renamed for some other reason.
+
|The command fails if a database with the specified name is currently used by another process, or if one of the documents to be added is not well-formed or could not be parsed for some other reason.
 
|-
 
|-
 
| valign='top' | '''Examples'''
 
| valign='top' | '''Examples'''
 
|
 
|
* <code>ALTER DATABASE db tempdb</code><br/>renames the database <code>db</code> into <code>tempdb</code>.
+
* <code>CREATE DATABASE input</code><br/>creates an empty database <code>input</code>.
 +
* <code>CREATE DATABASE xmark http://files.basex.org/xml/xmark.xml</code><br/>creates the database <code>input</code> with the remote file xmark.xml as initial content.
 +
* <code>CREATE DATABASE coll /path/to/input</code><br/>creates the database <code>coll</code> with all documents from the <code>input</code> directory as initial content.
 +
* <code>SET INTPARSE false;CREATE DB input input.xml</code><br/>creates a database <code>input</code>, using Java's [[Parsers#XML Parsers|default XML parser]].
 
|}
 
|}
  
==ALTER USER==
+
==OPEN==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>ALTER USER [name] ([password])</code>
+
|<code>OPEN [path]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''ADMIN''
+
|''READ''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Alters the <code>[password]</code> of the user specified by <code>[name]</code>. The password must be a valid MD5 hash value. If no password is specified in the console mode, it is requested via standard input.
+
|Opens the documents in a database. <code>[path]</code> is the name of the database, optionally followed by a path to the requested documents.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if the specified user does not exist, or if the password is no valid MD5 hash value.
+
|The command fails if the specified database cannot be opened for some unknown reason.
 
|}
 
|}
  
Line 115: Line 96:
 
|}
 
|}
  
==COPY==
+
==EXPORT==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>COPY [name] [newname]</code>
+
|<code>EXPORT [path]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
Line 125: Line 106:
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Creates a copy of the database specified by <code>[name]</code>. <code>[newname]</code> must be a [[Valid Names|valid database name]].
+
|Exports all documents in the database to the specified <code>[path]</code>, using the serializer options specified by the <code>[[Options#EXPORTER|EXPORTER]]</code> option.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if the target database already exists, or if the source database does not exist.
+
|The command fails if no database is opened, if the target path points to a file or is invalid, if the serialization parameters are invalid, or if the documents cannot be serialized for some other reason.
|}
 
==CREATE BACKUP==
 
{|
 
|-
 
| valign='top' width='90' | '''Signature'''
 
|<code>CREATE BACKUP [name]</code>
 
|-
 
| valign='top' | '''Permission'''
 
|''CREATE''
 
|-
 
| valign='top' | '''Summary'''
 
|Creates a zipped backup of the database specified by {{Mono|[name]}}. The backup file will be suffixed with the current timestamp and stored in the database directory. The Glob syntax can be used to address more than one database.
 
|-
 
| valign='top' | '''Errors'''
 
|The command fails if the specified database does not exist, or if it could not be zipped for some other reason.
 
|-
 
| valign='top' | '''Examples'''
 
|
 
* <code>BACKUP db</code><br/>creates a zip archive of the database <code>db</code> (e.g. <code>db-2011-04-01-12-27-28.zip</code>) in your [[Configuration#Database_Directory|database directory]].
 
 
|}
 
|}
  
==CREATE DATABASE==
+
==CREATE INDEX==
 +
 
 +
{{Mark|Updated in Version 7.2:}} {{Mono|PATH}} removed as argument; path summary is now updated by [[#OPTIMIZE|OPTIMIZE]] command
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>CREATE DATABASE [name] ([input])</code>
+
|<code>CREATE INDEX [TEXT&#124;ATTRIBUTE&#124;FULLTEXT]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''CREATE''
+
|''WRITE''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Creates the database <code>[name]</code> with an optional <code>[input]</code>.<br />The input may either be a single XML document, a directory, a remote URL or a plain XML string. <code>[name]</code> must be a [[Valid Names|valid database name]].
+
|Creates the specified database [[Indexes|index]].
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if a database with the specified name is currently used by another process, or if one of the documents to be added is not well-formed or could not be parsed for some other reason.
+
|The command fails if no database is opened, if the specified index is unknown, or if indexing fails for some other reason.
|-
 
| valign='top' | '''Examples'''
 
|
 
* <code>CREATE DATABASE input</code><br/>creates an empty database <code>input</code>.
 
* <code>CREATE DATABASE xmark http://files.basex.org/xml/xmark.xml</code><br/>creates the database <code>input</code> with the remote file xmark.xml as initial content.
 
* <code>CREATE DATABASE coll /path/to/input</code><br/>creates the database <code>coll</code> with all documents from the <code>input</code> directory as initial content.
 
* <code>SET INTPARSE false;CREATE DB input input.xml</code><br/>creates a database <code>input</code>, using Java's [[Parsers#XML Parsers|default XML parser]].
 
 
|}
 
|}
  
==CREATE INDEX==
+
==DROP INDEX==
  
{{Mark|Updated in Version 7.2:}} {{Mono|PATH}} removed as argument; path summary is now updated by [[#OPTIMIZE|OPTIMIZE]] command
+
{{Mark|Updated in Version 7.2:}} {{Mono|PATH}} removed as argument; path summary is now always available
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>CREATE INDEX [TEXT&#124;ATTRIBUTE&#124;FULLTEXT]</code>
+
|<code>DROP INDEX [TEXT&#124;ATTRIBUTE&#124;FULLTEXT]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
Line 185: Line 142:
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Creates the specified database [[Indexes|index]].
+
|Drops the specified database [[Indexes|index]].
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if no database is opened, if the specified index is unknown, or if indexing fails for some other reason.
+
|The command fails if no database is opened, if the specified index is unknown, or if it could not be deleted for some other reason.
 
|}
 
|}
  
==CREATE EVENT==
+
=Administration=
 +
 
 +
==ALTER DATABASE==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>CREATE EVENT [NAME]</code>
+
|<code>ALTER DATABASE [name] [newname]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''ADMIN''
+
|''CREATE''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Creates the specified [[Events|event]].
+
|Renames the database specified by <code>[name]</code> to <code>[newname]</code>. <code>[newname]</code> must be a [[Valid Names|valid database name]].
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if event already exists.
+
|The command fails if the target database already exists, if the source database does not exist or is currently locked, or if it could not be renamed for some other reason.
 +
|-
 +
| valign='top' | '''Examples'''
 +
|
 +
* <code>ALTER DATABASE db tempdb</code><br/>renames the database <code>db</code> into <code>tempdb</code>.
 
|}
 
|}
  
==CREATE USER==
+
==DROP DATABASE==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>CREATE USER [name] ([password])</code>
+
|<code>DROP DATABASE [name]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''ADMIN''
+
|''CREATE''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Creates a user with the specified <code>[name]</code> and <code>[password]</code>. <code>[name]</code> must be a [[Valid Names|valid user name]]. The password must be a valid MD5 hash value. If no password is specified in the console mode, it is requested via standard input.
+
|Drops the database with the specified <code>[name]</code>. The Glob syntax can be used to address more than one database.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if the specified user already exists, or if the password is no valid MD5 hash value.
+
|The command fails if the specified database does not exist or is currently locked, or if the database could not be deleted for some other reason.
 
|}
 
|}
  
==CS==
+
==CREATE BACKUP==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>CS [query]</code>
+
|<code>CREATE BACKUP [name]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''depends on query''
+
|''CREATE''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Evaluates the specified <code>[query]</code> and sets the result as new context set.
+
|Creates a zipped backup of the database specified by {{Mono|[name]}}. The backup file will be suffixed with the current timestamp and stored in the database directory. The Glob syntax can be used to address more than one database.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if no database is opened, if the specified query is invalid or if it does not return nodes of the currently opened database.
+
|The command fails if the specified database does not exist, or if it could not be zipped for some other reason.
 +
|-
 +
| valign='top' | '''Examples'''
 +
|
 +
* <code>BACKUP db</code><br/>creates a zip archive of the database <code>db</code> (e.g. <code>db-2011-04-01-12-27-28.zip</code>) in your [[Configuration#Database_Directory|database directory]].
 
|}
 
|}
==DELETE==
+
 
 +
==RESTORE==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>DELETE [path]</code>
+
|<code>RESTORE [name]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''WRITE''
+
|''CREATE''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Deletes all documents from the currently opened database that start with the specified <code>[path]</code>.
+
|Restores a database with the specified <code>[name]</code>. The name may include the timestamp of the backup file.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if no database is opened.
+
|The command fails if the specified backup does not exist, if the database to be restored is currently locked, or if it could not be restored for some other reason.
 
|}
 
|}
 +
 
==DROP BACKUP==
 
==DROP BACKUP==
 
{|
 
{|
Line 270: Line 239:
 
|}
 
|}
  
==DROP DATABASE==
+
==COPY==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>DROP DATABASE [name]</code>
+
|<code>COPY [name] [newname]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
Line 280: Line 249:
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Drops the database with the specified <code>[name]</code>. The Glob syntax can be used to address more than one database.
+
|Creates a copy of the database specified by <code>[name]</code>. <code>[newname]</code> must be a [[Valid Names|valid database name]].
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if the specified database does not exist or is currently locked, or if the database could not be deleted for some other reason.
+
|The command fails if the target database already exists, or if the source database does not exist.
 
|}
 
|}
  
==DROP EVENT==
+
==INFO DATABASE==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>DROP EVENT [NAME]</code>
+
|<code>INFO DATABASE</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''ADMIN''
+
|''READ''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Drops the specified [[Events|event]].
+
|Shows information on the currently opened database.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if the event doesn't exist.
+
|The command fails if no database is opened.
 
|}
 
|}
  
==DROP INDEX==
+
==INFO INDEX==
 
 
{{Mark|Updated in Version 7.2:}} {{Mono|PATH}} removed as argument; path summary is now always available
 
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>DROP INDEX [TEXT&#124;ATTRIBUTE&#124;FULLTEXT]</code>
+
|<code>INFO INDEX ([TEXT&#124;ATTRIBUTE&#124;FULLTEXT&#124;PATH])</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''WRITE''
+
|''READ''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Drops the specified database [[Indexes|index]].
+
|Shows information on the existing [[Indexes|index]] structures. The output can be optionally limited to the specified index.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if no database is opened, if the specified index is unknown, or if it could not be deleted for some other reason.
+
|The command fails if no database is opened, or if the specified index is unknown.
 
|}
 
|}
  
==DROP USER==
+
==INFO STORAGE==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>DROP USER [name] (ON [database])</code>:
+
| <code>INFO STORAGE [start end] &#124; [query]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''ADMIN''
+
|''READ''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Drops the user with the specified <code>[name]</code>. If a <code>[database]</code> is specified, the user is only dropped locally. The Glob syntax can be used to address more than one database or user.
+
|Shows the internal main table of the currently opened database. An integer range or a query may be specified as argument.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if <code>admin</code> is specified as user name, if the specified user does not exist or is logged in, or if the optional database could not be opened for modification.
+
|The command fails if no database is opened, or if one of the specified arguments is invalid.
 
|}
 
|}
==EXIT==
+
 
 +
= Querying =
 +
 
 +
==LIST==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>EXIT </code>
+
|<code>LIST ([path])</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
Line 345: Line 315:
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Exits the console mode.
+
|Lists all available databases, or the documents in a database. <code>[path]</code> is the name of the database, optionally followed by a path to the requested documents.
 +
|-
 +
| valign='top' | '''Errors'''
 +
|The command fails if the optional database cannot be opened, or if the existing databases cannot be listed for some other reason.
 
|}
 
|}
==EXPORT==
+
 
 +
==XQUERY==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>EXPORT [path]</code>
+
|<code>XQUERY [query]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''CREATE''
+
|''depends on query''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Exports all documents in the database to the specified <code>[path]</code>, using the serializer options specified by the <code>[[Options#EXPORTER|EXPORTER]]</code> option.
+
|Runs the specified <code>[query]</code> and prints the result.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if no database is opened, if the target path points to a file or is invalid, if the serialization parameters are invalid, or if the documents cannot be serialized for some other reason.
+
|The command fails if the specified query is invalid.
 +
|-
 +
| valign='top' | '''Examples'''
 +
|
 +
* <code>XQUERY 1 to 10</code><br/>returns the sequence <code>(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)</code>.
 +
* <code>SET RUNS 10;XQUERY 1 to 10</code><br/>runs the query 10 times, returns the result and prints the average execution time.
 +
* <code>SET XMLPLAN true;XQUERY 1 to 10</code><br/>returns the result and prints the query plan as XML.
 
|}
 
|}
  
==FIND==
+
==RETRIEVE==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>FIND [keywords]</code>
+
|<code>RETRIEVE [path] [input]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
Line 373: Line 353:
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Builds and runs a query for the specified <code>[keywords]</code>. Keywords can be enclosed in quotes to look for phrases. The following modifiers can be used to further limit search:
+
|Retrieves raw data from the specified database <code>[path]</code>.
<code>= </code> looks for exact text nodes<br/><code>~ </code> looks for approximate hits<br/><code>@=</code> looks for exact attribute values<br/><code>@ </code> looks for attributes
 
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if no database is opened.
+
|The command fails if no database is opened, if the source path is invalid or if the data cannot not be retrieved for some other reason.
 
|}
 
|}
  
==FLUSH==
+
==RUN==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>FLUSH</code>
+
|<code>RUN [file]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''WRITE''
+
|''depends on query''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Explicitly flushes the buffers of the currently opened database to disk. This command is applied if the [[Options#AUTOFLUSH|AUTOFLUSH]] option has been set to false.
+
|Runs the query contained in <code>[file]</code> and prints the result.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if no database is opened.
+
|The command fails if the specified file does not exist, or if the retrieved query is invalid.
 
|}
 
|}
  
==GET==
+
==FIND==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>GET [option]</code>
+
|<code>FIND [keywords]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
Line 406: Line 385:
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Returns the current value of the [[Options|Option]] specified via {{Mono|[key]}}.
+
|Builds and runs a query for the specified <code>[keywords]</code>. Keywords can be enclosed in quotes to look for phrases. The following modifiers can be used to further limit search:
 +
<code>= </code> looks for exact text nodes<br/><code>~ </code> looks for approximate hits<br/><code>@=</code> looks for exact attribute values<br/><code>@ </code> looks for attributes
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if the specified option is unknown.
+
|The command fails if no database is opened.
 
|}
 
|}
  
==GRANT==
+
==CS==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>GRANT [NONE&#124;READ&#124;WRITE&#124;CREATE&#124;ADMIN] (ON [database]) TO [user]</code>
+
|<code>CS [query]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''ADMIN''
+
|''depends on query''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Grants the specified [[User_Management|permission]] to the specified <code>[user]</code>. If a <code>[database]</code> is specified, the permissions are only granted locally. The Glob syntax can be used to address more than one database or user.
+
|Evaluates the specified <code>[query]</code> and sets the result as new context set.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if <code>admin</code> is specified as user name, if the specified user does not exist, or if the optional database could not be opened for modification.
+
|The command fails if no database is opened, if the specified query is invalid or if it does not return nodes of the currently opened database.
|-
 
| valign='top' | '''Examples'''
 
|
 
* <code>GRANT READ TO JoeWinson</code><br/>grants <code>READ</code> permission to the user <code>JoeWinson</code>.
 
* <code>GRANT WRITE ON Wiki TO editor*</code><br/>grants <code>WRITE</code> permissions on the <code>Wiki</code> database to all users starting with the characters <code>editor*</code>.
 
 
|}
 
|}
  
==HELP==
+
==REPO INSTALL==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>HELP ([command])</code>
+
|<code>REPO INSTALL [path]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''NONE''
+
|''CREATE'' ({{Mark|before Version 7.2}}: ''ADMIN'')
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|If <code>[command]</code> is specified, information on the specific command is printed; otherwise, all commands are listed.
+
| Installs the package with path <code>[path]</code>.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if the specified command is unknown.
+
| The command fails in the following cases:
 +
* The package to be installed is not a xar file.
 +
* The package to be installed does not exist or is already installed.
 +
* The package descriptor is with invalid syntax.
 +
* The package to be installed depends on a package which is not installed.
 +
* The package is not supported by the current version of BaseX.
 +
* A component of the package is already installed as part of another package.
 
|}
 
|}
==INFO==
+
 
 +
==REPO LIST==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>INFO</code>
+
|<code>REPO LIST</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''READ''
+
|''READ'' ({{Mark|before Version 7.2}}: ''ADMIN'')
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Shows global information.
+
| Lists all installed packages.
 
|}
 
|}
==INFO DATABASE==
+
 
 +
==REPO DELETE==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>INFO DATABASE</code>
+
|<code>REPO DELETE [name&#124;dir]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''READ''
+
|''CREATE'' ({{Mark|before Version 7.2}}: ''ADMIN'')
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Shows information on the currently opened database.
+
| Deletes the package with name <code>[name]</code> or with directory <code>[dir]</code>.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if no database is opened.
+
| The command fails if the package to be deleted participates in a dependency.
 
|}
 
|}
==INFO INDEX==
+
 
 +
=Updates=
 +
 
 +
==ADD==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>INFO INDEX ([TEXT&#124;ATTRIBUTE&#124;FULLTEXT&#124;PATH])</code>
+
|<code>ADD (TO [path]) [input]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''READ''
+
|''WRITE''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Shows information on the existing [[Indexes|index]] structures. The output can be optionally limited to the specified index.
+
|Adds the files, directory or XML string specified by <code>[input]</code> to the currently opened database at the specified <code>[path]</code>.<br/><code>[input]</code> may either be a single XML document, a directory, a remote URL or a plain XML string. If the path denotes a directory, it needs to be suffixed with a slash (<code>/</code>).
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if no database is opened, or if the specified index is unknown.
+
|The command fails if no database is opened, if one of the documents to be added is not well-formed, or if it could not be parsed for some other reason.
 +
|-
 +
| valign='top' | '''Examples'''
 +
|
 +
* <code>ADD input.xml</code><br/>adds the file <code>input.xml</code> to the database.
 +
* <code>ADD TO temp/one.xml input.xml</code><br/>adds <code>input.xml</code> to the database and moves it to <code>temp/one.xml</code>.
 +
* <code>ADD TO target/ xmldir</code><br/>adds all files from the <code>xmldir</code> directory to the database in the <code>target</code> path.
 
|}
 
|}
  
==INFO STORAGE==
+
==DELETE==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
| <code>INFO STORAGE [start end] &#124; [query]</code>
+
|<code>DELETE [path]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''READ''
+
|''WRITE''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Shows the internal main table of the currently opened database. An integer range or a query may be specified as argument.
+
|Deletes all documents from the currently opened database that start with the specified <code>[path]</code>.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if no database is opened, or if one of the specified arguments is invalid.
+
|The command fails if no database is opened.
 
|}
 
|}
==KILL==
+
 
 +
==RENAME==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>KILL [target]</code>
+
|<code>RENAME [path] [newpath]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''ADMIN''
+
|''WRITE''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Kills sessions of a user or an IP:port combination, specified by <code>[target]</code>. The Glob syntax can be used to address more than one user.
+
|Renames all document paths in the currently opened database that start with the specified <code>[path]</code>. The command may be used to either rename single documents or directories.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if a user tried to kill his/her own session.
+
|The command fails if no database is opened, or if the target path is empty.
 +
|-
 +
| valign='top' | '''Examples'''
 +
|
 +
* <code>RENAME one.xml two.xml</code><br/>renames the document <code>one.xml</code> to <code>two.xml</code>.
 +
* <code>RENAME / TOP</code><br/>moves all documents to a <code>TOP</code> root directory.
 
|}
 
|}
  
==LIST==
+
==REPLACE==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>LIST ([path])</code>
+
|<code>REPLACE [path] [input]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''NONE''
+
|''WRITE''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Lists all available databases, or the documents in a database. <code>[path]</code> is the name of the database, optionally followed by a path to the requested documents.
+
|Replaces the documents in the currently opened database, addressed by <code>[path]</code>, with the file or XML string specified by <code>[input]</code>. The original file name and path is preserved by the operation.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if the optional database cannot be opened, or if the existing databases cannot be listed for some other reason.
+
|The command fails if no database is opened, if the specified path points to a database directory, or if the input is not found.
 +
|-
 +
| valign='top' | '''Examples'''
 +
|
 +
* <code>REPLACE one.xml input.xml</code><br/>replaces the document <code>one.xml</code> with the contents of the file <code>input.xml</code>.
 +
* <code>REPLACE top.xml &lt;xml/&gt;</code><br/>replaces the document <code>top.xml</code> with the document <code>&lt;xml/&gt;</code>.
 
|}
 
|}
==OPEN==
+
 
 +
==STORE==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>OPEN [path]</code>
+
|<code>STORE (TO [path]) [input]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''READ''
+
|''WRITE''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Opens the documents in a database. <code>[path]</code> is the name of the database, optionally followed by a path to the requested documents.
+
|Stores raw data to the specified <code>[path]</code>. <code>[input]</code> may either be a file reference, a remote URL, or a plain string. If the path denotes a directory, it needs to be suffixed with a slash (<code>/</code>).
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if the specified database cannot be opened for some unknown reason.
+
|The command fails if no database is opened, if the specified resource is not found, if the target path is invalid or if the data cannot not be written for some other reason.
 
|}
 
|}
 +
 
==OPTIMIZE==
 
==OPTIMIZE==
 
{|
 
{|
Line 568: Line 573:
 
|}
 
|}
  
==PASSWORD==
+
==FLUSH==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>PASSWORD ([password])</code>
+
|<code>FLUSH</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''NONE''
+
|''WRITE''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Changes the <code>[password]</code> of the current user. The password must be a valid MD5 hash value. If no password is specified in the console mode, it is requested via standard input.
+
|Explicitly flushes the buffers of the currently opened database to disk. This command is applied if the [[Options#AUTOFLUSH|AUTOFLUSH]] option has been set to false.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if the password is no valid MD5 hash value.
+
|The command fails if no database is opened.
 +
|}
 +
 
 +
=Server Administration=
 +
 
 +
==SHOW BACKUPS==
 +
{|
 +
|-
 +
| valign='top' width='90' | '''Signature'''
 +
|<code>SHOW BACKUPS</code>
 +
|-
 +
| valign='top' | '''Permission'''
 +
|''CREATE''
 +
|-
 +
| valign='top' | '''Summary'''
 +
|Shows all database backups.
 
|}
 
|}
  
==RENAME==
+
==SHOW DATABASES==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>RENAME [path] [newpath]</code>
+
|<code>SHOW DATABASES</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''WRITE''
+
|''ADMIN''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Renames all document paths in the currently opened database that start with the specified <code>[path]</code>. The command may be used to either rename single documents or directories.
+
|Shows all databases that are opened in the current server instance.
 +
|}
 +
 
 +
==SHOW SESSIONS==
 +
{|
 +
|-
 +
| valign='top' width='90' | '''Signature'''
 +
|<code>SHOW SESSIONS</code>
 
|-
 
|-
| valign='top' | '''Errors'''
+
| valign='top' | '''Permission'''
|The command fails if no database is opened, or if the target path is empty.
+
|''ADMIN''
 
|-
 
|-
| valign='top' | '''Examples'''
+
| valign='top' | '''Summary'''
|
+
|Shows all sessions that are connected to the current server instance.
* <code>RENAME one.xml two.xml</code><br/>renames the document <code>one.xml</code> to <code>two.xml</code>.
 
* <code>RENAME / TOP</code><br/>moves all documents to a <code>TOP</code> root directory.
 
 
|}
 
|}
  
==REPLACE==
+
==SHOW USERS==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>REPLACE [path] [input]</code>
+
|<code>SHOW USERS (ON [database])</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''WRITE''
+
|''ADMIN''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Replaces the documents in the currently opened database, addressed by <code>[path]</code>, with the file or XML string specified by <code>[input]</code>. The original file name and path is preserved by the operation.
+
|Shows all users that are registered in the database. If a <code>[database]</code> is specified, local users are shown.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if no database is opened, if the specified path points to a database directory, or if the input is not found.
+
|The command fails if the optional database could not be opened.
|-
 
| valign='top' | '''Examples'''
 
|
 
* <code>REPLACE one.xml input.xml</code><br/>replaces the document <code>one.xml</code> with the contents of the file <code>input.xml</code>.
 
* <code>REPLACE top.xml &lt;xml/&gt;</code><br/>replaces the document <code>top.xml</code> with the document <code>&lt;xml/&gt;</code>.
 
 
|}
 
|}
  
==REPO DELETE==
+
==KILL==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>REPO DELETE [name&#124;dir]</code>
+
|<code>KILL [target]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''CREATE'' ({{Mark|before Version 7.2}}: ''ADMIN'')
+
|''ADMIN''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
| Deletes the package with name <code>[name]</code> or with directory <code>[dir]</code>.
+
|Kills sessions of a user or an IP:port combination, specified by <code>[target]</code>. The Glob syntax can be used to address more than one user.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
| The command fails if the package to be deleted participates in a dependency.
+
|The command fails if a user tried to kill his/her own session.
 
|}
 
|}
  
==REPO INSTALL==
+
==CREATE EVENT==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>REPO INSTALL [path]</code>
+
|<code>CREATE EVENT [NAME]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''CREATE'' ({{Mark|before Version 7.2}}: ''ADMIN'')
+
|''ADMIN''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
| Installs the package with path <code>[path]</code>.
+
|Creates the specified [[Events|event]].
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
| The command fails in the following cases:
+
|The command fails if event already exists.
* The package to be installed is not a xar file.
 
* The package to be installed does not exist or is already installed.
 
* The package descriptor is with invalid syntax.
 
* The package to be installed depends on a package which is not installed.
 
* The package is not supported by the current version of BaseX.
 
* A component of the package is already installed as part of another package.
 
 
|}
 
|}
  
==REPO LIST==
+
==SHOW EVENTS==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>REPO LIST</code>
+
|<code>SHOW EVENTS</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''READ'' ({{Mark|before Version 7.2}}: ''ADMIN'')
+
|''ADMIN''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
| Lists all installed packages.
+
|Shows all [[Events|events]] that have been registered in the database.
 
|}
 
|}
  
==RESTORE==
+
==DROP EVENT==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>RESTORE [name]</code>
+
|<code>DROP EVENT [NAME]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''CREATE''
+
|''ADMIN''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Restores a database with the specified <code>[name]</code>. The name may include the timestamp of the backup file.
+
|Drops the specified [[Events|event]].
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if the specified backup does not exist, if the database to be restored is currently locked, or if it could not be restored for some other reason.
+
|The command fails if the event doesn't exist.
 
|}
 
|}
  
==RETRIEVE==
+
=User Management=
 +
 
 +
==CREATE USER==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>RETRIEVE [path] [input]</code>
+
|<code>CREATE USER [name] ([password])</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''READ''
+
|''ADMIN''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Retrieves raw data from the specified database <code>[path]</code>.
+
|Creates a user with the specified <code>[name]</code> and <code>[password]</code>. <code>[name]</code> must be a [[Valid Names|valid user name]]. The password must be a valid MD5 hash value. If no password is specified in the console mode, it is requested via standard input.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if no database is opened, if the source path is invalid or if the data cannot not be retrieved for some other reason.
+
|The command fails if the specified user already exists, or if the password is no valid MD5 hash value.
 
|}
 
|}
  
==RUN==
+
==ALTER USER==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>RUN [file]</code>
+
|<code>ALTER USER [name] ([password])</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''depends on query''
+
|''ADMIN''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Runs the query contained in <code>[file]</code> and prints the result.
+
|Alters the <code>[password]</code> of the user specified by <code>[name]</code>. The password must be a valid MD5 hash value. If no password is specified in the console mode, it is requested via standard input.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if the specified file does not exist, or if the retrieved query is invalid.
+
|The command fails if the specified user does not exist, or if the password is no valid MD5 hash value.
 
|}
 
|}
  
==SET==
+
==DROP USER==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>SET [option] ([value])</code>
+
|<code>DROP USER [name] (ON [database])</code>:
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''READ''
+
|''ADMIN''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Sets the [[Options|Option]] with the specified <code>[key]</code> to a new <code>[value]</code>. If no value is specified, and if the value is boolean, it will be inverted.
+
|Drops the user with the specified <code>[name]</code>. If a <code>[database]</code> is specified, the user is only dropped locally. The Glob syntax can be used to address more than one database or user.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if the specified option is unknown or if the specified value is invalid.
+
|The command fails if <code>admin</code> is specified as user name, if the specified user does not exist or is logged in, or if the optional database could not be opened for modification.
 
|}
 
|}
  
==SHOW BACKUPS==
+
==GRANT==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>SHOW BACKUPS</code>
+
|<code>GRANT [NONE&#124;READ&#124;WRITE&#124;CREATE&#124;ADMIN] (ON [database]) TO [user]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''CREATE''
+
|''ADMIN''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Shows all database backups.
+
|Grants the specified [[User_Management|permission]] to the specified <code>[user]</code>. If a <code>[database]</code> is specified, the permissions are only granted locally. The Glob syntax can be used to address more than one database or user.
 +
|-
 +
| valign='top' | '''Errors'''
 +
|The command fails if <code>admin</code> is specified as user name, if the specified user does not exist, or if the optional database could not be opened for modification.
 +
|-
 +
| valign='top' | '''Examples'''
 +
|
 +
* <code>GRANT READ TO JoeWinson</code><br/>grants <code>READ</code> permission to the user <code>JoeWinson</code>.
 +
* <code>GRANT WRITE ON Wiki TO editor*</code><br/>grants <code>WRITE</code> permissions on the <code>Wiki</code> database to all users starting with the characters <code>editor*</code>.
 
|}
 
|}
==SHOW DATABASES==
+
 
 +
==PASSWORD==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>SHOW DATABASES</code>
+
|<code>PASSWORD ([password])</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''ADMIN''
+
|''NONE''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Shows all databases that are opened in the current server instance.
+
|Changes the <code>[password]</code> of the current user. The password must be a valid MD5 hash value. If no password is specified in the console mode, it is requested via standard input.
 +
|-
 +
| valign='top' | '''Errors'''
 +
|The command fails if the password is no valid MD5 hash value.
 
|}
 
|}
==SHOW SESSIONS==
+
 
 +
=General Commands=
 +
 
 +
==GET==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>SHOW SESSIONS</code>
+
|<code>GET [option]</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''ADMIN''
+
|''READ''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Shows all sessions that are connected to the current server instance.
+
|Returns the current value of the [[Options|Option]] specified via {{Mono|[key]}}.
 +
|-
 +
| valign='top' | '''Errors'''
 +
|The command fails if the specified option is unknown.
 
|}
 
|}
==SHOW EVENTS==
+
 
 +
==SET==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>SHOW EVENTS</code>
+
|<code>SET [option] ([value])</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''ADMIN''
+
|''READ''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Shows all [[Events|events]] that have been registered in the database.
+
|Sets the [[Options|Option]] with the specified <code>[key]</code> to a new <code>[value]</code>. If no value is specified, and if the value is boolean, it will be inverted.
 +
|-
 +
| valign='top' | '''Errors'''
 +
|The command fails if the specified option is unknown or if the specified value is invalid.
 
|}
 
|}
  
==SHOW USERS==
+
==INFO==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>SHOW USERS (ON [database])</code>
+
|<code>INFO</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''ADMIN''
+
|''READ''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Shows all users that are registered in the database. If a <code>[database]</code> is specified, local users are shown.
+
|Shows global information.
|-
 
| valign='top' | '''Errors'''
 
|The command fails if the optional database could not be opened.
 
 
|}
 
|}
  
==STORE==
+
==HELP==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>STORE (TO [path]) [input]</code>
+
|<code>HELP ([command])</code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''WRITE''
+
|''NONE''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Stores raw data to the specified <code>[path]</code>. <code>[input]</code> may either be a file reference, a remote URL, or a plain string. If the path denotes a directory, it needs to be suffixed with a slash (<code>/</code>).
+
|If <code>[command]</code> is specified, information on the specific command is printed; otherwise, all commands are listed.
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if no database is opened, if the specified resource is not found, if the target path is invalid or if the data cannot not be written for some other reason.
+
|The command fails if the specified command is unknown.
 
|}
 
|}
  
==XQUERY==
+
==EXIT==
 
{|
 
{|
 
|-
 
|-
 
| valign='top' width='90' | '''Signature'''
 
| valign='top' width='90' | '''Signature'''
|<code>XQUERY [query]</code>
+
|<code>EXIT </code>
 
|-
 
|-
 
| valign='top' | '''Permission'''
 
| valign='top' | '''Permission'''
|''depends on query''
+
|''NONE''
 
|-
 
|-
 
| valign='top' | '''Summary'''
 
| valign='top' | '''Summary'''
|Runs the specified <code>[query]</code> and prints the result.
+
|Exits the console mode.
|-
 
| valign='top' | '''Errors'''
 
|The command fails if the specified query is invalid.
 
|-
 
| valign='top' | '''Examples'''
 
|
 
* <code>XQUERY 1 to 10</code><br/>returns the sequence <code>(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)</code>.
 
* <code>SET RUNS 10;XQUERY 1 to 10</code><br/>runs the query 10 times, returns the result and prints the average execution time.
 
* <code>SET XMLPLAN true;XQUERY 1 to 10</code><br/>returns the result and prints the query plan as XML.
 
 
|}
 
|}
  

Revision as of 16:57, 6 April 2012

This page is linked from the Getting Started Section.

This page lists all commands that are supported by BaseX. Commands can be run from the Command Line, the Clients, REST, the input field in the GUI, or some other ways. If the GUI is used, all commands that are triggered by the GUI itself will show up in the Info View. The Permission fields indicate which rights are required by a user to perform a command in the client/server architecture. A shortcut exists for some of the command keywords. For example, you may replace the DATABASE keyword with DB.

Glob Syntax

For some commands, the glob syntax can be used to address more than one database or user. Question marks and asterisks can be used to match one or more characters, and commas can be used to separate multiple patterns. Some examples:

  • AB? addresses all names with the characters AB and one more character.
  • *AB addresses all names ending with the characters AB.
  • X*,Y*,Z* addresses all names starting with the characters X, Y, or Z.

Valid Names

Both database and user names must follow the same naming constraints. Valid names may contain letters, numbers, underscores and dashes. Names must have at least one character; they also should not be longer than 128 characters, although this is not enforced. A regular expression matching valid names is [-_a-zA-Z0-9]{1,128}.

Database Operations

CREATE DATABASE

Signature CREATE DATABASE [name] ([input])
Permission CREATE
Summary Creates the database [name] with an optional [input].
The input may either be a single XML document, a directory, a remote URL or a plain XML string. [name] must be a valid database name.
Errors The command fails if a database with the specified name is currently used by another process, or if one of the documents to be added is not well-formed or could not be parsed for some other reason.
Examples
  • CREATE DATABASE input
    creates an empty database input.
  • CREATE DATABASE xmark http://files.basex.org/xml/xmark.xml
    creates the database input with the remote file xmark.xml as initial content.
  • CREATE DATABASE coll /path/to/input
    creates the database coll with all documents from the input directory as initial content.
  • SET INTPARSE false;CREATE DB input input.xml
    creates a database input, using Java's default XML parser.

OPEN

Signature OPEN [path]
Permission READ
Summary Opens the documents in a database. [path] is the name of the database, optionally followed by a path to the requested documents.
Errors The command fails if the specified database cannot be opened for some unknown reason.

CHECK

Signature CHECK [input]
Permission CREATE
Summary Opens an existing database for the specified [input] or creates a new instance.
Errors The command fails if the database could beither be opened nor created.

CLOSE

Signature CLOSE
Permission NONE
Summary Closes the currently opened database.
Errors The command fails if the database files could not be closed for some unknown reason.

EXPORT

Signature EXPORT [path]
Permission CREATE
Summary Exports all documents in the database to the specified [path], using the serializer options specified by the EXPORTER option.
Errors The command fails if no database is opened, if the target path points to a file or is invalid, if the serialization parameters are invalid, or if the documents cannot be serialized for some other reason.

CREATE INDEX

Template:Mark PATH removed as argument; path summary is now updated by OPTIMIZE command

Signature CREATE INDEX [TEXT|ATTRIBUTE|FULLTEXT]
Permission WRITE
Summary Creates the specified database index.
Errors The command fails if no database is opened, if the specified index is unknown, or if indexing fails for some other reason.

DROP INDEX

Template:Mark PATH removed as argument; path summary is now always available

Signature DROP INDEX [TEXT|ATTRIBUTE|FULLTEXT]
Permission WRITE
Summary Drops the specified database index.
Errors The command fails if no database is opened, if the specified index is unknown, or if it could not be deleted for some other reason.

Administration

ALTER DATABASE

Signature ALTER DATABASE [name] [newname]
Permission CREATE
Summary Renames the database specified by [name] to [newname]. [newname] must be a valid database name.
Errors The command fails if the target database already exists, if the source database does not exist or is currently locked, or if it could not be renamed for some other reason.
Examples
  • ALTER DATABASE db tempdb
    renames the database db into tempdb.

DROP DATABASE

Signature DROP DATABASE [name]
Permission CREATE
Summary Drops the database with the specified [name]. The Glob syntax can be used to address more than one database.
Errors The command fails if the specified database does not exist or is currently locked, or if the database could not be deleted for some other reason.

CREATE BACKUP

Signature CREATE BACKUP [name]
Permission CREATE
Summary Creates a zipped backup of the database specified by [name]. The backup file will be suffixed with the current timestamp and stored in the database directory. The Glob syntax can be used to address more than one database.
Errors The command fails if the specified database does not exist, or if it could not be zipped for some other reason.
Examples
  • BACKUP db
    creates a zip archive of the database db (e.g. db-2011-04-01-12-27-28.zip) in your database directory.

RESTORE

Signature RESTORE [name]
Permission CREATE
Summary Restores a database with the specified [name]. The name may include the timestamp of the backup file.
Errors The command fails if the specified backup does not exist, if the database to be restored is currently locked, or if it could not be restored for some other reason.

DROP BACKUP

Signature DROP BACKUP [name]
Permission CREATE
Summary Drops all backups of the database with the specified [name]. The Glob syntax can be used to address more than one database.
Examples
  • DROP BACKUP abc*
    deletes the backups of all databases starting with the characters abc.

COPY

Signature COPY [name] [newname]
Permission CREATE
Summary Creates a copy of the database specified by [name]. [newname] must be a valid database name.
Errors The command fails if the target database already exists, or if the source database does not exist.

INFO DATABASE

Signature INFO DATABASE
Permission READ
Summary Shows information on the currently opened database.
Errors The command fails if no database is opened.

INFO INDEX

Signature INFO INDEX ([TEXT|ATTRIBUTE|FULLTEXT|PATH])
Permission READ
Summary Shows information on the existing index structures. The output can be optionally limited to the specified index.
Errors The command fails if no database is opened, or if the specified index is unknown.

INFO STORAGE

Signature INFO STORAGE [start end] | [query]
Permission READ
Summary Shows the internal main table of the currently opened database. An integer range or a query may be specified as argument.
Errors The command fails if no database is opened, or if one of the specified arguments is invalid.

Querying

LIST

Signature LIST ([path])
Permission NONE
Summary Lists all available databases, or the documents in a database. [path] is the name of the database, optionally followed by a path to the requested documents.
Errors The command fails if the optional database cannot be opened, or if the existing databases cannot be listed for some other reason.

XQUERY

Signature XQUERY [query]
Permission depends on query
Summary Runs the specified [query] and prints the result.
Errors The command fails if the specified query is invalid.
Examples
  • XQUERY 1 to 10
    returns the sequence (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).
  • SET RUNS 10;XQUERY 1 to 10
    runs the query 10 times, returns the result and prints the average execution time.
  • SET XMLPLAN true;XQUERY 1 to 10
    returns the result and prints the query plan as XML.

RETRIEVE

Signature RETRIEVE [path] [input]
Permission READ
Summary Retrieves raw data from the specified database [path].
Errors The command fails if no database is opened, if the source path is invalid or if the data cannot not be retrieved for some other reason.

RUN

Signature RUN [file]
Permission depends on query
Summary Runs the query contained in [file] and prints the result.
Errors The command fails if the specified file does not exist, or if the retrieved query is invalid.

FIND

Signature FIND [keywords]
Permission READ
Summary Builds and runs a query for the specified [keywords]. Keywords can be enclosed in quotes to look for phrases. The following modifiers can be used to further limit search:

= looks for exact text nodes
~ looks for approximate hits
@= looks for exact attribute values
@ looks for attributes

Errors The command fails if no database is opened.

CS

Signature CS [query]
Permission depends on query
Summary Evaluates the specified [query] and sets the result as new context set.
Errors The command fails if no database is opened, if the specified query is invalid or if it does not return nodes of the currently opened database.

REPO INSTALL

Signature REPO INSTALL [path]
Permission CREATE (Template:Mark: ADMIN)
Summary Installs the package with path [path].
Errors The command fails in the following cases:
  • The package to be installed is not a xar file.
  • The package to be installed does not exist or is already installed.
  • The package descriptor is with invalid syntax.
  • The package to be installed depends on a package which is not installed.
  • The package is not supported by the current version of BaseX.
  • A component of the package is already installed as part of another package.

REPO LIST

Signature REPO LIST
Permission READ (Template:Mark: ADMIN)
Summary Lists all installed packages.

REPO DELETE

Signature REPO DELETE [name|dir]
Permission CREATE (Template:Mark: ADMIN)
Summary Deletes the package with name [name] or with directory [dir].
Errors The command fails if the package to be deleted participates in a dependency.

Updates

ADD

Signature ADD (TO [path]) [input]
Permission WRITE
Summary Adds the files, directory or XML string specified by [input] to the currently opened database at the specified [path].
[input] may either be a single XML document, a directory, a remote URL or a plain XML string. If the path denotes a directory, it needs to be suffixed with a slash (/).
Errors The command fails if no database is opened, if one of the documents to be added is not well-formed, or if it could not be parsed for some other reason.
Examples
  • ADD input.xml
    adds the file input.xml to the database.
  • ADD TO temp/one.xml input.xml
    adds input.xml to the database and moves it to temp/one.xml.
  • ADD TO target/ xmldir
    adds all files from the xmldir directory to the database in the target path.

DELETE

Signature DELETE [path]
Permission WRITE
Summary Deletes all documents from the currently opened database that start with the specified [path].
Errors The command fails if no database is opened.

RENAME

Signature RENAME [path] [newpath]
Permission WRITE
Summary Renames all document paths in the currently opened database that start with the specified [path]. The command may be used to either rename single documents or directories.
Errors The command fails if no database is opened, or if the target path is empty.
Examples
  • RENAME one.xml two.xml
    renames the document one.xml to two.xml.
  • RENAME / TOP
    moves all documents to a TOP root directory.

REPLACE

Signature REPLACE [path] [input]
Permission WRITE
Summary Replaces the documents in the currently opened database, addressed by [path], with the file or XML string specified by [input]. The original file name and path is preserved by the operation.
Errors The command fails if no database is opened, if the specified path points to a database directory, or if the input is not found.
Examples
  • REPLACE one.xml input.xml
    replaces the document one.xml with the contents of the file input.xml.
  • REPLACE top.xml <xml/>
    replaces the document top.xml with the document <xml/>.

STORE

Signature STORE (TO [path]) [input]
Permission WRITE
Summary Stores raw data to the specified [path]. [input] may either be a file reference, a remote URL, or a plain string. If the path denotes a directory, it needs to be suffixed with a slash (/).
Errors The command fails if no database is opened, if the specified resource is not found, if the target path is invalid or if the data cannot not be written for some other reason.

OPTIMIZE

Signature OPTIMIZE (ALL)
Permission WRITE
Summary Optimizes the index structures, meta data and statistics of the currently opened database. If the ALL flag is specified, the internal database structures are completely rebuilt; this often leads to a reduction of the total database size.
Errors The command fails if no database is opened, or if the currently opened database is a main-memory instance.

FLUSH

Signature FLUSH
Permission WRITE
Summary Explicitly flushes the buffers of the currently opened database to disk. This command is applied if the AUTOFLUSH option has been set to false.
Errors The command fails if no database is opened.

Server Administration

SHOW BACKUPS

Signature SHOW BACKUPS
Permission CREATE
Summary Shows all database backups.

SHOW DATABASES

Signature SHOW DATABASES
Permission ADMIN
Summary Shows all databases that are opened in the current server instance.

SHOW SESSIONS

Signature SHOW SESSIONS
Permission ADMIN
Summary Shows all sessions that are connected to the current server instance.

SHOW USERS

Signature SHOW USERS (ON [database])
Permission ADMIN
Summary Shows all users that are registered in the database. If a [database] is specified, local users are shown.
Errors The command fails if the optional database could not be opened.

KILL

Signature KILL [target]
Permission ADMIN
Summary Kills sessions of a user or an IP:port combination, specified by [target]. The Glob syntax can be used to address more than one user.
Errors The command fails if a user tried to kill his/her own session.

CREATE EVENT

Signature CREATE EVENT [NAME]
Permission ADMIN
Summary Creates the specified event.
Errors The command fails if event already exists.

SHOW EVENTS

Signature SHOW EVENTS
Permission ADMIN
Summary Shows all events that have been registered in the database.

DROP EVENT

Signature DROP EVENT [NAME]
Permission ADMIN
Summary Drops the specified event.
Errors The command fails if the event doesn't exist.

User Management

CREATE USER

Signature CREATE USER [name] ([password])
Permission ADMIN
Summary Creates a user with the specified [name] and [password]. [name] must be a valid user name. The password must be a valid MD5 hash value. If no password is specified in the console mode, it is requested via standard input.
Errors The command fails if the specified user already exists, or if the password is no valid MD5 hash value.

ALTER USER

Signature ALTER USER [name] ([password])
Permission ADMIN
Summary Alters the [password] of the user specified by [name]. The password must be a valid MD5 hash value. If no password is specified in the console mode, it is requested via standard input.
Errors The command fails if the specified user does not exist, or if the password is no valid MD5 hash value.

DROP USER

Signature DROP USER [name] (ON [database]):
Permission ADMIN
Summary Drops the user with the specified [name]. If a [database] is specified, the user is only dropped locally. The Glob syntax can be used to address more than one database or user.
Errors The command fails if admin is specified as user name, if the specified user does not exist or is logged in, or if the optional database could not be opened for modification.

GRANT

Signature GRANT [NONE|READ|WRITE|CREATE|ADMIN] (ON [database]) TO [user]
Permission ADMIN
Summary Grants the specified permission to the specified [user]. If a [database] is specified, the permissions are only granted locally. The Glob syntax can be used to address more than one database or user.
Errors The command fails if admin is specified as user name, if the specified user does not exist, or if the optional database could not be opened for modification.
Examples
  • GRANT READ TO JoeWinson
    grants READ permission to the user JoeWinson.
  • GRANT WRITE ON Wiki TO editor*
    grants WRITE permissions on the Wiki database to all users starting with the characters editor*.

PASSWORD

Signature PASSWORD ([password])
Permission NONE
Summary Changes the [password] of the current user. The password must be a valid MD5 hash value. If no password is specified in the console mode, it is requested via standard input.
Errors The command fails if the password is no valid MD5 hash value.

General Commands

GET

Signature GET [option]
Permission READ
Summary Returns the current value of the Option specified via [key].
Errors The command fails if the specified option is unknown.

SET

Signature SET [option] ([value])
Permission READ
Summary Sets the Option with the specified [key] to a new [value]. If no value is specified, and if the value is boolean, it will be inverted.
Errors The command fails if the specified option is unknown or if the specified value is invalid.

INFO

Signature INFO
Permission READ
Summary Shows global information.

HELP

Signature HELP ([command])
Permission NONE
Summary If [command] is specified, information on the specific command is printed; otherwise, all commands are listed.
Errors The command fails if the specified command is unknown.

EXIT

Signature EXIT
Permission NONE
Summary Exits the console mode.

Changelog

Version 7.2

Version 7.1

  • Updated: KILL (killing sessions by specifying IP:port)

Version 7.0