odbc_driver.go 791 B

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