Skip to content

Commit d07ed07

Browse files
vmathur12vmathur22
andauthored
Added INSTALL.md file and new testcases (#216)
* Added INSTALL.md and stored procedure test case Co-authored-by: Vikas Mathur <[email protected]>
1 parent ff9973e commit d07ed07

File tree

4 files changed

+385
-0
lines changed

4 files changed

+385
-0
lines changed

INSTALL.md

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
# Installing go_ibm_db
2+
3+
*Copyright (c) 2014 IBM Corporation and/or its affiliates. All rights reserved.*
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
6+
software and associated documentation files (the "Software"), to deal in the Software
7+
without restriction, including without limitation the rights to use, copy, modify,
8+
merge, publish, distribute, sublicense, and/or sell copies of the Software,
9+
and to permit persons to whom the Software is furnished to do so, subject to the
10+
following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all copies
13+
or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
18+
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
DEALINGS IN THE SOFTWARE.
21+
22+
## Contents
23+
24+
1. [Overview](#Installation)
25+
2. [ibm_db Installation on Linux](#inslnx)
26+
3. [ibm_db Installation on MacOS](#insmac)
27+
4. [ibm_db Installation on Windows](#inswin)
28+
29+
## <a name="overview"></a> 1. Overview
30+
31+
The [*go_ibm_db*](https://github.com/ibmdb/go_ibm_db) is an asynchronous/synchronous interface for GoLang to IBM DB2.
32+
33+
Following are the steps to installation in your system.
34+
35+
This go_ibm_db driver has been tested on 64-bit/32-bit IBM Linux, MacOS and Windows.
36+
37+
38+
39+
40+
41+
## <a name="inslnx"></a> 2. Go_ibm_db Installation on Linux.
42+
43+
### 2.1 Install GoLang for Linux
44+
45+
Download the
46+
[GoLang Linux binaries](https://golang.org/dl) or [Go Latest binaries](https://go.dev/dl) and
47+
extract the file, for example into `/mygo`:
48+
49+
```
50+
cd /mygo
51+
wget -c https://golang.org/dl/go1.20.5.linux-amd64.tar.gz
52+
tar -xzf go1.20.5.linux-amd64.tar.gz
53+
```
54+
55+
Set PATH to include Go:
56+
57+
```
58+
export PATH=/mygo/go/bin:$PATH
59+
```
60+
61+
### 2.2 Install go_ibm_db
62+
63+
Following are the steps to install [*go_ibm_db*](https://github.com/ibmdb/go_ibm_db) from github.
64+
using directory `/goapp` for example.
65+
66+
#### 2.2.1 Direct Installation.
67+
```
68+
1. mkdir goapp
69+
2. cd goapp
70+
3. go install github.com/ibmdb/go_ibm_db/installer@latest
71+
or
72+
go install github.com/ibmdb/go_ibm_db/[email protected]
73+
```
74+
75+
It's Done.
76+
77+
#### 2.2.2 Manual Installation by using git clone.
78+
79+
```
80+
1. mkdir goapp
81+
2. cd goapp
82+
3. git clone https://github.com/ibmdb/go_ibm_db/
83+
```
84+
85+
### 2.3 Download clidriver
86+
87+
Download clidriver in your system, use below command:
88+
go to installer folder where go_ibm_db is downloaded in your system
89+
(Example: /home/uname/go/src/github.com/ibmdb/go_ibm_db/installer or /home/uname/goapp/go_ibm_db/installer
90+
where uname is the username) and run setup.go file (go run setup.go)
91+
92+
93+
### 2.4 Set environment variables to clidriver directory path
94+
95+
#### 2.4.1 Manual
96+
```
97+
export IBM_DB_HOME=/home/uname/clidriver
98+
export CGO_CFLAGS=-I$IBM_DB_HOME/include
99+
export CGO_LDFLAGS=-L$IBM_DB_HOME/lib
100+
export LD_LIBRARY_PATH=/home/uname/clidriver/lib
101+
or
102+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$IBM_DB_HOME/lib
103+
```
104+
105+
#### 2.4.2 Script file
106+
```
107+
cd .../go_ibm_db/installer
108+
source setenv.sh
109+
```
110+
## <a name="insmac"></a> 3. Go_ibm_db Installation on MacOS.
111+
112+
### 3.1 Install GoLang for Mac
113+
114+
Download the
115+
[GoLang MacOS binaries](https://golang.org/dl) or [GoLang Latest binaries](https://go.dev/dl) and
116+
extract the file.
117+
118+
### 3.2 Install go_ibm_db
119+
120+
#### 3.2.1 Direct Installation.
121+
```
122+
1. mkdir goapp
123+
2. cd goapp
124+
3. go install github.com/ibmdb/go_ibm_db/installer@latest
125+
or
126+
go install github.com/ibmdb/go_ibm_db/[email protected]
127+
```
128+
129+
It's Done.
130+
131+
#### 3.2.2 Manual Installation by using git clone.
132+
```
133+
1. mkdir goapp
134+
2. cd goapp
135+
3. git clone https://github.com/ibmdb/go_ibm_db/
136+
```
137+
138+
### 3.3 Download clidriver
139+
140+
Download clidriver in your system, use below command:
141+
go to installer folder where go_ibm_db is downloaded in your system
142+
(Example: /home/uname/go/src/github.com/ibmdb/go_ibm_db/installer or /home/uname/goapp/go_ibm_db/installer
143+
where uname is the username) and run setup.go file (go run setup.go)
144+
145+
146+
### 3.4 Set environment variables to clidriver directory path
147+
148+
#### 3.4.1 Manual
149+
```
150+
export IBM_DB_HOME=/home/uname/clidriver
151+
export CGO_CFLAGS=-I$IBM_DB_HOME/include
152+
export CGO_LDFLAGS=-L$IBM_DB_HOME/lib
153+
154+
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/home/uname/go/src/github.com/ibmdb/clidriver/lib
155+
or
156+
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$IBM_DB_HOME/lib
157+
```
158+
159+
#### 3.4.2 Script file
160+
```
161+
cd .../go_ibm_db/installer
162+
source setenv.sh
163+
```
164+
165+
## <a name="inswin"></a> 4. Go_ibm_db Installation on Windows.
166+
167+
### 4.1 Install GoLang for Windows
168+
169+
Download the [Go Windows binary/installer](https://golang.org/dl) or [Go Latest binaries](https://go.dev/dl/) and
170+
install it.
171+
172+
### 4.2 Install go_ibm_db
173+
174+
Following are the steps to install [*go_ibm_db*](https://github.com/ibmdb/go_ibm_db) from github.
175+
using directory `/goapp` for example.
176+
177+
#### 4.2.1 Direct Installation.
178+
```
179+
1. mkdir goapp
180+
2. cd gopapp
181+
3. go install github.com/ibmdb/go_ibm_db/installer@latest
182+
or
183+
go install github.com/ibmdb/go_ibm_db/[email protected]
184+
```
185+
186+
#### 4.2.2 Manual Installation by using git clone.
187+
```
188+
1. mkdir goapp
189+
2. cd goapp
190+
3. git clone https://github.com/ibmdb/go_ibm_db/
191+
```
192+
193+
### 4.3 Download clidriver
194+
195+
Download clidriver in your system, go to installer folder where go_ibm_db is downloaded in your system, use below command:
196+
(Example: C:\Users\uname\go\src\github.com\ibmdb\go_ibm_db\installer or C:\goapp\go_ibm_db\installer
197+
where uname is the username ) and run setup.go file (go run setup.go).
198+
199+
200+
### 4.4 Set environment variables to clidriver directory path
201+
202+
#### 4.4.1 Manual
203+
```
204+
set IBM_DB_HOME=C:\Users\uname\go\src\github.com\ibmdb\clidriver
205+
set PATH=%PATH%;C:\Users\uname\go\src\github.com\ibmdb\clidriver\bin
206+
or
207+
set PATH=%PATH%;%IBM_DB_HOME%\bin
208+
```
209+
210+
### 4.4.2 Script file
211+
```
212+
cd .../go_ibm_db/installer
213+
Run setenvwin.bat
214+
```
215+
It's Done.
216+
217+
4. Download platform specific clidriver from https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/ , untar/unzip it and set `IBM_DB_HOME` environmental variable to full path of extracted 'clidriver' directory, for example if clidriver is extracted as: `/home/mysystem/clidriver`, then set system level environment variable `IBM_DB_HOME=/home/mysystem/clidriver`.
218+
219+
220+
221+
## <a name="m1chip"></a> 5. Steps to install ibm_db on MacOS M1/M2 Chip system (arm64 architecture)
222+
**Warning:** If you use the ARM version of homebrew (as recommended for M1/M2 chip systems) you will get the following error message:
223+
```
224+
$ brew install gcc-12
225+
Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
226+
Please create a new installation in /opt/homebrew using one of the
227+
"Alternative Installs" from:
228+
https://docs.brew.sh/Installation
229+
You can migrate your previously installed formula list with:
230+
brew bundle dump
231+
```
232+
Install `gcc@12` using homebrew `(note: the x86_64 version of homebrew is needed for this, not the recommended ARM based homebrew)`. The clearest instructions on how to install and use the `x86_64` version of `homebrew` is by following below steps:
233+
* My arm64/M1 brew is installed here:
234+
```
235+
$ which brew
236+
/opt/homebrew/bin/brew
237+
```
238+
* Step 1. Install x86_64 brew under /usr/local/bin/brew
239+
`arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"`
240+
* Step 2. Create an alias for the x86_64 brew
241+
I added this to my ~/.bashrc as below:
242+
```
243+
# brew hack for x86_64
244+
alias brew64='arch -x86_64 /usr/local/bin/brew'
245+
```
246+
* Then install gcc@12 using the x86_64 homebrew:
247+
```
248+
brew64 install gcc@12
249+
```
250+
* Now find location of `lib/gcc/12/libstdc++.6.dylib` file in your system. It should be inside `/usr/local/homebrew/lib/gcc/12` or `/usr/local/lib/gcc/12` or `/usr/local/homebrew/Cellar/gcc@12/12.2.0/lib/gcc/12` or something similar. You need to find the correct path.
251+
Suppose path of gcc lib is `/usr/local/homebrew/lib/gcc/12`. Then update your .bashrc/.zshrc file with below line
252+
```
253+
export DYLD_LIBRARY_PATH=/usr/local/homebrew/lib/gcc/12:$DYLD_LIBRARY_PATH
254+
```

testdata/Codeunits32_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestCodeunits32(t *testing.T) {
8+
if ChineseCharCodeunits32() != nil {
9+
t.Error("Error at ChineseCodeunits32")
10+
}
11+
}

testdata/main.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,6 +2732,20 @@ func main() {
27322732
} else {
27332733
fmt.Println("Fail")
27342734
}
2735+
2736+
result70 := StoredProcedureArray()
2737+
if result70 == nil {
2738+
fmt.Println("Pass")
2739+
} else {
2740+
fmt.Println("Fail")
2741+
}
2742+
2743+
result71 := ChineseCharCodeunits32()
2744+
if result71 == nil {
2745+
fmt.Println("Pass")
2746+
} else {
2747+
fmt.Println("Fail")
2748+
}
27352749
}
27362750

27372751
func AllDataTypes() error {
@@ -3306,8 +3320,105 @@ func Decfloat() error {
33063320
return nil
33073321
}
33083322

3323+
//StoredProcedureArray
3324+
func StoredProcedureArray() error{
3325+
db, _ := sql.Open("go_ibm_db", connStr)
3326+
3327+
var arr1 = []int{10, 20, 30, 40, 50}
3328+
var arr2 = []string{"Row 10", "Row 20", "Row 30", "Row 40", "Row 50"}
3329+
3330+
db.Exec("Drop table TT")
3331+
3332+
_, err1 := db.Exec("Drop procedure sp1(INTEGER, VARCHAR(10))")
3333+
if err1 != nil {
3334+
fmt.Println("Drop procedure error : ", err1)
3335+
return err1
3336+
}
3337+
3338+
_, err := db.Exec("create table TT(C1 INTEGER NOT NULL, C2 VARCHAR(10))");
3339+
if err != nil {
3340+
fmt.Println("Error: ", err)
3341+
return err
3342+
}
3343+
3344+
st, err := db.Prepare("create procedure sp1(in arr1 INTEGER, in arr2 VARCHAR(10)) LANGUAGE SQL BEGIN INSERT INTO TT VALUES(arr1, arr2); END")
3345+
if err != nil {
3346+
fmt.Println("Error: ", err)
3347+
return err
3348+
}
3349+
3350+
_, err = st.Query()
3351+
if !strings.Contains(fmt.Sprint(err), "did not create a result set") {
3352+
return err
3353+
}
3354+
3355+
_, err = db.Exec("CALL sp1(?,?)", arr1, arr2)
3356+
if err != nil {
3357+
fmt.Println("Error: ", err)
3358+
return err
3359+
}
3360+
/*
3361+
queryTypes := "select * from TT;"
3362+
3363+
rows, err := db.Query(queryTypes)
3364+
if err != nil {
3365+
fmt.Println("Error:", err)
3366+
return err
3367+
}
3368+
3369+
for rows.Next() {
3370+
var c1 int
3371+
var c2 string
3372+
err = rows.Scan(&c1, &c2)
3373+
if err != nil {
3374+
fmt.Println("Error:", err)
3375+
}
3376+
fmt.Printf("C1=: %v\t C2: %v\n", c1, c2)
3377+
}
3378+
*/
3379+
return nil
3380+
}
3381+
33093382

3383+
func ChineseCharCodeunits32() error {
3384+
db, _ := sql.Open("go_ibm_db", connStr)
3385+
defer db.Close()
3386+
db.Exec("Drop table TT")
3387+
_, err := db.Exec("create table TT(C1 INTEGER NOT NULL, C2 VARCHAR(5 CODEUNITS32))")
3388+
if err != nil {
3389+
return err
3390+
}
3391+
st, err := db.Prepare("Insert into TT(C1, C2) values(1,'一二三四五')")
3392+
defer st.Close()
3393+
if err != nil {
3394+
return err
3395+
}
3396+
_, err = st.Query()
3397+
if !strings.Contains(fmt.Sprint(err), "did not create a result set") {
3398+
fmt.Println("Error while inserting []string")
3399+
return err
3400+
}
3401+
/*
3402+
queryTypes := "select * from TT;"
3403+
3404+
rows, err := db.Query(queryTypes)
3405+
if err != nil {
3406+
fmt.Println("Error:", err)
3407+
return err
3408+
}
33103409
3410+
for rows.Next() {
3411+
var c1 int
3412+
var c2 string
3413+
err = rows.Scan(&c1, &c2)
3414+
if err != nil {
3415+
fmt.Println("Error:", err)
3416+
}
3417+
fmt.Printf("C1=: %v\t C2: %v\n", c1, c2)
3418+
}
33113419
3420+
*/
3421+
return nil
3422+
}
33123423

33133424

0 commit comments

Comments
 (0)