oci8_driver.go 916 B

12345678910111213141516171819202122232425262728293031323334353637
  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/go-xorm/core"
  9. )
  10. type oci8Driver struct {
  11. }
  12. //dataSourceName=user/password@ipv4:port/dbname
  13. //dataSourceName=user/password@[ipv6]:port/dbname
  14. func (p *oci8Driver) Parse(driverName, dataSourceName string) (*core.Uri, error) {
  15. db := &core.Uri{DbType: core.ORACLE}
  16. dsnPattern := regexp.MustCompile(
  17. `^(?P<user>.*)\/(?P<password>.*)@` + // user:password@
  18. `(?P<net>.*)` + // ip:port
  19. `\/(?P<dbname>.*)`) // dbname
  20. matches := dsnPattern.FindStringSubmatch(dataSourceName)
  21. names := dsnPattern.SubexpNames()
  22. for i, match := range matches {
  23. switch names[i] {
  24. case "dbname":
  25. db.DbName = match
  26. }
  27. }
  28. if db.DbName == "" {
  29. return nil, errors.New("dbname is empty")
  30. }
  31. return db, nil
  32. }