-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathload_oracle.go
57 lines (47 loc) · 1.5 KB
/
load_oracle.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"bufio"
"bytes"
"fmt"
"os"
"os/exec"
"path/filepath"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
func loadToOracle(file string) error {
fileName := filepath.Base(file)
fileNameNoExt := fileName[0 : len(fileName)-len(filepath.Ext(fileName))]
username := viper.GetString("load." + fileNameNoExt + ".userName")
password := viper.GetString("load." + fileNameNoExt + ".password")
tnsname := viper.GetString("load." + fileNameNoExt + ".tnsName")
ctlFileContent := viper.GetString("load." + fileNameNoExt + ".loadControlFile")
if username == "" || password == "" || tnsname == "" || ctlFileContent == "" {
log.Warning("Load: No config for this file: " + file)
return nil
}
//Creating control file for sqlldr
f, err := os.Create(Config.Path.Parsed + "/" + FolderName + "/" + fileNameNoExt + Config.CustomFileExtention.OracleControlFileExt)
if err != nil {
return err
}
w := bufio.NewWriter(f)
fmt.Fprint(w, ctlFileContent)
w.Flush()
f.Sync()
f.Close()
sqlldrCommand := "sqlldr" + " userid='" + username + "/" + password + "@" + tnsname + "'" +
" control='" + Config.Path.Parsed + "/" + FolderName + "/" + fileNameNoExt + ".ctl" + "'" +
" log='" + Config.Path.Parsed + "/" + FolderName + "/" + fileNameNoExt + ".log" + "'" +
" direct=true rows=" + "100000" +
" errors=" + "100"
cmd := exec.Command("sh", "-c", sqlldrCommand)
var outb, errb bytes.Buffer
cmd.Stdout = &outb
cmd.Stderr = &errb
err = cmd.Run()
if err != nil {
return err
}
return nil
}