oci8_driver.go 987 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2015 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package xorm
  5. import (
  6. "errors"
  7. "regexp"
  8. "github.com/xormplus/core"
  9. )
  10. // func init() {
  11. // core.RegisterDriver("oci8", &oci8Driver{})
  12. // }
  13. type oci8Driver struct {
  14. }
  15. //dataSourceName=user/password@ipv4:port/dbname
  16. //dataSourceName=user/password@[ipv6]:port/dbname
  17. func (p *oci8Driver) Parse(driverName, dataSourceName string) (*core.Uri, error) {
  18. db := &core.Uri{DbType: core.ORACLE}
  19. dsnPattern := regexp.MustCompile(
  20. `^(?P<user>.*)\/(?P<password>.*)@` + // user:password@
  21. `(?P<net>.*)` + // ip:port
  22. `\/(?P<dbname>.*)`) // dbname
  23. matches := dsnPattern.FindStringSubmatch(dataSourceName)
  24. names := dsnPattern.SubexpNames()
  25. for i, match := range matches {
  26. switch names[i] {
  27. case "dbname":
  28. db.DbName = match
  29. }
  30. }
  31. if db.DbName == "" {
  32. return nil, errors.New("dbname is empty")
  33. }
  34. return db, nil
  35. }