https://docs.basex.org/api.php?action=feedcontributions&user=Jan.vlcinsky&feedformat=atomBaseX Documentation - User contributions [en]2024-03-28T14:06:17ZUser contributionsMediaWiki 1.34.0https://docs.basex.org/index.php?title=Commands&diff=3493Commands2011-05-09T16:58:02Z<p>Jan.vlcinsky: COPY command description contained irrelevant text from ALTER DATABASE</p>
<hr />
<div>This page lists all database commands that are supported by BaseX.<br />
Database commands can either be run from the [[Startup_Options#BaseX_Standalone|Command Line]],<br />
the [[Language Bindings]], [[JAX-RX]], the input field in the [[GUI_Tutorial|GUI]], or<br />
in many other ways. If the GUI is used, all commands that are triggered by the GUI itself<br />
will show up in the [[GUI_Views|Info View]].<br />
<br />
The [[User_Management#Command_Permissions|Permissions]] indicate which<br />
rights are required by a user to perform a command in the client/server architecture.<br />
A shortcut exists for some of the command keywords. For example, you may replace<br />
the <code>DATABASE</code> keyword with <code>DB</code>.<br />
<br />
==ADD==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>ADD (AS [name]) (TO [target]) [input]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Write<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Adds the files, directory or XML string specified by <code>[input]</code> to the currently opened database, using an optional <code>[target]</code> path and an optional file <code>[name]</code>.<br/>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.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|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.<br />
|-<br />
| valign='top' | '''Examples'''<br />
|<br />
* <code>ADD input.xml</code><br/>adds the file <code>input.xml</code> to the database.<br />
* <code>ADD AS one.xml TO temp input.xml</code><br/>adds <code>input.xml</code> to the database and moves it to <code>temp/one.xml</code>.<br />
* <code>ADD TO new xmldir</code><br/>adds all files in the <code>xmldir</code> source directory to the database and moves them to to the target directory <code>new</code>.<br />
|}<br />
<br />
==ALTER DATABASE==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>ALTER DATABASE [name] [newname]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Create<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Renames the database specified by <code>[name]</code> to <code>[newname]</code>.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|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.<br />
|-<br />
| valign='top' | '''Examples'''<br />
|<br />
* <code>ALTER DATABASE db tempdb</code><br/>renames the database <code>db</code> into <code>tempdb</code>.<br />
|}<br />
<br />
==ALTER USER==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>ALTER USER [name] ([password])</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Admin<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Alters the <code>[password]</code> of the user specified by <code>[name]</code>. If no password is specified in the console mode, it is requested via standard input.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if the specified user does not exist, or if no password has been specified.<br />
|}<br />
<br />
==BACKUP==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>BACKUP [name]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Create<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Creates a zipped backup of the specified database. The backup file will be suffixed with the current timestamp.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if the specified database does not exist, or if it could not be zipped for some other reason.<br />
|-<br />
| valign='top' | '''Examples'''<br />
|<br />
* <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]] folder.<br />
|}<br />
<br />
==CHECK==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>CHECK [input]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Create<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Opens an existing database for the specified <code>[input]</code> or creates a new instance.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if the database could beither be opened nor created.<br />
|}<br />
<br />
==CLOSE==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>CLOSE </code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|None<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Closes the currently opened database.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if the database files could not be closed for some unknown reason.<br />
|}<br />
<br />
==COPY==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>COPY [name] [newname]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Create<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Creates a copy of the database specified by <code>[name]</code>.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if the target database already exists, or if the source database does not exist.<br />
|}<br />
==CREATE DATABASE==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>CREATE DATABASE [name] ([input])</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Create<br />
|-<br />
| valign='top' | '''Summary'''<br />
|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.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|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.<br />
|-<br />
| valign='top' | '''Examples'''<br />
|<br />
* <code>CREATE DATABASE input</code><br/>creates an empty database <code>input</code>.<br />
* <code>CREATE DATABASE input input.xml</code><br/>creates the database <code>input</code> with input.xml as content.<br />
* <code>CREATE DATABASE coll folder</code><br/>creates the database <code>coll</code> with all documents from the directory <code>folder</code> as content.<br />
* <code>SET INTPARSE ON;CREATE DB input input.xml</code><br/>creates a database <code>input</code>, using the [[Options#Database options|internal XML parser]].<br />
|}<br />
<br />
==CREATE INDEX==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>CREATE INDEX [TEXT&#124;ATTRIBUTE&#124;FULLTEXT&#124;PATH]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Write<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Creates the specified database index.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if no database is opened, if the specified index is unknown, or if indexing fails for some other reason.<br />
|}<br />
==CREATE USER==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>CREATE USER [name] ([password])</code>:<br />
|-<br />
| valign='top' | '''Permission'''<br />
|Admin<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Creates a user with the specified <code>[name]</code> and <code>[password]</code>. If no password is specified in the console mode, it is requested via standard input.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if the specified user already exists, or if no password has been specified.<br />
|}<br />
==CS==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>CS [query]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|''depends on query''<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Evaluates the specified <code>[query]</code> and sets the result as new context set.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|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.<br />
|}<br />
==DELETE==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>DELETE [path]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Write<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Deletes all documents from the currently opened database that start with the specified <code>[path]</code>.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if no database is opened.<br />
|}<br />
==DROP BACKUP==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>DROP BACKUP [name]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Create<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Drops all backups of the database with the specified <code>[name]</code>.<br />
|}<br />
==DROP DATABASE==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>DROP DATABASE [name]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Create<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Drops the database with the specified <code>[name]</code>.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|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.<br />
|}<br />
==DROP INDEX==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>DROP INDEX [PATH&#124;TEXT&#124;ATTRIBUTE&#124;FULLTEXT]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Write<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Drops the specified database index.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|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.<br />
|}<br />
==DROP USER==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>DROP USER [name] (ON [database])</code>:<br />
|-<br />
| valign='top' | '''Permission'''<br />
|Admin<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Drops the user with the specified <code>[name]</code>. If a <code>[database]</code> is specified, the user is only dropped locally. The default <code>admin</code> user can never be dropped.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|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.<br />
|}<br />
==EXIT==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>EXIT </code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|None<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Exits the console mode.<br />
|}<br />
==EXPORT==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>EXPORT [path]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Create<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Exports all documents in the database to the specified <code>[path]</code>, using the serializer options specified by the <code>[[Options#Query_options|EXPORTER]]</code> option.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|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.<br />
|}<br />
<br />
==FIND==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>FIND [keywords]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Read<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Builds and runs a query for the specified <code>[keywords]</code>. The following modifiers can be used to further limit search:<br />
<code>= </code> looks for exact text nodes<br/><code>@=</code> looks for exact attributes<br/><code>@ </code> looks for attributes<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if no database is opened.<br />
|}<br />
==GET==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>GET [option]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|None<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Returns the value of the specified <code>[option]</code>. A list of all options is [[Options|available here]].<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if the specified option is unknown.<br />
|}<br />
==GRANT==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>GRANT [NONE&#124;READ&#124;WRITE&#124;CREATE&#124;ADMIN] (ON [database]) TO [user]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Admin<br />
|-<br />
| valign='top' | '''Summary'''<br />
|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 permissions of the <code>admin</code> user cannot be modified.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if <code>admin</code> 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.<br />
|}<br />
<br />
==HELP==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>HELP ([command])</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|None<br />
|-<br />
| valign='top' | '''Summary'''<br />
|If <code>[command]</code> is specified, information on the specific command is printed; otherwise, all commands are listed.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if the specified command is unknown.<br />
|}<br />
==INFO==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>INFO</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Read<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Shows global information.<br />
|}<br />
==INFO DATABASE==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>INFO DATABASE</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Read<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Shows information on the currently opened database.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if no database is opened.<br />
|}<br />
==INFO INDEX==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>INFO INDEX ([TEXT&#124;ATTRIBUTE&#124;FULLTEXT&#124;PATH])</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Read<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Shows information on the existing index structures. The output can be optionally limited to the specified index.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if no database is opened, or if the specified index is unknown.<br />
|}<br />
<br />
==INFO STORAGE==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
| <code>INFO STORAGE [start end] &#124; [query]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Read<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Shows the internal main table of the currently opened database. An integer range or a query may be specified as argument.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if no database is opened, or if one of the specified arguments is invalid.<br />
|}<br />
==KILL==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>KILL [name]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Admin<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Kills all sessions of the user specified by <code>[name]</code>.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if <code>admin</code> is specified as user name, or if a user tries to kill his own sessions.<br />
|}<br />
==LIST==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>LIST ([path])</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|None<br />
|-<br />
| valign='top' | '''Summary'''<br />
|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.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if the optional database cannot be opened, or if the existing databases cannot be listed for some other reason.<br />
|}<br />
==OPEN==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>OPEN [path]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Read<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Opens the documents in a database. <code>[path]</code> is the name of the database, optionally followed by a path to the requested documents.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if the specified database cannot be opened for some unknown reason.<br />
|}<br />
==OPTIMIZE==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>OPTIMIZE (ALL)</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Write<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Optimizes the current database structures. If the <code>ALL</code> flag is specified, the size of all database files is minimized.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if no database is opened, or if the currently opened database is a main-memory instance.<br />
|}<br />
==PASSWORD==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>PASSWORD ([password])</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|None<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Changes the <code>[password]</code> of the current user. If no password is specified in the console mode, it is requested via standard input.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if no password has been specified.<br />
|}<br />
==RESTORE==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>RESTORE [name]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Create<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Restores a database with the specified <code>[name]</code>. The name may include the timestamp of the backup file.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|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.<br />
|}<br />
==RUN==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>RUN [file]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|''depends on query''<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Runs the query contained in <code>[file]</code> and prints the result.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if the specified file does not exist, or if the retrieved query is invalid.<br />
|}<br />
<br />
==SET==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>SET [option] ([value])</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|None<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Sets an <code>[option]</code> to the specified <code>[value]</code>. A list of all options is [[Options|available here]].<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if the specified option is unknown or if the specified value is invalid.<br />
|}<br />
==SHOW BACKUPS==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>SHOW BACKUPS</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Create<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Shows all database backups.<br />
|}<br />
==SHOW DATABASES==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>SHOW DATABASES</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Admin<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Shows all databases that are opened in the current server instance.<br />
|}<br />
==SHOW SESSIONS==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>SHOW SESSIONS</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Admin<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Shows all sessions that are connected to the current server instance.<br />
|}<br />
==SHOW USERS==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>SHOW USERS (ON [database])</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|Admin<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Shows all users that are registered in the database. If a <code>[database]</code> is specified, local users are shown.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if the optional database could not be opened.<br />
|}<br />
==XQUERY==<br />
{|<br />
|-<br />
| valign='top' width='90' | '''Signature'''<br />
|<code>XQUERY [query]</code><br />
|-<br />
| valign='top' | '''Permission'''<br />
|''depends on query''<br />
|-<br />
| valign='top' | '''Summary'''<br />
|Runs the specified <code>[query]</code> and prints the result.<br />
|-<br />
| valign='top' | '''Errors'''<br />
|The command fails if the specified query is invalid.<br />
|-<br />
| valign='top' | '''Examples'''<br />
|<br />
* <code>XQUERY 1 to 10</code><br/>returns the sequence <code>(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)</code>.<br />
* <code>SET RUNS 10;XQUERY 1 to 10</code><br/>runs the query 10 times, returns the result and prints the average execution time.<br />
* <code>SET XMLPLAN TRUE;XQUERY 1 to 10</code><br/>returns the result and prints the query plan as XML.<br />
|}<br />
<br />
[[Category:Beginner]]<br />
[[Category:Server]]</div>Jan.vlcinskyhttps://docs.basex.org/index.php?title=User_talk:Jan.vlcinsky&diff=2146User talk:Jan.vlcinsky2011-01-19T07:52:49Z<p>Jan.vlcinsky: </p>
<hr />
<div>Hi Jan and welcome to our Wiki. We decided to open it for public edits - that will be reviewed by admins - today! <br />
Nice to have you here!<br />
--[[User:Michael|Michael]] 22:21, 18 January 2011 (CET)<br />
Hi Michael and others, nice to see the THING evolving and growing.</div>Jan.vlcinsky