forked from SAP/cgo-ase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.go
61 lines (50 loc) · 1.43 KB
/
driver.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
58
59
60
61
// SPDX-FileCopyrightText: 2020 SAP SE
// SPDX-FileCopyrightText: 2021 SAP SE
// SPDX-FileCopyrightText: 2022 SAP SE
// SPDX-FileCopyrightText: 2023 SAP SE
//
// SPDX-License-Identifier: Apache-2.0
package ase
/*
#cgo CFLAGS: -I${SRCDIR}/includes
#cgo LDFLAGS: -lsybct64 -lsybct_r64 -lsybcs_r64 -lsybtcl_r64 -lsybcomn_r64 -lsybintl_r64 -lsybunic64
#cgo LDFLAGS: -Wl,-rpath,\$ORIGIN/../lib
#include <stdlib.h>
#include "ctlib.h"
#include "bridge.h"
*/
import "C"
import (
"database/sql"
"database/sql/driver"
"fmt"
"github.com/SAP/go-dblib/dsn"
)
// Interface satisfaction checks.
var (
_ driver.Driver = (*aseDrv)(nil)
drv = &aseDrv{}
)
//DriverName is the driver name to use with sql.Open for ase databases.
const DriverName = "ase"
// aseDrv is the struct on which we later call Open() to get a connection.
type aseDrv struct{}
func init() {
sql.Register(DriverName, drv)
}
// Open implements the driver.Driver interface.
func (d *aseDrv) Open(name string) (driver.Conn, error) {
info := new(Info)
if err := dsn.Parse(name, info); err != nil {
return nil, fmt.Errorf("error parsing DSN: %w", err)
}
return NewConnection(nil, info)
}
// OpenConnector implements the driver.DriverContext interface.
func (d *aseDrv) OpenConnector(name string) (driver.Connector, error) {
info := new(Info)
if err := dsn.Parse(name, info); err != nil {
return nil, fmt.Errorf("error parsing DSN: %w", err)
}
return NewConnector(info)
}