Пример #1
0
// GetDSN returns a (command-line defined) connection string
func GetDSN() string {
	if !flag.Parsed() {
		flag.Parse()
		if *fDsn == "" {
			*fDsn = os.Getenv("DSN")
		}
	}

	var user, passw, sid string
	if !(fDsn == nil || *fDsn == "") {
		user, passw, sid = oracle.SplitDSN(*fDsn)
		//log.Printf("user=%q passw=%q sid=%q", user, passw, sid)
	}
	if user == "" && fUsername != nil && *fUsername != "" {
		user = *fUsername
	}
	if passw == "" && fPassword != nil && *fPassword != "" {
		passw = *fPassword
	}
	if sid == "" {
		if fSid != nil && *fSid != "" {
			sid = *fSid
		} else {
			sid = oracle.MakeDSN(*fHost, *fPort, "", *fServiceName)
		}
	}
	return user + "/" + passw + "@" + sid
}
Пример #2
0
// 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)
}
Пример #3
0
// 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
}