// GetMysqlPort is part of the MysqlDaemon interface
173395
func (fmd *FakeMysqlDaemon) GetMysqlPort() (int32, error) {
	if fmd.MysqlPort == -1 {
		return 0, fmt.Errorf("FakeMysqlDaemon.GetMysqlPort returns an error")
	}
	return fmd.MysqlPort, nil
}
368462
func (pdb *PrefixDB) Get(key []byte) []byte {
	return pdb.db.Get(pdb.prefix.Key(key))
}
588839
func (sqlite3 *Sqlite3DB) GetVal(key string) string {
	var val string
	sqlCmd := fmt.Sprintf("select FieldValue from %s where FieldKey = ?", sqlite3.TableName)
	rows, errDB := sqlite3.GolDB.Query(sqlCmd, key)
	if errDB != nil {
		golerror.Boohoo("Statement failed for Key "+key+" query.", false)
		return ""
	}
	for rows.Next() {
		if val != "" {
			golerror.Boohoo("Multiple Key "+key+" found. Should be Primary.", false)
			return val
		}
		if errDB = rows.Scan(&val); errDB != nil {
			golerror.Boohoo("Key "+key+" query failed.", false)
			return ""
		}
	}
	if errDB = rows.Err(); errDB != nil {
		golerror.Boohoo("Key "+key+" query failed, rows have error.", false)
	}
	rows.Close()
	return string(val)
}
117799
func (s *server) RunMysqlUpgrade(ctx context.Context, request *mysqlctlpb.RunMysqlUpgradeRequest) (*mysqlctlpb.RunMysqlUpgradeResponse, error) {
	return &mysqlctlpb.RunMysqlUpgradeResponse{}, s.mysqld.RunMysqlUpgrade()
}
605019
func (pdb *prefixDB) Get(key []byte) []byte {
	pdb.mtx.Lock()
	defer pdb.mtx.Unlock()

	pkey := pdb.prefixed(key)
	value := pdb.db.Get(pkey)
	return value
}
214635
func (t *dbTables) getCondSQL(cond *Condition, sub bool, tz *time.Location) (where string, params []interface{}) {
	if cond == nil || cond.IsEmpty() {
		return
	}

	Q := t.base.TableQuote()

	mi := t.mi

	for i, p := range cond.params {
		if i > 0 {
			if p.isOr {
				where += "OR "
			} else {
				where += "AND "
			}
		}
		if p.isNot {
			where += "NOT "
		}
		if p.isCond {
			w, ps := t.getCondSQL(p.cond, true, tz)
			if w != "" {
				w = fmt.Sprintf("( %s) ", w)
			}
			where += w
			params = append(params, ps...)
		} else {
			exprs := p.exprs

			num := len(exprs) - 1
			operator := ""
			if operators[exprs[num]] {
				operator = exprs[num]
				exprs = exprs[:num]
			}

			index, _, fi, suc := t.parseExprs(mi, exprs)
			if suc == false {
				panic(fmt.Errorf("unknown field/column name `%s`", strings.Join(p.exprs, ExprSep)))
			}

			if operator == "" {
				operator = "exact"
			}

			operSQL, args := t.base.GenerateOperatorSQL(mi, fi, operator, p.args, tz)

			leftCol := fmt.Sprintf("%s.%s%s%s", index, Q, fi.column, Q)
			t.base.GenerateOperatorLeftCol(fi, operator, &leftCol)

			where += fmt.Sprintf("%s %s ", leftCol, operSQL)
			params = append(params, args...)

		}
	}

	if sub == false && where != "" {
		where = "WHERE " + where
	}

	return
}
1186520
func (ds *MySQLDatastore) GetApp(ctx context.Context, name string) (*models.App, error) {
	row := ds.db.QueryRow(`SELECT name, config FROM apps WHERE name=?`, name)

	var resName string
	var config string
	err := row.Scan(&resName, &config)

	res := &models.App{
		Name: resName,
	}

	json.Unmarshal([]byte(config), &res.Config)

	if err != nil {
		if err == sql.ErrNoRows {
			return nil, models.ErrAppsNotFound
		}
		return nil, err
	}

	return res, nil
}
1272370
func GetSocketFromTCPConnection(ctx context.Context, dsn string) (socket string, err error) {
	db, err := sql.Open("mysql", dsn)
	if err != nil {
		return "", ErrNoSocket
	}
	defer db.Close()

	err = db.QueryRowContext(ctx, "SELECT @@socket").Scan(socket)
	if err != nil {
		return "", ErrNoSocket
	}
	if !path.IsAbs(socket) {
		return "", ErrNoSocket
	}
	if socket != "" {
		return socket, nil
	}

	return "", ErrNoSocket
}
714743
func (m *Module) GetBackend(dbname string) (backend, error) {
	ds, ok := m.config.Datasources[dbname]
	if !ok {
		return nil, fmt.Errorf("migrate: %q not configured", dbname)
	}

	migrations, err := m.getMigrationSource()
	if err != nil {
		return nil, err
	}

	// special case for parallelizing tests: add a suffix to the dbname
	if dbname == "test" {
		u, err := url.Parse(ds.DSN)
		if err != nil {
			return nil, err
		}
		database := strings.Trim(u.Path, "/")
		if m.suffixForTest == "" {
			m.suffixForTest = randomToken()
		}
		u.Path = database + "_" + m.suffixForTest
		ds.DSN = u.String()
	}
	switch ds.Driver {
	case "postgres":
		return &postgresBackend{ds, migrations}, nil
	case "mysql":
		return &mysqlBackend{ds, migrations}, nil
	}
	return nil, fmt.Errorf("migrate: unsupported driver %s", ds.Driver)
}
632858
func (mysqld *Mysqld) GetColumns(dbName, table string) ([]string, error) {
	conn, err := getPoolReconnect(context.TODO(), mysqld.dbaPool)
	if err != nil {
		return nil, err
	}
	defer conn.Recycle()
	qr, err := conn.ExecuteFetch(fmt.Sprintf("SELECT * FROM %s.%s WHERE 1=0", sqlescape.EscapeID(dbName), sqlescape.EscapeID(table)), 0, true)
	if err != nil {
		return nil, err
	}
	columns := make([]string, len(qr.Fields))
	for i, field := range qr.Fields {
		columns[i] = field.Name
	}
	return columns, nil

}
741703
func (ds *MySQLDatastore) Get(ctx context.Context, key []byte) ([]byte, error) {
	row := ds.db.QueryRow("SELECT value FROM extras WHERE id=?", key)

	var value string
	err := row.Scan(&value)
	if err == sql.ErrNoRows {
		return nil, nil
	} else if err != nil {
		return nil, err
	}

	return []byte(value), nil
}
689310
func (db *SQLDB) getTableDef(tableName string) (*types.SQLTable, error) {
	table := &types.SQLTable{
		Name: safe(tableName),
	}
	found, err := db.findTable(table.Name)
	if err != nil {
		return nil, err
	}

	if !found {
		db.Log.Info("msg", "Error table not found", "value", table.Name)
		return nil, errors.New("Error table not found " + table.Name)
	}

	query := db.DBAdapter.TableDefinitionQuery()

	db.Log.Info("msg", "QUERY STRUCTURE", "query", query, "value", table.Name)
	rows, err := db.DB.Query(query, safe(tableName))
	if err != nil {
		db.Log.Info("msg", "Error querying table structure", "err", err)
		return nil, err
	}
	defer rows.Close()

	var columns []*types.SQLTableColumn

	for rows.Next() {
		var columnName string
		var columnSQLType types.SQLColumnType
		var columnIsPK int
		var columnLength int

		if err = rows.Scan(&columnName, &columnSQLType, &columnLength, &columnIsPK); err != nil {
			db.Log.Info("msg", "Error scanning table structure", "err", err)
			return nil, err
		}

		if _, err = db.DBAdapter.TypeMapping(columnSQLType); err != nil {
			return nil, err
		}

		columns = append(columns, &types.SQLTableColumn{
			Name:    columnName,
			Type:    columnSQLType,
			Length:  columnLength,
			Primary: columnIsPK == 1,
		})
	}

	if err = rows.Err(); err != nil {
		db.Log.Info("msg", "Error during rows iteration", "err", err)
		return nil, err
	}

	table.Columns = columns
	return table, nil
}
191398
func NewMySQLLock(in *MySQLBackend, l log.Logger, key, value string) (*MySQLLock, error) {
	// Create a new MySQL connection so we can close this and have no effect on
	// the rest of the MySQL backend and any cleanup that might need to be done.
	conn, _ := NewMySQLClient(in.conf, in.logger)

	m := &MySQLLock{
		parentConn: in,
		in:         conn,
		logger:     l,
		statements: make(map[string]*sql.Stmt),
		key:        key,
		value:      value,
	}

	statements := map[string]string{
		"put": "INSERT INTO " + in.dbLockTable +
			" VALUES( ?, ? ) ON DUPLICATE KEY UPDATE current_leader=VALUES(current_leader)",
	}

	for name, query := range statements {
		if err := m.prepare(name, query); err != nil {
			return nil, err
		}
	}

	return m, nil
}
519188
func initMySQLProtocol() {
	log.Infof("initializing mysql protocol")

	// Flag is not set, just return.
	if *mysqlServerPort < 0 && *mysqlServerSocketPath == "" {
		return
	}

	// If no mysqlproxy was created, just return.
	if mysqlProxy == nil {
		log.Fatalf("mysqlProxy not initialized")
		return
	}

	// Initialize registered AuthServer implementations (or other plugins)
	for _, initFn := range pluginInitializers {
		initFn()
	}
	authServer := mysql.GetAuthServer(*mysqlAuthServerImpl)

	// Create a Listener.
	var err error
	mh := newProxyHandler(mysqlProxy)
	if *mysqlServerPort >= 0 {
		mysqlListener, err = mysql.NewListener("tcp", net.JoinHostPort(*mysqlServerBindAddress, fmt.Sprintf("%v", *mysqlServerPort)), authServer, mh, *mysqlConnReadTimeout, *mysqlConnWriteTimeout)
		if err != nil {
			log.Exitf("mysql.NewListener failed: %v", err)
		}
		if *mysqlSslCert != "" && *mysqlSslKey != "" {
			mysqlListener.TLSConfig, err = vttls.ServerConfig(*mysqlSslCert, *mysqlSslKey, *mysqlSslCa)
			if err != nil {
				log.Exitf("grpcutils.TLSServerConfig failed: %v", err)
				return
			}
		}
		mysqlListener.AllowClearTextWithoutTLS = *mysqlAllowClearTextWithoutTLS

		// Check for the connection threshold
		if *mysqlSlowConnectWarnThreshold != 0 {
			log.Infof("setting mysql slow connection threshold to %v", mysqlSlowConnectWarnThreshold)
			mysqlListener.SlowConnectWarnThreshold = *mysqlSlowConnectWarnThreshold
		}
		// Start listening for tcp
		go mysqlListener.Accept()
		log.Infof("listening on %s:%d", *mysqlServerBindAddress, *mysqlServerPort)
	}

	if *mysqlServerSocketPath != "" {
		// Let's create this unix socket with permissions to all users. In this way,
		// clients can connect to mysqlproxy mysql server without being mysqlproxy user
		oldMask := syscall.Umask(000)
		mysqlUnixListener, err = newMysqlUnixSocket(*mysqlServerSocketPath, authServer, mh)
		_ = syscall.Umask(oldMask)
		if err != nil {
			log.Exitf("mysql.NewListener failed: %v", err)
			return
		}
		// Listen for unix socket
		go mysqlUnixListener.Accept()
	}
}
298237
func (_m *Driver) GetConnection() (datastore.Connection, error) {
	ret := _m.Called()

	var r0 datastore.Connection
	if rf, ok := ret.Get(0).(func() datastore.Connection); ok {
		r0 = rf()
	} else {
		r0 = ret.Get(0).(datastore.Connection)
	}

	var r1 error
	if rf, ok := ret.Get(1).(func() error); ok {
		r1 = rf()
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
1139167
func (n *Graph) getProcPort(procName, portName string, dir reflect.ChanDir) (reflect.Value, error) {
	nilValue := reflect.ValueOf(nil)
	// Ensure process exists
	proc, ok := n.procs[procName]
	if !ok {
		return nilValue, fmt.Errorf("Connect error: process '%s' not found", procName)
	}

	// Ensure sender is settable
	val := reflect.ValueOf(proc)
	if val.Kind() == reflect.Ptr && val.IsValid() {
		val = val.Elem()
	}
	if !val.CanSet() {
		return nilValue, fmt.Errorf("Connect error: process '%s' is not settable", procName)
	}

	// Get the port value
	var portVal reflect.Value
	var err error
	// Check if sender is a net
	net, ok := val.Interface().(Graph)
	if ok {
		// Sender is a net
		if dir == reflect.SendDir {
			portVal, err = net.getOutPort(portName)
		} else {
			portVal, err = net.getInPort(portName)
		}

	} else {
		// Sender is a proc
		portVal = val.FieldByName(portName)
		if !portVal.IsValid() {
			err = errors.New("")
		}
	}
	if err != nil {
		return nilValue, fmt.Errorf("Connect error: process '%s' does not have port '%s'", procName, portName)
	}

	// Validate port type
	portType := portVal.Type()

	// Sender port can be an array port
	if dir == reflect.SendDir && portType.Kind() == reflect.Slice {
		portType = portType.Elem()
	}

	// Validate
	if portType.Kind() != reflect.Chan || portType.ChanDir()&dir == 0 {
		return nilValue, fmt.Errorf("Connect error: '%s.%s' is not of the correct chan type", procName, portName)
	}

	// Check assignability
	if !portVal.CanSet() {
		return nilValue, fmt.Errorf("'%s.%s' is not assignable", procName, portName)
	}

	return portVal, nil
}
83534
func MysqlHostname(tablet *topodatapb.Tablet) string {
	if tablet.MysqlHostname == "" {
		return tablet.Hostname
	}
	return tablet.MysqlHostname
}