dsn.go
func GenODBC(u *URL) (string, error) {
	q := u.Query()

	host, port, dbname := hostname(u.Host), hostport(u.Host), strings.TrimPrefix(u.Path, "/")

	// save host, port, dbname
	if u.hostPortDB == nil {
		u.hostPortDB = []string{host, port, dbname}
	}

	q.Set("Driver", "{"+strings.Replace(u.Proto, "+", " ", -1)+"}")
	q.Set("Server", host)

	if port == "" {
		proto := strings.ToLower(u.Proto)
		switch {
		case strings.Contains(proto, "mysql"):
			q.Set("Port", "3306")
		case strings.Contains(proto, "postgres"):
			q.Set("Port", "5432")
		case strings.Contains(proto, "db2") || strings.Contains(proto, "ibm"):
			q.Set("ServiceName", "50000")
		default:
			q.Set("Port", "1433")
		}
	} else {
		q.Set("Port", port)
	}
	q.Set("Database", dbname)

	// add user/pass
	if u.User != nil {
		q.Set("UID", u.User.Username())
		p, _ := u.User.Password()
		q.Set("PWD", p)
	}

	return genOptionsODBC(q, true), nil
}
func GenODBC(u *URL) (string, error) {
	q := u.Query()

	host, port, dbname := hostname(u.Host), hostport(u.Host), strings.TrimPrefix(u.Path, "/")

	// save host, port, dbname
	if u.hostPortDB == nil {
		u.hostPortDB = []string{host, port, dbname}
	}

	q.Set("Driver", "{"+strings.Replace(u.Proto, "+", " ", -1)+"}")
	q.Set("Server", host)

	if port == "" {
		proto := strings.ToLower(u.Proto)
		switch {
		case strings.Contains(proto, "mysql"):
			q.Set("Port", "3306")
		case strings.Contains(proto, "postgres"):
			q.Set("Port", "5432")
		case strings.Contains(proto, "db2") || strings.Contains(proto, "ibm"):
			q.Set("ServiceName", "50000")
		default:
			q.Set("Port", "1433")
		}
	} else {
		q.Set("Port", port)
	}
	q.Set("Database", dbname)

	// add user/pass
	if u.User != nil {
		q.Set("UID", u.User.Username())
		p, _ := u.User.Password()
		q.Set("PWD", p)
	}

	return genOptionsODBC(q, true), nil
}
func GenODBC ( u * URL ) ( string , error ) { q := u . Query ( ) host , port , dbname := hostname ( u . Host ) , hostport ( u . Host ) , strings . TrimPrefix ( u . Path , " " ) // save host, port, dbname if u . hostPortDB == nil { u . hostPortDB = [ ] string { host , port , dbname } } q . Set ( " " , " " + strings . Replace ( u . Proto , " " , " " , - 1 ) + " " ) q . Set ( " " , host ) if port == " " { proto := strings . ToLower ( u . Proto ) switch { case strings . Contains ( proto , " " ) : q . Set ( " " , " " ) case strings . Contains ( proto , " " ) : q . Set ( " " , " " ) case strings . Contains ( proto , " " ) || strings . Contains ( proto , " " ) : q . Set ( " " , " " ) default : q . Set ( " " , " " ) } } else { q . Set ( " " , port ) } q . Set ( " " , dbname ) // add user/pass if u . User != nil { q . Set ( " " , u . User . Username ( ) ) p , _ := u . User . Password ( ) q . Set ( " " , p ) } return genOptionsODBC ( q , true ) , nil }
// GenODBC generates a odbc DSN from the passed URL.
GenODBC generates a odbc DSN from the passed URL .