Difference between revisions of "Commands"
Line 9: | Line 9: | ||
A shortcut exists for some of the command keywords. For example, you may replace | A shortcut exists for some of the command keywords. For example, you may replace | ||
the <code>DATABASE</code> keyword with <code>DB</code>. | the <code>DATABASE</code> keyword with <code>DB</code>. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=Database Operations= | =Database Operations= | ||
Line 34: | Line 22: | ||
|- | |- | ||
| 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 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''' | ||
Line 159: | Line 147: | ||
|- | |- | ||
| 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]]. | + | |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''' | ||
Line 179: | Line 167: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Drops the database with the specified <code>[name]</code>. The Glob | + | |Drops the database with the specified <code>[name]</code>. The [[#Glob Syntax|Glob Syntax]] can be used to address more than one database. |
|- | |- | ||
| valign='top' | '''Errors''' | | valign='top' | '''Errors''' | ||
Line 195: | Line 183: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | 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 | + | |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|Glob Syntax]] can be used to address more than one database. |
|- | |- | ||
| valign='top' | '''Errors''' | | valign='top' | '''Errors''' | ||
Line 231: | Line 219: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Drops all backups of the database with the specified <code>[name]</code>. The Glob | + | |Drops all backups of the database with the specified <code>[name]</code>. The [[#Glob Syntax|Glob Syntax]] can be used to address more than one database. |
|- | |- | ||
| valign='top' | '''Examples''' | | valign='top' | '''Examples''' | ||
Line 248: | Line 236: | ||
|- | |- | ||
| 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]]. | + | |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''' | ||
Line 655: | Line 643: | ||
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Kills sessions of a user or an IP:port combination, specified by <code>[target]</code>. The Glob | + | |Kills sessions of a user or an IP:port combination, specified by <code>[target]</code>. The [[#Glob Syntax|Glob Syntax]] can be used to address more than one user. |
|- | |- | ||
| valign='top' | '''Errors''' | | valign='top' | '''Errors''' | ||
Line 718: | Line 706: | ||
|- | |- | ||
| 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. | + | |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''' | ||
Line 750: | Line 738: | ||
|- | |- | ||
| 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 | + | |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|Glob Syntax]] can be used to address more than one database or user. |
|- | |- | ||
| valign='top' | '''Errors''' | | valign='top' | '''Errors''' | ||
Line 766: | Line 754: | ||
|- | |- | ||
| 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 | + | |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|Glob Syntax]] can be used to address more than one database or user. |
|- | |- | ||
| valign='top' | '''Errors''' | | valign='top' | '''Errors''' | ||
Line 868: | Line 856: | ||
|Exits the console mode. | |Exits the console mode. | ||
|} | |} | ||
+ | |||
+ | =Conventions= | ||
+ | |||
+ | ==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: | ||
+ | |||
+ | * <code>AB?</code> addresses all names with the characters <code>AB</code> and one more character. | ||
+ | * <code>*AB</code> addresses all names ending with the characters <code>AB</code>. | ||
+ | * <code>X*,Y*,Z*</code> addresses all names starting with the characters <code>X</code>, <code>Y</code>, or <code>Z</code>. | ||
+ | |||
+ | ==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 <code>[-_a-zA-Z0-9]{1,128}</code>. | ||
=Changelog= | =Changelog= |
Revision as of 17:08, 6 April 2012
This article is linked from the Getting Started Section.
It lists all database commands 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
.
Contents
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 |
|
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 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 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 |
|
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 |
|
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 |
|
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 |
|
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:
|
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:
|
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 |
|
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 |
|
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 |
|
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 |
|
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. |
Conventions
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 charactersAB
and one more character.*AB
addresses all names ending with the charactersAB
.X*,Y*,Z*
addresses all names starting with the charactersX
,Y
, orZ
.
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}
.
Changelog
Version 7.2
- Updated:
CREATE INDEX
,DROP INDEX
(PATH
argument removed. Path summary is always available now and updated with OPTIMIZE) - Updated: permissions for
REPO DELETE
,REPO INSTALL
andREPO LIST
Version 7.1
- Updated:
KILL
(killing sessions by specifying IP:port)