// GetRawConnection returns a raw (*oracle.Connection) connection // - using GetDSN if dsn is empty func GetRawConnection(dsn string) (*oracle.Connection, error) { if dsn == "" { dsn = GetDSN() } user, passw, sid := oracle.SplitDSN(dsn) conn, err := oracle.NewConnection(user, passw, sid, false) if err != nil { return conn, errgo.Mask(err) } return conn, conn.Connect(0, false) }
// Open a database. func (d *driver) Open(c *rdb.Config) (rdb.DriverConn, error) { if c.Secure { return nil, errors.New("Secure connection is not supported.") } // Establish the connection cx, err := oracle.NewConnection(c.Username, c.Password, c.Instance, false) if err != nil { return nil, err } return &conn{cx: cx}, nil }
// Open new connection. The uri need to have the following syntax: // // USER/PASSWD@SID // // SID (database identifier) can be a DSN (see goracle/oracle.MakeDSN) func (d *Driver) Open(uri string) (driver.Conn, error) { d.user, d.passwd, d.db = oracle.SplitDSN(uri) // Establish the connection cx, err := oracle.NewConnection(d.user, d.passwd, d.db, d.autocommit) if err == nil { err = cx.Connect(0, false) } if err != nil { return nil, errgo.Mask(err) } return &conn{cx: cx}, nil }
// Open new connection. The uri need to have the following syntax: // // USER/PASSWD@SID // // SID (database identifier) can be a DSN (see goracle/oracle.MakeDSN) func (d *Driver) Open(uri string) (driver.Conn, error) { p := strings.Index(uri, "/") d.user = uri[:p] q := strings.Index(uri[p+1:], "@") if q < 0 { q = len(uri) - 1 } else { q += p + 1 } d.passwd = uri[p+1 : q] d.db = uri[q+1:] // Establish the connection cx, err := oracle.NewConnection(d.user, d.passwd, d.db) if err == nil { err = cx.Connect(0, false) } if err != nil { return nil, err } return &conn{cx: &cx}, nil }
func getConnection(t *testing.T) oracle.Connection { if conn.IsConnected() { return conn } if !(dsn != nil && *dsn != "") { t.Logf("cannot test connection without dsn!") return conn } user, passw, sid := oracle.SplitDsn(*dsn) var err error log.Printf("connecting to %s", *dsn) conn, err = oracle.NewConnection(user, passw, sid) if err != nil { t.Logf("error creating connection to %s: %s", *dsn, err) t.Fail() } if err = conn.Connect(0, false); err != nil { t.Logf("error connecting: %s", err) t.Fail() } return conn }