odbc_driver.go 720 B

12345678910111213141516171819202122232425262728293031323334
  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. "strings"
  8. "github.com/go-xorm/core"
  9. )
  10. type odbcDriver struct {
  11. }
  12. func (p *odbcDriver) Parse(driverName, dataSourceName string) (*core.Uri, error) {
  13. kv := strings.Split(dataSourceName, ";")
  14. var dbName string
  15. for _, c := range kv {
  16. vv := strings.Split(strings.TrimSpace(c), "=")
  17. if len(vv) == 2 {
  18. switch strings.ToLower(vv[0]) {
  19. case "database":
  20. dbName = vv[1]
  21. }
  22. }
  23. }
  24. if dbName == "" {
  25. return nil, errors.New("no db name provided")
  26. }
  27. return &core.Uri{DbName: dbName, DbType: core.MSSQL}, nil
  28. }