Difference between revisions of "Commands"
m (Text replace - "{{Mono|" to "{{Code|") |
|||
Line 8: | Line 8: | ||
rights are required by a user to perform a command in the client/server architecture. | 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 | A shortcut exists for some of the command keywords. For example, you may replace | ||
− | the | + | the {{Code|DATABASE}} keyword with {{Code|DB}}. |
+ | |||
+ | =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?}} addresses all names with the characters {{Code|AB}} and one more character. | ||
+ | * {{Code|*AB}} addresses all names ending with the characters {{Code|AB}}. | ||
+ | * {{Code|X*,Y*,Z*}} addresses all names starting with the characters {{Code|X}}, {{Code|Y}}, or {{Code|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 <code>[-_a-zA-Z0-9]{1,128}</code>. | ||
+ | |||
+ | ==Shortcuts== | ||
+ | |||
+ | In all commands, the {{Code|DATABASE}} keyword can be replaced by the shortcut {{Code|DB}}. | ||
=Database Operations= | =Database Operations= | ||
Line 16: | Line 34: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|CREATE DATABASE [name] ([input])}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 22: | Line 40: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Creates the database | + | |Creates the database {{Code|[name]}} with an optional {{Code|[input]}}.<br />The input may either be a reference to a single XML document, a directory, a remote URL, or a string containing XML. {{Code|[name]}} must be a [[#Valid Names|valid database name]]. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 29: | Line 47: | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
− | * | + | * {{Code|CREATE DATABASE input}}<br/>creates an empty database {{Code|input}}. |
− | * | + | * {{Code|CREATE DATABASE xmark http://files.basex.org/xml/xmark.xml}}<br/>creates the database {{Code|xmark}}, containing a single initial document called {{Code|xmark.xml}}. |
− | * | + | * {{Code|CREATE DATABASE coll /path/to/input}}<br/>creates the database {{Code|coll}} with all documents found in the {{Code|input}} directory. |
− | * | + | * {{Code|SET INTPARSE false; CREATE DATABASE input input.xml}}<br/>creates a database {{Code|input}} with {{Code|input.xml}} as initial document, which will be parsed with Java's [[Parsers#XML Parsers|default XML parser]]. |
|} | |} | ||
Line 39: | Line 57: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|OPEN [path]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 45: | Line 63: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Opens a database or some of its documents. | + | |Opens a database or some of its documents. {{Code|[path]}} is the name of the database. If the name is further refined by a path, only some of the documents in the database will be opened. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 55: | Line 73: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|CHECK [input]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 71: | Line 89: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|CLOSE }} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 87: | Line 105: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|EXPORT [path]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 93: | Line 111: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Exports all documents in the database to the specified | + | |Exports all documents in the database to the specified {{Code|[path]}}, using the serializer options specified by the <code>[[Options#EXPORTER|EXPORTER]]</code> option. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 105: | Line 123: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|CREATE INDEX [TEXT|ATTRIBUTE|FULLTEXT]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 123: | Line 141: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|DROP INDEX [TEXT|ATTRIBUTE|FULLTEXT]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 141: | Line 159: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|ALTER DATABASE [name] [newname]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 147: | Line 165: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Renames the database specified by | + | |Renames the database specified by {{Code|[name]}} to {{Code|[newname]}}. {{Code|[newname]}} must be a [[#Valid Names|valid database name]]. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 154: | Line 172: | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
− | * | + | * {{Code|ALTER DATABASE db tempdb}}<br/>renames the database {{Code|db}} into {{Code|tempdb}}. |
|} | |} | ||
Line 161: | Line 179: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|DROP DATABASE [name]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 167: | Line 185: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Drops the database with the specified | + | |Drops the database with the specified {{Code|[name]}}. The [[#Glob Syntax|Glob Syntax]] can be used to address more than one database. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 177: | Line 195: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|CREATE BACKUP [name]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 190: | Line 208: | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
− | * | + | * {{Code|BACKUP db}}<br/>creates a zip archive of the database {{Code|db}} (e.g. {{Code|db-2011-04-01-12-27-28.zip}}) in the [[Configuration#Database_Directory|database directory]]. |
|} | |} | ||
Line 197: | Line 215: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|RESTORE [name]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 203: | Line 221: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Restores a database with the specified | + | |Restores a database with the specified {{Code|[name]}}. The name may include the timestamp of the backup file. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 213: | Line 231: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|DROP BACKUP [name]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 219: | Line 237: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Drops all backups of the database with the specified | + | |Drops all backups of the database with the specified {{Code|[name]}}. The [[#Glob Syntax|Glob Syntax]] can be used to address more than one database. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
− | * | + | * {{Code|DROP BACKUP abc*}}<br/>deletes the backups of all databases starting with the characters {{Code|abc}}. |
|} | |} | ||
Line 230: | Line 248: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|SHOW BACKUPS}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 243: | Line 261: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|COPY [name] [newname]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 249: | Line 267: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Creates a copy of the database specified by | + | |Creates a copy of the database specified by {{Code|[name]}}. {{Code|[newname]}} must be a [[#Valid Names|valid database name]]. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 259: | Line 277: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|INFO DATABASE}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 275: | Line 293: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|INFO INDEX ([TEXT|ATTRIBUTE|FULLTEXT|PATH])}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 291: | Line 309: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | | {{Code|INFO STORAGE [start end] | [query]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 309: | Line 327: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|LIST ([path])}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 315: | Line 333: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Lists all available databases, or the documents in a database. | + | |Lists all available databases, or the documents in a database. {{Code|[path]}} is the name of the database, optionally followed by a path to the requested documents. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 325: | Line 343: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|XQUERY [query]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 331: | Line 349: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Runs the specified | + | |Runs the specified {{Code|[query]}} and prints the result. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 338: | Line 356: | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
− | * | + | * {{Code|XQUERY 1 to 10}}<br/>returns the sequence {{Code|(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)}}. |
− | * | + | * {{Code|SET RUNS 10; XQUERY 1 to 10}}<br/>runs the query 10 times, returns the result and prints the average execution time. |
− | * | + | * {{Code|SET XMLPLAN true; XQUERY 1 to 10}}<br/>returns the result and prints the query plan as XML. |
|} | |} | ||
Line 347: | Line 365: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|RETRIEVE [path] [input]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 353: | Line 371: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Retrieves raw data from the specified database | + | |Retrieves raw data from the specified database {{Code|[path]}}. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 363: | Line 381: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|RUN [file]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 369: | Line 387: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Runs the query contained in | + | |Runs the query contained in {{Code|[file]}} and prints the result. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 379: | Line 397: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|FIND [keywords]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 385: | Line 403: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Builds and runs a query for the specified | + | |Builds and runs a query for the specified {{Code|[keywords]}}. Keywords can be enclosed in quotes to look for phrases. The following modifiers can be used to further limit search: |
− | + | {{Code|= }} looks for exact text nodes<br/>{{Code|~ }} looks for approximate hits<br/>{{Code|@=}} looks for exact attribute values<br/>{{Code|@ }} looks for attributes | |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 396: | Line 414: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|CS [query]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 402: | Line 420: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Evaluates the specified | + | |Evaluates the specified {{Code|[query]}} and sets the result as new context set. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 412: | Line 430: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|REPO INSTALL [path]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 418: | Line 436: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | | Installs the package with path | + | | Installs the package with path {{Code|[path]}}. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 434: | Line 452: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|REPO LIST}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 447: | Line 465: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|REPO DELETE [name|dir]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 453: | Line 471: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | | Deletes the package with name | + | | Deletes the package with name {{Code|[name]}} or with directory {{Code|[dir]}}. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 465: | Line 483: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|ADD (TO [path]) [input]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 471: | Line 489: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Adds the files, directory or XML string specified by | + | |Adds the files, directory or XML string specified by {{Code|[input]}} to the currently opened database at the specified {{Code|[path]}}.<br/>{{Code|[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 ({{Code|/}}). |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 478: | Line 496: | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
− | * | + | * {{Code|ADD input.xml}}<br/>adds the file {{Code|input.xml}} to the database. |
− | * | + | * {{Code|ADD TO temp/one.xml input.xml}}<br/>adds {{Code|input.xml}} to the database and moves it to {{Code|temp/one.xml}}. |
− | * | + | * {{Code|ADD TO target/ xmldir}}<br/>adds all files from the {{Code|xmldir}} directory to the database in the {{Code|target}} path. |
|} | |} | ||
Line 487: | Line 505: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|DELETE [path]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 493: | Line 511: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Deletes all documents from the currently opened database that start with the specified | + | |Deletes all documents from the currently opened database that start with the specified {{Code|[path]}}. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 503: | Line 521: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|RENAME [path] [newpath]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 509: | Line 527: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Renames all document paths in the currently opened database that start with the specified | + | |Renames all document paths in the currently opened database that start with the specified {{Code|[path]}}. The command may be used to either rename single documents or directories. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 516: | Line 534: | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
− | * | + | * {{Code|RENAME one.xml two.xml}}<br/>renames the document {{Code|one.xml}} to {{Code|two.xml}}. |
− | * | + | * {{Code|RENAME / TOP}}<br/>moves all documents to a {{Code|TOP}} root directory. |
|} | |} | ||
Line 524: | Line 542: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|REPLACE [path] [input]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 530: | Line 548: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Replaces the documents in the currently opened database, addressed by | + | |Replaces the documents in the currently opened database, addressed by {{Code|[path]}}, with the file or XML string specified by {{Code|[input]}}. The original file name and path is preserved by the operation. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 537: | Line 555: | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
− | * | + | * {{Code|REPLACE one.xml input.xml}}<br/>replaces the document {{Code|one.xml}} with the contents of the file {{Code|input.xml}}. |
− | * | + | * {{Code|REPLACE top.xml <xml/>}}<br/>replaces the document {{Code|top.xml}} with the document {{Code|<xml/>}}. |
|} | |} | ||
Line 545: | Line 563: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|STORE (TO [path]) [input]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 551: | Line 569: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Stores raw data to the specified | + | |Stores raw data to the specified {{Code|[path]}}. {{Code|[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 ({{Code|/}}). |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 561: | Line 579: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|OPTIMIZE (ALL)}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 577: | Line 595: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|FLUSH}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 595: | Line 613: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|SHOW DATABASES}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 608: | Line 626: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|SHOW SESSIONS}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 621: | Line 639: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|SHOW USERS (ON [database])}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 627: | Line 645: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Shows all users that are registered in the database. If a | + | |Shows all users that are registered in the database. If a {{Code|[database]}} is specified, local users are shown. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 637: | Line 655: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|KILL [target]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 643: | Line 661: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Kills sessions of a user or an IP:port combination, specified by | + | |Kills sessions of a user or an IP:port combination, specified by {{Code|[target]}}. The [[#Glob Syntax|Glob Syntax]] can be used to address more than one user. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 653: | Line 671: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|CREATE EVENT [NAME]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 669: | Line 687: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|SHOW EVENTS}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 682: | Line 700: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|DROP EVENT [NAME]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 700: | Line 718: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|CREATE USER [name] ([password])}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 706: | Line 724: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Creates a user with the specified | + | |Creates a user with the specified {{Code|[name]}} and {{Code|[password]}}. {{Code|[name]}} 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. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 716: | Line 734: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|ALTER USER [name] ([password])}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 722: | Line 740: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Alters the | + | |Alters the {{Code|[password]}} of the user specified by {{Code|[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''' | | '''Errors''' | ||
Line 732: | Line 750: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|DROP USER [name] (ON [database])}}: |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 738: | Line 756: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Drops the user with the specified | + | |Drops the user with the specified {{Code|[name]}}. If a {{Code|[database]}} is specified, the user is only dropped locally. The [[#Glob Syntax|Glob Syntax]] can be used to address more than one database or user. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
− | |The command fails if | + | |The command fails if {{Code|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. |
|} | |} | ||
Line 748: | Line 766: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|GRANT [NONE|READ|WRITE|CREATE|ADMIN] (ON [database]) TO [user]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 754: | Line 772: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Grants the specified [[User_Management|permission]] to the specified | + | |Grants the specified [[User_Management|permission]] to the specified {{Code|[user]}}. If a {{Code|[database]}} is specified, the permissions are only granted locally. The [[#Glob Syntax|Glob Syntax]] can be used to address more than one database or user. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
− | |The command fails if | + | |The command fails if {{Code|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''' | | '''Examples''' | ||
| | | | ||
− | * | + | * {{Code|GRANT READ TO JoeWinson}}<br/>grants {{Code|READ}} permission to the user {{Code|JoeWinson}}. |
− | * | + | * {{Code|GRANT WRITE ON Wiki TO editor*}}<br/>grants {{Code|WRITE}} permissions on the {{Code|Wiki}} database to all users starting with the characters {{Code|editor*}}. |
|} | |} | ||
Line 769: | Line 787: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|PASSWORD ([password])}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 775: | Line 793: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Changes the | + | |Changes the {{Code|[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''' | | '''Errors''' | ||
Line 788: | Line 806: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|GET [option]}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 805: | Line 823: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|SET [option] ([value])}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 811: | Line 829: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Sets the [[Options|Option]] with the specified | + | |Sets the [[Options|Option]] with the specified {{Code|[key]}} to a new {{Code|[value]}}. If no value is specified, and if the value is boolean, it will be inverted. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 821: | Line 839: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|INFO}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 834: | Line 852: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|HELP ([command])}} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 840: | Line 858: | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |If | + | |If {{Code|[command]}} is specified, information on the specific command is printed; otherwise, all commands are listed. |
|- | |- | ||
| '''Errors''' | | '''Errors''' | ||
Line 850: | Line 868: | ||
|- | |- | ||
| width='90' | '''Signature''' | | width='90' | '''Signature''' | ||
− | | | + | |{{Code|EXIT }} |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
Line 858: | Line 876: | ||
|Exits the console mode. | |Exits the console mode. | ||
|} | |} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=Changelog= | =Changelog= |
Revision as of 22:57, 26 May 2012
This article is linked from the Getting Started Section.
It lists all database commands supported by BaseX.
Commands can e.g. be run from the Command Line,
the Clients, REST, the input field in the GUI, and in numerous
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
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}
.
Shortcuts
In all commands, the DATABASE
keyword can be replaced by the shortcut DB
.
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 reference to a single XML document, a directory, a remote URL, or a string containing XML. [name] must be a valid database name.
|
Errors | The command fails if a database with the specified name is currently used by another process, if one of the documents to be added is not well-formed or if it cannot be parsed for some other reason. |
Examples |
|
OPEN
Signature | OPEN [path]
|
Permission | READ |
Summary | Opens a database or some of its documents. [path] is the name of the database. If the name is further refined by a path, only some of the documents in the database will be opened.
|
Errors | The command fails if the specified database does not exist, is currently being updated by another process, cannot be opened for some other reason. |
CHECK
Signature | CHECK [input]
|
Permission | READ/CREATE |
Summary | This command combines OPEN and CREATE DATABASE: if a database with the name [input] exists, it is opened. Otherwise, it creates a new database and stores the specified input as initial content.
|
Errors | The command fails if the addressed database could neither be opened nor created. |
CLOSE
Signature | CLOSE
|
Permission | READ |
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 |
|
SHOW BACKUPS
Signature | SHOW BACKUPS
|
Permission | CREATE |
Summary | Shows all database backups. |
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 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
Template:Mark permission changed from READ
to NONE
Signature | GET [option]
|
Permission | NONE |
Summary | Returns the current value of the Option specified via [key] .
|
Errors | The command fails if the specified option is unknown. |
SET
Template:Mark permission changed from READ
to NONE
Signature | SET [option] ([value])
|
Permission | NONE |
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.1
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)