Difference between revisions of "Commands"
| Line 1: | Line 1: | ||
| − | This article is | + | This article is part of the [[Getting Started]] Section. |
It lists all database commands supported by BaseX. | It lists all database commands supported by BaseX. | ||
Commands can e.g. be run from the [[Startup_Options#BaseX_Standalone|Command Line]], | Commands can e.g. be run from the [[Startup_Options#BaseX_Standalone|Command Line]], | ||
| Line 9: | Line 9: | ||
=Conventions= | =Conventions= | ||
| + | |||
| + | Multiple commands can be separated by semicolons. | ||
| + | |||
| + | ==XML Syntax== | ||
| + | |||
| + | {{Mark|Introduced with Version 7.3:}} | ||
| + | |||
| + | In addition to the string syntax, database commands can also be formulated in XML. All commands are surrounded by a {{Code|<commands/>}} root element. The following XML script creates a database, adds two documents and performs a query: | ||
| + | |||
| + | <pre class="brush:xquery"> | ||
| + | <commands> | ||
| + | <create-db name='test'/> | ||
| + | <add>input.xml</add> | ||
| + | <add path='embedded.xml'><root>Embedded Document</root></add> | ||
| + | <xquery>count(//text())</xquery> | ||
| + | </commands> | ||
| + | </pre> | ||
==Glob Syntax== | ==Glob Syntax== | ||
| Line 24: | Line 41: | ||
==Aliases== | ==Aliases== | ||
| − | In all commands, the {{Code|DB}} keyword can be replaced by | + | In all commands, the {{Code|DB}} keyword can be replaced by {{Code|DATABASE}}. |
=Database Operations= | =Database Operations= | ||
==CREATE DB== | ==CREATE DB== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|CREATE DB [name] ([input])}} | + | |width='100%'|{{Code|CREATE DB [name] ([input])}} |
|- | |- | ||
| − | | '''XML Syntax''' | + | | '''XML Syntax''' |
| − | |<code><create-db name='[name]'/></code><br/><code><create-db name='[name]'>[input]</create-db></code> | + | |<code><create-db name='[name]'/></code><br/><code><create-db name='[name]'>[input]</create-db></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 55: | Line 72: | ||
==OPEN== | ==OPEN== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|OPEN [path]}} | + | |width='100%'|{{Code|OPEN [path]}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><open path='[path]'/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 71: | Line 91: | ||
==CHECK== | ==CHECK== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|CHECK [input]}} | ||
|- | |- | ||
| − | | | + | | '''XML Syntax''' |
| − | | | + | |<code><check input='[input]'/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 87: | Line 110: | ||
==CLOSE== | ==CLOSE== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|CLOSE }} | ||
|- | |- | ||
| − | + | | '''XML Syntax''' | |
| − | | | + | |<code><close/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 103: | Line 129: | ||
==EXPORT== | ==EXPORT== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|EXPORT [path]}} | ||
|- | |- | ||
| − | | | + | | '''XML Syntax''' |
| − | | | + | |<code><export path='[path]'/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 121: | Line 150: | ||
{{Mark|Updated in Version 7.2:}} {{Code|PATH}} removed as argument; path summary is now updated by [[#OPTIMIZE|OPTIMIZE]] command | {{Mark|Updated in Version 7.2:}} {{Code|PATH}} removed as argument; path summary is now updated by [[#OPTIMIZE|OPTIMIZE]] command | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|CREATE INDEX [TEXT|ATTRIBUTE|FULLTEXT]}} | ||
|- | |- | ||
| − | | | + | | '''XML Syntax''' |
| − | + | |<code><create-index type='text|attribute|fulltext'/></code><br/> | |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 139: | Line 171: | ||
{{Mark|Updated in Version 7.2:}} {{Code|PATH}} removed as argument; path summary is now always available | {{Mark|Updated in Version 7.2:}} {{Code|PATH}} removed as argument; path summary is now always available | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|DROP INDEX [TEXT|ATTRIBUTE|FULLTEXT]}} | + | |width='100%'|{{Code|DROP INDEX [TEXT|ATTRIBUTE|FULLTEXT]}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><drop-index type='text|attribute|fulltext'/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 157: | Line 192: | ||
==ALTER DB== | ==ALTER DB== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|ALTER DB [name] [newname]}} | + | |width='100%'|{{Code|ALTER DB [name] [newname]}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><alter-db name='[name]' newname='[newname]'/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 177: | Line 215: | ||
==DROP DB== | ==DROP DB== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|DROP DB [name]}} | + | |width='100%'|{{Code|DROP DB [name]}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><drop-db name='[name]'/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 193: | Line 234: | ||
==CREATE BACKUP== | ==CREATE BACKUP== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|CREATE BACKUP [name]}} | ||
|- | |- | ||
| − | | | + | | '''XML Syntax''' |
| − | | | + | |<code><create-backup name='[name]'/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 213: | Line 257: | ||
==RESTORE== | ==RESTORE== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|RESTORE [name]}} | ||
|- | |- | ||
| − | | | + | | '''XML Syntax''' |
| − | | | + | |<code><restore name='[name]'/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 229: | Line 276: | ||
==DROP BACKUP== | ==DROP BACKUP== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|DROP BACKUP [name]}} | ||
|- | |- | ||
| − | | | + | | '''XML Syntax''' |
| − | | | + | |<code><drop-backup name='[name]'/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 246: | Line 296: | ||
==SHOW BACKUPS== | ==SHOW BACKUPS== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|SHOW BACKUPS}} | ||
|- | |- | ||
| − | + | | '''XML Syntax''' | |
| − | | | + | |<code><show-backups/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 259: | Line 312: | ||
==COPY== | ==COPY== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|COPY [name] [newname]}} | + | |width='100%'|{{Code|COPY [name] [newname]}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><copy name='[name]' newname='[newname]'/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 275: | Line 331: | ||
==INFO DB== | ==INFO DB== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|INFO DB}} | + | |width='100%'|{{Code|INFO DB}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><info-db/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 291: | Line 350: | ||
==INFO INDEX== | ==INFO INDEX== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|INFO INDEX ([TEXT|ATTRIBUTE|FULLTEXT|PATH])}} | + | |width='100%'|{{Code|INFO INDEX ([TEXT|ATTRIBUTE|FULLTEXT|PATH])}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><info-index type='tag|attname|path|text|attribute|fulltext'/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 307: | Line 369: | ||
==INFO STORAGE== | ==INFO STORAGE== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|INFO STORAGE [start end] | [query]}} | ||
|- | |- | ||
| − | | | + | | '''XML Syntax''' |
| − | | | + | |<code><info-storage/></code><br/><code><info-storage start='[start]' end='[end]'/></code><br/><code><info-storage>[query]</info-storage></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 325: | Line 390: | ||
==LIST== | ==LIST== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|LIST ([path])}} | ||
|- | |- | ||
| − | | | + | | '''XML Syntax''' |
| − | | | + | |<code><list/></code><br/><code><list path='[path]'/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 341: | Line 409: | ||
==XQUERY== | ==XQUERY== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|XQUERY [query]}} | ||
|- | |- | ||
| − | + | | '''XML Syntax''' | |
| − | | | + | |<code><xquery>[query]</xquery></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 363: | Line 434: | ||
==RETRIEVE== | ==RETRIEVE== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|RETRIEVE [path]}} | ||
|- | |- | ||
| − | | | + | | '''XML Syntax''' |
| − | | | + | |<code><retrieve path='[path]'/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 379: | Line 453: | ||
==RUN== | ==RUN== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|RUN [file]}} | + | |width='100%'|{{Code|RUN [file]}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><run file='[file]'/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 395: | Line 472: | ||
==FIND== | ==FIND== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|FIND [keywords]}} | + | |width='100%'|{{Code|FIND [keywords]}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><find>[keywords]</find></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 412: | Line 492: | ||
==CS== | ==CS== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|CS [query]}} | + | |width='100%'|{{Code|CS [query]}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><cs>[query]</cs></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 428: | Line 511: | ||
==REPO INSTALL== | ==REPO INSTALL== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|REPO INSTALL [path]}} | ||
|- | |- | ||
| − | | | + | | '''XML Syntax''' |
| − | | | + | |<code><repo-install path='[path]'/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 450: | Line 536: | ||
==REPO LIST== | ==REPO LIST== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|REPO LIST}} | ||
|- | |- | ||
| − | + | | '''XML Syntax''' | |
| − | | | + | |<code><repo-list/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 463: | Line 552: | ||
==REPO DELETE== | ==REPO DELETE== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|REPO DELETE [name]}} | ||
|- | |- | ||
| − | | | + | | '''XML Syntax''' |
| − | | | + | |<code><repo-delete name='[name]'/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 481: | Line 573: | ||
==ADD== | ==ADD== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|ADD (TO [path]) [input]}} | ||
|- | |- | ||
| − | + | | '''XML Syntax''' | |
| − | | | + | |<code><add>[input]</add></code><br/><code><add path='[path]'>[input]</add></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 503: | Line 598: | ||
==DELETE== | ==DELETE== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|DELETE [path]}} | + | |width='100%'|{{Code|DELETE [path]}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><delete path='[path]'/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 519: | Line 617: | ||
==RENAME== | ==RENAME== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|RENAME [path] [newpath]}} | + | |width='100%'|{{Code|RENAME [path] [newpath]}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><rename path='[path]' newpath='[newpath]'/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 540: | Line 641: | ||
==REPLACE== | ==REPLACE== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|REPLACE [path] [input]}} | + | |width='100%'|{{Code|REPLACE [path] [input]}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><replace path='[path]'>[input]</replace></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 561: | Line 665: | ||
==STORE== | ==STORE== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|STORE (TO [path]) [input]}} | ||
|- | |- | ||
| − | + | | '''XML Syntax''' | |
| − | | | + | |<code><store>[input]</store></code><br/><code><store path='[path]'>[input]</store></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 577: | Line 684: | ||
==OPTIMIZE== | ==OPTIMIZE== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|OPTIMIZE (ALL)}} | ||
|- | |- | ||
| − | + | | '''XML Syntax''' | |
| − | | | + | |<code><optimize/></code><br/><code><optimize-all/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 593: | Line 703: | ||
==FLUSH== | ==FLUSH== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|FLUSH}} | ||
|- | |- | ||
| − | + | | '''XML Syntax''' | |
| − | | | + | |<code><flush/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 611: | Line 724: | ||
==SHOW DATABASES== | ==SHOW DATABASES== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|SHOW DATABASES}} | ||
|- | |- | ||
| − | + | | '''XML Syntax''' | |
| − | | | + | |<code><show-databases/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 624: | Line 740: | ||
==SHOW SESSIONS== | ==SHOW SESSIONS== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|SHOW SESSIONS}} | + | |width='100%'|{{Code|SHOW SESSIONS}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><show-sessions/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 637: | Line 756: | ||
==SHOW USERS== | ==SHOW USERS== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|SHOW USERS (ON [database])}} | + | |width='100%'|{{Code|SHOW USERS (ON [database])}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><show-users/></code><br/><code><show-users database='[database]'/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 653: | Line 775: | ||
==KILL== | ==KILL== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|KILL [target]}} | + | |width='100%'|{{Code|KILL [target]}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><kill target='[target]'/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 669: | Line 794: | ||
==CREATE EVENT== | ==CREATE EVENT== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|CREATE EVENT [NAME]}} | ||
|- | |- | ||
| − | + | | '''XML Syntax''' | |
| − | | | + | |<code><create-event name='[name]'/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 685: | Line 813: | ||
==SHOW EVENTS== | ==SHOW EVENTS== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|SHOW EVENTS}} | ||
|- | |- | ||
| − | + | | '''XML Syntax''' | |
| − | | | + | |<code><show-events/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 698: | Line 829: | ||
==DROP EVENT== | ==DROP EVENT== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|DROP EVENT [NAME]}} | ||
|- | |- | ||
| − | + | | '''XML Syntax''' | |
| − | | | + | |<code><drop-event name='[name]'/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 716: | Line 850: | ||
==CREATE USER== | ==CREATE USER== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|CREATE USER [name] ([password])}} | ||
|- | |- | ||
| − | | | + | | '''XML Syntax''' |
| − | + | |<code><create-user name='[name]'/></code><br/><code><create-user name='[name]' password='[password]'/></code><br/> | |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 732: | Line 869: | ||
==ALTER USER== | ==ALTER USER== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|ALTER USER [name] ([password])}} | + | |width='100%'|{{Code|ALTER USER [name] ([password])}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><alter-user name='[name]'/></code><br/><code><alter-user name='[name]' password='[password]'/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 748: | Line 888: | ||
==DROP USER== | ==DROP USER== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|DROP USER [name] (ON [database])}}: | + | |width='100%'|{{Code|DROP USER [name] (ON [database])}}: |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><drop-user name='[name]'/></code><br/><code><drop-user name='[name]' database='[database]'/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 764: | Line 907: | ||
==GRANT== | ==GRANT== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|GRANT [NONE|READ|WRITE|CREATE|ADMIN] (ON [database]) TO [user]}} | + | |width='100%'|{{Code|GRANT [NONE|READ|WRITE|CREATE|ADMIN] (ON [database]) TO [user]}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><grant name='[name]' permission='none|read|write|create|admin'/></code><br/><code><grant name='[name]' database='[database]' permission='none|read|write|create|admin'/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 785: | Line 931: | ||
==PASSWORD== | ==PASSWORD== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|PASSWORD ([password])}} | ||
|- | |- | ||
| − | + | | '''XML Syntax''' | |
| − | | | + | |<code><password/></code><br/><code><password>[password]</password></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 804: | Line 953: | ||
==GET== | ==GET== | ||
{{Mark|Updated in Version 7.2.1:}} permission changed from {{Code|READ}} to {{Code|NONE}} | {{Mark|Updated in Version 7.2.1:}} permission changed from {{Code|READ}} to {{Code|NONE}} | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|GET [option]}} | ||
|- | |- | ||
| − | | | + | | '''XML Syntax''' |
| − | | | + | |<code><get option='[option]'/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 821: | Line 973: | ||
==SET== | ==SET== | ||
{{Mark|Updated in Version 7.2.1:}} permission changed from {{Code|READ}} to {{Code|NONE}} | {{Mark|Updated in Version 7.2.1:}} permission changed from {{Code|READ}} to {{Code|NONE}} | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|SET [option] ([value])}} | ||
|- | |- | ||
| − | | | + | | '''XML Syntax''' |
| − | + | |<code><set option='[option]'/></code><br/><code><set option='[option]'>[value]</set></code><br/> | |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 837: | Line 992: | ||
==INFO== | ==INFO== | ||
| − | {| | + | {| width='100%' |
| + | |- | ||
| + | | '''Syntax''' | ||
| + | |width='100%'|{{Code|INFO}} | ||
|- | |- | ||
| − | + | | '''XML Syntax''' | |
| − | | | + | |<code><info/></code><br/> |
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 850: | Line 1,008: | ||
==HELP== | ==HELP== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|HELP ([command])}} | + | |width='100%'|{{Code|HELP ([command])}} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><help/></code><br/><code><help>[command]</help></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 866: | Line 1,027: | ||
==EXIT== | ==EXIT== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | | + | | '''Syntax''' |
| − | |{{Code|EXIT }} | + | |width='100%'|{{Code|EXIT }} |
| + | |- | ||
| + | | '''XML Syntax''' | ||
| + | |<code><exit/></code><br/> | ||
|- | |- | ||
| '''Permission''' | | '''Permission''' | ||
| Line 879: | Line 1,043: | ||
=Changelog= | =Changelog= | ||
| + | |||
| + | ;Version 7.3 | ||
| + | |||
| + | * Added: XML Syntax added | ||
;Version 7.2.1 | ;Version 7.2.1 | ||
Revision as of 23:12, 7 June 2012
This article is part of 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.
Contents
Conventions
Multiple commands can be separated by semicolons.
XML Syntax
In addition to the string syntax, database commands can also be formulated in XML. All commands are surrounded by a <commands/> root element. The following XML script creates a database, adds two documents and performs a query:
<commands> <create-db name='test'/> <add>input.xml</add> <add path='embedded.xml'><root>Embedded Document</root></add> <xquery>count(//text())</xquery> </commands>
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 charactersABand one more character.*ABaddresses 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}.
Aliases
In all commands, the DB keyword can be replaced by DATABASE.
Database Operations
CREATE DB
| Syntax | CREATE DB [name] ([input])
|
| XML Syntax | <create-db name='[name]'/><create-db name='[name]'>[input]</create-db> |
| 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
| Syntax | OPEN [path]
|
| XML Syntax | <open path='[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
| Syntax | CHECK [input]
|
| XML Syntax | <check input='[input]'/> |
| Permission | READ/CREATE |
| Summary | This command combines OPEN and CREATE DB: 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
| Syntax | CLOSE
|
| XML Syntax | <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
| Syntax | EXPORT [path]
|
| XML Syntax | <export path='[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
| Syntax | CREATE INDEX [TEXT|ATTRIBUTE|FULLTEXT]
|
| XML Syntax | 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
| Syntax | DROP INDEX [TEXT|ATTRIBUTE|FULLTEXT]
|
| XML Syntax | 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 DB
| Syntax | ALTER DB [name] [newname]
|
| XML Syntax | <alter-db name='[name]' newname='[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 DB
| Syntax | DROP DB [name]
|
| XML Syntax | <drop-db name='[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
| Syntax | CREATE BACKUP [name]
|
| XML Syntax | <create-backup name='[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
| Syntax | RESTORE [name]
|
| XML Syntax | <restore name='[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
| Syntax | DROP BACKUP [name]
|
| XML Syntax | <drop-backup name='[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
| Syntax | SHOW BACKUPS
|
| XML Syntax | <show-backups/> |
| Permission | CREATE |
| Summary | Shows all database backups. |
COPY
| Syntax | COPY [name] [newname]
|
| XML Syntax | <copy name='[name]' newname='[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 DB
| Syntax | INFO DB
|
| XML Syntax | <info-db/> |
| Permission | READ |
| Summary | Shows information on the currently opened database. |
| Errors | The command fails if no database is opened. |
INFO INDEX
| Syntax | INFO INDEX ([TEXT|ATTRIBUTE|FULLTEXT|PATH])
|
| XML Syntax | attname|path|text|attribute|fulltext'/> |
| 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
| Syntax | INFO STORAGE [start end] | [query]
|
| XML Syntax | <info-storage/><info-storage start='[start]' end='[end]'/><info-storage>[query]</info-storage> |
| 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
| Syntax | LIST ([path])
|
| XML Syntax | <list/><list path='[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
| Syntax | XQUERY [query]
|
| XML Syntax | <xquery>[query]</xquery> |
| 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
| Syntax | RETRIEVE [path]
|
| XML Syntax | <retrieve path='[path]'/> |
| 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
| Syntax | RUN [file]
|
| XML Syntax | <run file='[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
| Syntax | FIND [keywords]
|
| XML Syntax | <find>[keywords]</find> |
| 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
| Syntax | CS [query]
|
| XML Syntax | <cs>[query]</cs> |
| 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
| Syntax | REPO INSTALL [path]
|
| XML Syntax | <repo-install path='[path]'/> |
| Permission | CREATE (Template:Mark: ADMIN) |
| Summary | Installs the package with path [path].
|
| Errors | The command fails in the following cases:
|
REPO LIST
| Syntax | REPO LIST
|
| XML Syntax | <repo-list/> |
| Permission | READ (Template:Mark: ADMIN) |
| Summary | Lists all installed packages. |
REPO DELETE
| Syntax | REPO DELETE [name]
|
| XML Syntax | <repo-delete name='[name]'/> |
| Permission | CREATE (Template:Mark: ADMIN) |
| Summary | Deletes the package with name [name], optionally followed by a version.
|
| Errors | The command fails if the package to be deleted participates in a dependency. |
Updates
ADD
| Syntax | ADD (TO [path]) [input]
|
| XML Syntax | <add>[input]</add><add path='[path]'>[input]</add> |
| 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
| Syntax | DELETE [path]
|
| XML Syntax | <delete path='[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
| Syntax | RENAME [path] [newpath]
|
| XML Syntax | <rename path='[path]' newpath='[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
| Syntax | REPLACE [path] [input]
|
| XML Syntax | <replace path='[path]'>[input]</replace> |
| 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
| Syntax | STORE (TO [path]) [input]
|
| XML Syntax | <store>[input]</store><store path='[path]'>[input]</store> |
| 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
| Syntax | OPTIMIZE (ALL)
|
| XML Syntax | <optimize/><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
| Syntax | FLUSH
|
| XML Syntax | <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
| Syntax | SHOW DATABASES
|
| XML Syntax | <show-databases/> |
| Permission | ADMIN |
| Summary | Shows all databases that are opened in the current server instance. |
SHOW SESSIONS
| Syntax | SHOW SESSIONS
|
| XML Syntax | <show-sessions/> |
| Permission | ADMIN |
| Summary | Shows all sessions that are connected to the current server instance. |
SHOW USERS
| Syntax | SHOW USERS (ON [database])
|
| XML Syntax | <show-users/><show-users database='[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
| Syntax | KILL [target]
|
| XML Syntax | <kill target='[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
| Syntax | CREATE EVENT [NAME]
|
| XML Syntax | <create-event name='[name]'/> |
| Permission | ADMIN |
| Summary | Creates the specified event. |
| Errors | The command fails if event already exists. |
SHOW EVENTS
| Syntax | SHOW EVENTS
|
| XML Syntax | <show-events/> |
| Permission | ADMIN |
| Summary | Shows all events that have been registered in the database. |
DROP EVENT
| Syntax | DROP EVENT [NAME]
|
| XML Syntax | <drop-event name='[name]'/> |
| Permission | ADMIN |
| Summary | Drops the specified event. |
| Errors | The command fails if the event doesn't exist. |
User Management
CREATE USER
| Syntax | CREATE USER [name] ([password])
|
| XML Syntax | <create-user name='[name]'/><create-user name='[name]' password='[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
| Syntax | ALTER USER [name] ([password])
|
| XML Syntax | <alter-user name='[name]'/><alter-user name='[name]' password='[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
| Syntax | DROP USER [name] (ON [database]):
|
| XML Syntax | <drop-user name='[name]'/><drop-user name='[name]' database='[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
| Syntax | GRANT [NONE|READ|WRITE|CREATE|ADMIN] (ON [database]) TO [user]
|
| XML Syntax | read|write|create|admin'/><grant name='[name]' database='[database]' permission='none|read|write|create|admin'/> |
| 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
| Syntax | PASSWORD ([password])
|
| XML Syntax | <password/><password>[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
| Syntax | GET [option]
|
| XML Syntax | <get option='[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
| Syntax | SET [option] ([value])
|
| XML Syntax | <set option='[option]'/><set option='[option]'>[value]</set> |
| 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
| Syntax | INFO
|
| XML Syntax | <info/> |
| Permission | READ |
| Summary | Shows global information. |
HELP
| Syntax | HELP ([command])
|
| XML Syntax | <help/><help>[command]</help> |
| 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
| Syntax | EXIT
|
| XML Syntax | <exit/> |
| Permission | NONE |
| Summary | Exits the console mode. |
Changelog
- Version 7.3
- Added: XML Syntax added
- Version 7.2.1
- Version 7.2
- Updated:
CREATE INDEX,DROP INDEX(PATHargument removed. Path summary is always available now and updated with OPTIMIZE) - Updated: permissions for
REPO DELETE,REPO INSTALLandREPO LIST
- Version 7.1
- Updated:
KILL(killing sessions by specifying IP:port)
- Version 7.0