github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/go-xorm/xorm/odbc_driver.go (about)

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