YottaDB - Perl extension for accessing YottaDB
use YottaDB ":all"; y_set "^var", 1; # s ^var=1 y_set "var", 2, 3; # s var(2)=3 print y_get "var", 2; # w var(2) y_lock_incr (3.14, "a", 1) or die "timeout"; y_trans (sub { ok (1 == y_get '$TLEVEL'); y_trans (sub { ok (2 == y_get '$TLEVEL'); y_ok; }, "BATCH" ); ok (1 == y_get '$TLEVEL'); y_ok; }, "BATCH" );
This module gives you access to the YottaDB database engine using YottaDB's simple API. It requires that you install and setup YottaDB first.
After installing the database, setting up the environment is required for Mumps and Perl. Environment-variable ydb_gbldir is needed for Mumps and Perl. If incorrectly/not set you can't access globals or use M-Style locking and every attempt to do so will throw an exception. The installation process itself does not need ydb_gbldir by default; but "make test TEST_DB=1" needs it.
Mumps
Perl
ydb_gbldir
"make test TEST_DB=1"
I highly recommend using:
$ source "$(pkg-config --variable=prefix yottadb)"/ydb_env_set
and
$ source "$(pkg-config --variable=prefix yottadb)"/ydb_env_unset
for basic setup of environment and databases.
Rule of the thumb: If it fails in Mumps it will fail in Perl, too.
Always try getting Mumps working first.
Here we try to access a global without ydb_gbldir set in Mumps and - just for reference - Perl:
Mumps:
$ cd /tmp $ echo 'I $o(^foo(""))'|"$(pkg-config --variable=prefix yottadb)"/mumps -dir YDB> %YDB-E-ZGBLDIRACC, Cannot access global directory /tmp/$ydb_gbldir.gld. Cannot continue. %SYSTEM-E-ENO2, No such file or directory YDB>
Perl:
$ cd /tmp $ perl -MYottaDB=:all -e 'y_next ("^foo","")' YottaDB-Error: -150374122 150374122,(SimpleAPI),%YDB-E-ZGBLDIRACC, Cannot access global directory /tmp/$ydb_gbldir.gld. Cannot continue.,%SYSTEM-E-ENO2, No such file or directory at -e line 1.
Installing the YottaDB module from the git repository:
$ # sudo apt install make libextutils-pkgconfig-perl libjson-perl $ git clone https://gitlab.com/oesiman/yottadb-perl.git $ cd yottadb-perl $ perl Makefile.PL $ make $ make test $ make test TEST_DB=1 # optional, accesses database $ sudo make install
DO NOT USE THIS MODULE ON PRODUCTION SYSTEMS.
The y_data function returns in $data:
$data
0 - no value and no subtree 1 - has a value but no subtree 10 - no value but a subtree 11 - a value and a subtree exists
The y_killall function kills all local variables.
The y_kill_excl function deletes all local variables except the specified one(s). y_kill_excl without arguments is the same as y_killall.
Deletes a node but not a subtree.
Deletes a node and all subtrees.
Sets the variable to $value
$value
Sets $value to the value of $var [, @subs]. Returns undef if not defined.
Sets $value to the value of $var [, @subs]. Croaks if it is not defined.
Returns the next subscript or undef if there is none. Here a sample "order-loop":
my $x = ""; while (defined ($x = y_next "^global", "subscript", $x)) { # ... do something with $x ... }
Returns the previous subscript or undef if there is none.
Returns the next node or the empty list if there is none.
Returns the previous node or the empty list if there is none.
Increments $var [, @subs] by $increment and returns the result in $incval.
$increment
$incval
Decodes the $zwr_encoded_string to $string.
$zwr_encoded_string
$string
Encodes $string in zwr-format.
Release all locks held. If globals are specified lock all and return 1 if succeed or 0 if it's not possible to lock all references within $timeout, return 1 if it fails. Example:
y_lock 0, ["^temp", 1, "two"], ["^temp", 3] or die "can't lock";
Try to gain lock on $var [, @subs] for $timeout seconds if not held. Increment lock counter otherwise. $timeout may be 0.0001 for example. Returns 1 on timeout 0 otherwise.
$timeout
Decrement lock count on $var [, @subs] and release the lock if it goes 0.
Run a transaction. :)
This module depends on JSON for ydb_json_import. Install it on Debian:
ydb_json_import
# apt-get install libjson-perl
or via CPAN:
# cpan JSON
https://yottadb.com
Stefan Traby <stefan@hello-penguin.com>
Copyright (C) 2018, 2019, 2020 by Stefan Traby
This library is free software; you can redistribute it and/or modify it under terms of the GNU Affero General Public License Version 3.
To install YottaDB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm YottaDB
CPAN shell
perl -MCPAN -e shell install YottaDB
For more information on module installation, please visit the detailed CPAN module installation guide.