+ var dbh *sql.DB
+
+ if *flag_host != "" || *flag_socket != "" {
+ lib.Logger.Println("--host= or --socket= defined")
+ var components = make(map[string]string)
+ if *flag_host != "" && *flag_socket != "" {
+ fmt.Println(lib.MyName() + ": Do not specify --host and --socket together" )
+ os.Exit(1)
+ }
+ if *flag_host != "" {
+ components["host"] = *flag_host
+ }
+ if *flag_port != 0 {
+ if *flag_socket == "" {
+ components["port"] = fmt.Sprintf("%d", *flag_port)
+ } else {
+ fmt.Println(lib.MyName() + ": Do not specify --socket and --port together" )
+ os.Exit(1)
+ }
+ }
+ if *flag_socket != "" {
+ components["socket"] = *flag_socket
+ }
+ if *flag_user != "" {
+ components["user"] = *flag_user
+ }
+ if *flag_password != "" {
+ components["password"] = *flag_password
+ }
+ dbh = connect_by_components( components )
+ } else {
+ if flag_defaults_file != nil && *flag_defaults_file != "" {
+ lib.Logger.Println("--defaults-file defined")
+ defaults_file = *flag_defaults_file
+ } else {
+ lib.Logger.Println("connecting by implicit defaults file")
+ }
+ dbh = connect_by_defaults_file( defaults_file )