791d963ea0
- Identifying textual characters sets; converting into specific type when applying dml events - Refactored `ColumnsList`: introducing `Column` type - Refactored `unsigned` handling, as part of `Column` - `Column` type supports `convertArg()`: converting value of argument according to column data type - DB URI attempts `utf8mb4,utf8,latin1` charsets in that order (first one to be recognized wins) - Local tests filter by pattern - Local tests append table schema on failure - Local tests do not have postpone flag file - Added character set local tests: `utf8`, `utf8mb4`, `latin1`
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
/*
|
|
Copyright 2016 GitHub Inc.
|
|
See https://github.com/github/gh-ost/blob/master/LICENSE
|
|
*/
|
|
|
|
package mysql
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
)
|
|
|
|
// ConnectionConfig is the minimal configuration required to connect to a MySQL server
|
|
type ConnectionConfig struct {
|
|
Key InstanceKey
|
|
User string
|
|
Password string
|
|
ImpliedKey *InstanceKey
|
|
}
|
|
|
|
func NewConnectionConfig() *ConnectionConfig {
|
|
config := &ConnectionConfig{
|
|
Key: InstanceKey{},
|
|
}
|
|
config.ImpliedKey = &config.Key
|
|
return config
|
|
}
|
|
|
|
func (this *ConnectionConfig) Duplicate() *ConnectionConfig {
|
|
config := &ConnectionConfig{
|
|
Key: InstanceKey{
|
|
Hostname: this.Key.Hostname,
|
|
Port: this.Key.Port,
|
|
},
|
|
User: this.User,
|
|
Password: this.Password,
|
|
}
|
|
config.ImpliedKey = &config.Key
|
|
return config
|
|
}
|
|
|
|
func (this *ConnectionConfig) String() string {
|
|
return fmt.Sprintf("%s, user=%s", this.Key.DisplayString(), this.User)
|
|
}
|
|
|
|
func (this *ConnectionConfig) Equals(other *ConnectionConfig) bool {
|
|
return this.Key.Equals(&other.Key) || this.ImpliedKey.Equals(other.ImpliedKey)
|
|
}
|
|
|
|
func (this *ConnectionConfig) GetDBUri(databaseName string) string {
|
|
hostname := this.Key.Hostname
|
|
var ip = net.ParseIP(hostname)
|
|
if (ip != nil) && (ip.To4() == nil) {
|
|
// Wrap IPv6 literals in square brackets
|
|
hostname = fmt.Sprintf("[%s]", hostname)
|
|
}
|
|
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4,utf8,latin1", this.User, this.Password, hostname, this.Key.Port, databaseName)
|
|
}
|