Difference between revisions of "Commands"

From BaseX Documentation
Jump to navigation Jump to search
(COPY command description contained irrelevant text from ALTER DATABASE)
Line 133: Line 133:
 
|-
 
|-
 
| valign='top' | '''Errors'''
 
| valign='top' | '''Errors'''
|The command fails if the target database already exists, if the source database does not exist, or if it could not be renamed for some other reason.
+
|The command fails if the target database already exists, or if the source database does not exist.
 
|}
 
|}
 
==CREATE DATABASE==
 
==CREATE DATABASE==

Revision as of 17:58, 9 May 2011

This page lists all database commands that are supported by BaseX. Database commands can either be run from the Command Line, the Language Bindings, JAX-RX, the input field in the GUI, or in many other ways. If the GUI is used, all commands that are triggered by the GUI itself will show up in the Info View.

The Permissions 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.

ADD

Signature ADD (AS [name]) (TO [target]) [input]
Permission Write
Summary Adds the files, directory or XML string specified by [input] to the currently opened database, using an optional [target] path and an optional file [name].
The input may either be a single XML document, a directory, a remote URL or a plain XML string. The optional name is ignored if the input is a directory.
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 AS one.xml TO temp input.xml
    adds input.xml to the database and moves it to temp/one.xml.
  • ADD TO new xmldir
    adds all files in the xmldir source directory to the database and moves them to to the target directory new.

ALTER DATABASE

Signature ALTER DATABASE [name] [newname]
Permission Create
Summary Renames the database specified by [name] to [newname].
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.

ALTER USER

Signature ALTER USER [name] ([password])
Permission Admin
Summary Alters the [password] of the user specified by [name]. 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 no password has been specified.

BACKUP

Signature BACKUP [name]
Permission Create
Summary Creates a zipped backup of the specified database. The backup file will be suffixed with the current timestamp.
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 folder.

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.

COPY

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

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.
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 input input.xml
    creates the database input with input.xml as content.
  • CREATE DATABASE coll folder
    creates the database coll with all documents from the directory folder as content.
  • SET INTPARSE ON;CREATE DB input input.xml
    creates a database input, using the internal XML parser.

CREATE INDEX

Signature CREATE INDEX [TEXT|ATTRIBUTE|FULLTEXT|PATH]
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.

CREATE USER

Signature CREATE USER [name] ([password]):
Permission Admin
Summary Creates a user with the specified [name] and [password]. 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 no password has been specified.

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.

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.

DROP BACKUP

Signature DROP BACKUP [name]
Permission Create
Summary Drops all backups of the database with the specified [name].

DROP DATABASE

Signature DROP DATABASE [name]
Permission Create
Summary Drops the database with the specified [name].
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.

DROP INDEX

Signature DROP INDEX [PATH|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.

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 default admin user can never be dropped.
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.

EXIT

Signature EXIT
Permission None
Summary Exits the console mode.

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, or if the documents cannot be serialized for some other reason.

FIND

Signature FIND [keywords]
Permission Read
Summary Builds and runs a query for the specified [keywords]. The following modifiers can be used to further limit search:

= looks for exact text nodes
@= looks for exact attributes
@ looks for attributes

Errors The command fails if no database is opened.

GET

Signature GET [option]
Permission None
Summary Returns the value of the specified [option]. A list of all options is available here.
Errors The command fails if the specified option is unknown.

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 permissions of the admin user cannot be modified.
Errors The command fails if admin is specified as user name, if the specified index is unknown, if the specified user does not exist, or if the optional database could not be opened for modification.

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.

INFO

Signature INFO
Permission Read
Summary Shows global information.

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.

KILL

Signature KILL [name]
Permission Admin
Summary Kills all sessions of the user specified by [name].
Errors The command fails if admin is specified as user name, or if a user tries to kill his own sessions.

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.

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.

OPTIMIZE

Signature OPTIMIZE (ALL)
Permission Write
Summary Optimizes the current database structures. If the ALL flag is specified, the size of all database files is minimized.
Errors The command fails if no database is opened, or if the currently opened database is a main-memory instance.

PASSWORD

Signature PASSWORD ([password])
Permission None
Summary Changes the [password] of the current user. If no password is specified in the console mode, it is requested via standard input.
Errors The command fails if no password has been specified.

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.

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.

SET

Signature SET [option] ([value])
Permission None
Summary Sets an [option] to the specified [value]. A list of all options is available here.
Errors The command fails if the specified option is unknown or if the specified value is invalid.

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.

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.