// QuoteSimpleTableName quotes a simple table name.
// A simple table name does not contain any schema prefix.
508032
func (b *BaseBuilder) QuoteSimpleTableName(s string) string {
	if strings.Contains(s, `"`) {
		return s
	}
	return `"` + s + `"`
}
214475
func (b *MysqlBuilder) QuoteSimpleColumnName(s string) string {
	if strings.Contains(s, "`") || s == "*" {
		return s
	}
	return "`" + s + "`"
}
310700
func (s *ConditionCheck) SetTableName(v string) *ConditionCheck {
	s.TableName = &v
	return s
}
1251538
func (s *Delete) SetTableName(v string) *Delete {
	s.TableName = &v
	return s
}
152286
func (scope *Scope) TableName() string {
	if scope.Search != nil && len(scope.Search.tableName) > 0 {
		return scope.Search.tableName
	}

	if tabler, ok := scope.Value.(tabler); ok {
		return tabler.TableName()
	}

	if tabler, ok := scope.Value.(dbTabler); ok {
		return tabler.TableName(scope.db)
	}

	return scope.GetModelStruct().TableName(scope.db.Model(scope.Value))
}
444721
func (pb *primitiveBuilder) buildTablePrimitive(tableExpr *sqlparser.AliasedTableExpr, tableName sqlparser.TableName) error {
	alias := tableName
	if !tableExpr.As.IsEmpty() {
		alias = sqlparser.TableName{Name: tableExpr.As}
	}
	sel := &sqlparser.Select{From: sqlparser.TableExprs([]sqlparser.TableExpr{tableExpr})}

	if systemTable(tableName.Qualifier.String()) {
		ks, err := pb.vschema.DefaultKeyspace()
		if err != nil {
			return err
		}
		rb, st := newRoute(sel)
		rb.routeOptions = []*routeOption{newSimpleRouteOption(rb, engine.NewSimpleRoute(engine.SelectDBA, ks))}
		pb.bldr, pb.st = rb, st
		return nil
	}

	vschemaTables, vindex, _, destTableType, destTarget, err := pb.vschema.FindTablesOrVindex(tableName)
	if err != nil {
		return err
	}
	if vindex != nil {
		pb.bldr, pb.st = newVindexFunc(alias, vindex)
		return nil
	}

	rb, st := newRoute(sel)
	pb.bldr, pb.st = rb, st
	vindexMaps, err := st.AddVSchemaTable(alias, vschemaTables, rb)
	if err != nil {
		return err
	}
	for i, vst := range vschemaTables {
		sub := &tableSubstitution{
			oldExpr: tableExpr,
		}
		if tableExpr.As.IsEmpty() {
			if tableName.Name != vst.Name {
				// Table name does not match. Change and alias it to old name.
				sub.newExpr = &sqlparser.AliasedTableExpr{
					Expr: sqlparser.TableName{Name: vst.Name},
					As:   tableName.Name,
				}
			}
		} else {
			// Table is already aliased.
			if tableName.Name != vst.Name {
				// Table name does not match. Change it and reuse existing alias.
				sub.newExpr = &sqlparser.AliasedTableExpr{
					Expr: sqlparser.TableName{Name: vst.Name},
					As:   tableExpr.As,
				}
			}
		}
		var eroute *engine.Route
		switch {
		case vst.Type == vindexes.TypeSequence:
			eroute = engine.NewSimpleRoute(engine.SelectNext, vst.Keyspace)
		case vst.Type == vindexes.TypeReference:
			eroute = engine.NewSimpleRoute(engine.SelectReference, vst.Keyspace)
		case !vst.Keyspace.Sharded:
			eroute = engine.NewSimpleRoute(engine.SelectUnsharded, vst.Keyspace)
		case vst.Pinned == nil:
			eroute = engine.NewSimpleRoute(engine.SelectScatter, vst.Keyspace)
			eroute.TargetDestination = destTarget
			eroute.TargetTabletType = destTableType
		default:
			// Pinned tables have their keyspace ids already assigned.
			// Use the Binary vindex, which is the identity function
			// for keyspace id. Currently only dual tables are pinned.
			eroute = engine.NewSimpleRoute(engine.SelectEqualUnique, vst.Keyspace)
			eroute.Vindex, _ = vindexes.NewBinary("binary", nil)
			eroute.Values = []sqltypes.PlanValue{{Value: sqltypes.MakeTrusted(sqltypes.VarBinary, vst.Pinned)}}
		}
		rb.routeOptions = append(rb.routeOptions, newRouteOption(rb, vst, sub, vindexMaps[i], eroute))
	}
	return nil
}
539242
func (engine *Engine) TableName(bean interface{}, includeSchema ...bool) string {
	tbName := engine.tbNameNoSchema(bean)
	if len(includeSchema) > 0 && includeSchema[0] {
		tbName = engine.tbNameWithSchema(tbName)
	}

	return tbName
}
431756
func (s *DescribeTimeToLiveInput) SetTableName(v string) *DescribeTimeToLiveInput {
	s.TableName = &v
	return s
}
209664
func (s *GetTableVersionsInput) SetTableName(v string) *GetTableVersionsInput {
	s.TableName = &v
	return s
}
535164
func (s *CatalogEntry) SetTableName(v string) *CatalogEntry {
	s.TableName = &v
	return s
}
520067
func (s *BatchCreatePartitionInput) SetTableName(v string) *BatchCreatePartitionInput {
	s.TableName = &v
	return s
}
62356
func (s *StreamDescription) SetTableName(v string) *StreamDescription {
	s.TableName = &v
	return s
}
138737
func (s *DeleteTableInput) SetTableName(v string) *DeleteTableInput {
	s.TableName = &v
	return s
}
1334710
func (s *QueryInput) SetTableName(v string) *QueryInput {
	s.TableName = &v
	return s
}
319049
func (s *TableVersionError) SetTableName(v string) *TableVersionError {
	s.TableName = &v
	return s
}
84616
func (s *ReferenceDataSourceDescription) SetTableName(v string) *ReferenceDataSourceDescription {
	s.TableName = &v
	return s
}
1360802
func (statement *Statement) TableName() string {
	if statement.AltTableName != "" {
		return statement.AltTableName
	}

	return statement.tableName
}