Content files added
[stands-website.git] / content / stands / yottadb / hello_world.md
1 ---
2 title: "Hello World Examples"
3 draft: false
4 ---
5
6 The following sections discuss YottaDB's Multi-Language support via a simple `sayHello` example. Each language uses its own sample program to add a node in the same database. Then the MUPIP EXTRACT command is used to display the contents of that database, successfully showing YottaDB being accessed by different APIs/ wrappers.
7
8 ## Access from C
9
10 YottaDB comes with a [C API](https://docs.yottadb.com/MultiLangProgGuide/cprogram.html) and all you need to use it is the gcc compiler. The `sayhelloC.c` program is downloaded, compiled and run. Notice that it sets a node in the database (the MUPIP EXTRACT command prints database contents):
11
12 ```bash
13 yottadbuser@yottadbworkshop:~$ ls -l
14 total 52
15 -rw-r--r-- 1 root root 262 Jan 17 2020 sayhelloC.c
16 -rwxr-xr-x 1 yottadbuser yottadbuser 47020 Aug 26 14:00 ydbinstall.sh
17 yottadbuser@yottadbworkshop:~$ gcc $(pkg-config --libs --cflags yottadb) -o sayhelloC sayhelloC.c -lyottadb
18 yottadbuser@yottadbworkshop:~$ ls -l
19 total 72
20 -rwxr-xr-x 1 yottadbuser yottadbuser 16600 Aug 26 14:41 sayhelloC
21 -rw-r--r-- 1 root root 262 Jan 17 2020 sayhelloC.c
22 -rwxr-xr-x 1 yottadbuser yottadbuser 47020 Aug 26 14:00 ydbinstall.sh
23 yottadbuser@yottadbworkshop:~$ ./sayhelloC
24 yottadbuser@yottadbworkshop:~$ mupip extract -format=zwr -label="Hello label" -select=hello -stdout
25 Hello label UTF-8
26 26-AUG-2020 15:00:13 ZWR
27 ^hello("C")="Hello, world!"
28 %YDB-I-RECORDSTAT, ^hello: Key cnt: 1 max subsc len: 10 max rec len: 13 max node len: 27
29 %YDB-I-RECORDSTAT, TOTAL: Key cnt: 1 max subsc len: 10 max rec len: 13 max node len: 27
30 yottadbuser@yottadbworkshop:~$
31 ```
32
33 ## Access from Go
34
35 [Accessing YottaDB from Go](https://docs.yottadb.com/MultiLangProgGuide/goprogram.html) requires the Go yottadb package to be downloaded and installed. The `sayhelloGo.go` program is downloaded, compiled and run. Notice that it too sets a node in the database:
36
37 ```bash
38 yottadbuser@yottadbworkshop:~$ go build sayhelloGo.go
39 yottadbuser@yottadbworkshop:~$ ./sayhelloGo
40 yottadbuser@yottadbworkshop:~$ mupip extract -format=zwr -label="Hello" -select=hello -stdout
41 YottaDB MUPIP EXTRACT /usr/local/lib/yottadb/r130/mupip extract -format=zwr -select=hello -stdout UTF-8
42 26-AUG-2020 15:08:23 ZWR
43 ^hello("C")="Hello, world!"
44 ^hello("Go")="สวัสดีชาวโลก"
45 %YDB-I-RECORDSTAT, ^hello: Key cnt: 2 max subsc len: 11 max rec len: 36 max node len: 44
46 %YDB-I-RECORDSTAT, TOTAL: Key cnt: 2 max subsc len: 11 max rec len: 36 max node len: 44
47 yottadbuser@yottadbworkshop:~$
48 ```
49
50 ## Access from M
51
52 YottaDB includes a complete language implementation for M. The `sayhelloM.m` program is downloaded and run (there is no need for a separate compilation step, as there was for C and Go):
53
54 ```bash
55 yottadbuser@yottadbworkshop:~/.yottadb$ ls -l r
56 total 4
57 -rw-r--r-- 1 yottadbuser yottadbuser 67 Jan 17 2020 sayhelloM.m
58 yottadbuser@yottadbworkshop:~/.yottadb$ yottadb -run sayhelloM
59 yottadbuser@yottadbworkshop:~/.yottadb$ mupip extract -format=zwr -label="Hello" -select=hello -stdout
60 YottaDB MUPIP EXTRACT /usr/local/lib/yottadb/r130/mupip extract -format=zwr -select=hello -stdout UTF-8
61 26-AUG-2020 15:12:49 ZWR
62 ^hello("C")="Hello, world!"
63 ^hello("Go")="สวัสดีชาวโลก"
64 ^hello("M")="Приветствую, мир!"
65 %YDB-I-RECORDSTAT, ^hello: Key cnt: 3 max subsc len: 11 max rec len: 36 max node len: 44
66 %YDB-I-RECORDSTAT, TOTAL: Key cnt: 3 max subsc len: 11 max rec len: 36 max node len: 44
67 yottadbuser@yottadbworkshop:~/.yottadb$
68 ```
69
70 ## Access from Perl
71
72 YottaDB can also be accessed from Perl, which requires the Perl yottadb package to be downloaded and installed, to provide a YottaDB Perl “wrapper”.
73
74 The `sayhelloPerl.pl` program is downloaded, marked as an executable and run.
75
76 ```bash
77 yottadbuser@yottadbworkshop:~$ ls -l
78 total 3176
79 drwxr-xr-x 4 yottadbuser yottadbuser 4096 Aug 26 14:42 go
80 -rwxr-xr-x 1 yottadbuser yottadbuser 16600 Aug 26 14:41 sayhelloC
81 -rw-r--r-- 1 root root 262 Jan 17 2020 sayhelloC.c
82 -rwxr-xr-x 1 yottadbuser yottadbuser 3164920 Aug 26 14:44 sayhelloGo
83 -rw-r--r-- 1 yottadbuser yottadbuser 203 Jan 17 2020 sayhelloGo.go
84 -rw-r--r-- 1 yottadbuser yottadbuser 86 Aug 26 15:21 sayhelloPerl.pl
85 -rwxr-xr-x 1 yottadbuser yottadbuser 47020 Aug 26 14:00 ydbinstall.sh
86 yottadbuser@yottadbworkshop:~$ chmod +x sayhelloPerl.pl
87 yottadbuser@yottadbworkshop:~$ ./sayhelloPerl.pl.
88 yottadbuser@yottadbworkshop:~$ mupip extract -format=zwr -select=hello -stdout
89 YottaDB MUPIP EXTRACT /usr/local/lib/yottadb/r130/mupip extract -format=zwr -select=hello -stdout UTF-8
90 26-AUG-2020 15:24:21 ZWR
91 ^hello("C")="Hello, world!"
92 ^hello("Go")="สวัสดีชาวโลก"
93 ^hello("M")="Приветствую, мир!"
94 ^hello("Perl")="Grüẞ Gott Welt"
95 %YDB-I-RECORDSTAT, ^hello: Key cnt: 4 max subsc len: 13 max rec len: 36 max node len: 44
96 %YDB-I-RECORDSTAT, TOTAL: Key cnt: 4 max subsc len: 13 max rec len: 36 max node len: 44
97 yottadbuser@yottadbworkshop:~$
98 ```
99
100 ## Access from Rust
101
102 YottaDB can also be accessed from Rust, using the YottaDB wrapper for Rust [YDBRust](https://gitlab.com/YottaDB/Lang/YDBRust). Run the `say_hello_rust` example, which will add another node in the database:
103
104 ```bash
105 yottadbuser@yottadbworkshop:~$ git clone --quiet https://gitlab.com/YottaDB/Lang/YDBRust/ # Do this only once for the Acculturation Guide
106 yottadbuser@yottadbworkshop:~$ cd YDBRust
107 yottadbuser@yottadbworkshop:~/YDBRust$ cargo run --quiet --example say_hello_rust # May take some time the first time
108 yottadbuser@yottadbworkshop:~/YDBRust$ mupip extract -format=zwr -select=hello -stdout
109 YottaDB MUPIP EXTRACT /usr/local/lib/yottadb/r130/mupip extract -format=zwr -select=hello -stdout UTF-8
110 28-AUG-2020 15:34:04 ZWR
111 ^hello("C")="Hello, world!"
112 ^hello("Go")="สวัสดีชาวโลก"
113 ^hello("M")="Приветствую, мир!"
114 ^hello("Perl")="Grüẞ Gott Welt"
115 ^hello("Rust")="こんにちは"
116 %YDB-I-RECORDSTAT, ^hello: Key cnt: 5 max subsc len: 13 max rec len: 36 max node len: 44
117 %YDB-I-RECORDSTAT, TOTAL: Key cnt: 5 max subsc len: 13 max rec len: 36 max node len: 44
118 yottadbuser@yottadbworkshop:~/YDBRust$
119 ```