// SELECT <columns> FROM <table> WHERE ... [FOR UPDATE]
186790
func (h *sqlHelper) All(
	logger lager.Logger,
	q Queryable,
	table string,
	columns ColumnList,
	lockRow RowLock,
	wheres string,
	whereBindings ...interface{},
) (*sql.Rows, error) {
	query := fmt.Sprintf("SELECT %s FROM %s\n", strings.Join(columns, ", "), table)

	if len(wheres) > 0 {
		query += "WHERE " + wheres
	}

	if lockRow {
		query += "\nFOR UPDATE"
	}

	return q.Query(h.Rebind(query), whereBindings...)
}
54600
func (r *DB) Select(dest interface{}, query string, args ...interface{}) error {
	var err error
	exec := func() error {
		if r.Tx != nil {
			return r.Tx.SelectContext(r.ctx, dest, query, args...)
		}
		return r.DB.SelectContext(r.ctx, dest, query, args...)
	}

	r.Log(func() {
		err = exec()
	}, query, args...)

	// clear no rows returned error
	if err == sql.ErrNoRows {
		return nil
	}

	return errors.Wrap(err, "select query failed")
}
65007
func Select(selections ...Selectable) (stmt SelectStmt) {
	columns := make([]ColumnElem, 0)
	for _, selection := range selections {
		if selection == nil {
			stmt.SetError("aspect: received a nil selectable - do the columns or tables you selected exist?")
			return
		}
		columns = append(columns, selection.Selectable()...)
	}

	if len(columns) < 1 {
		stmt.SetError("aspect: must select at least one column")
		return
	}

	for _, column := range columns {
		// Adding a bad column will pass a zero-initialized ColumnElem and
		// since blank column names are invalid SQL we can reject them
		if column.Name() == "" {
			stmt.SetError("aspect: selected column does not exist")
			return
		}
		stmt.columns = append(stmt.columns, column)

		// Add the table to the stmt tables if it does not already exist
		if !stmt.TableExists(column.Table().Name()) {
			stmt.tables = append(stmt.tables, column.Table())
		}
	}
	return
}
75078
func (t *DatacentersTable) update(c context.Context) error {
	// Avoid using the database connection to prepare unnecessary statements.
	if len(t.updates) == 0 {
		return nil
	}

	db := database.Get(c)
	stmt, err := db.PrepareContext(c, `
		UPDATE datacenters
		SET description = ?, state = ?
		WHERE id = ?
	`)
	if err != nil {
		return errors.Annotate(err, "failed to prepare statement").Err()
	}
	defer stmt.Close()

	// Update each datacenter in the table. It's more efficient to update the slice of
	// datacenters once at the end rather than for each update, so use a defer.
	updated := make(map[int64]*Datacenter, len(t.updates))
	defer func() {
		for _, dc := range t.current {
			if u, ok := updated[dc.Id]; ok {
				dc.Description = u.Description
				dc.State = u.State
			}
		}
	}()
	for len(t.updates) > 0 {
		dc := t.updates[0]
		if _, err := stmt.ExecContext(c, dc.Description, dc.State, dc.Id); err != nil {
			return errors.Annotate(err, "failed to update datacenter %q", dc.Name).Err()
		}
		updated[dc.Id] = dc
		t.updates = t.updates[1:]
		logging.Infof(c, "Updated datacenter %q", dc.Name)
	}
	return nil
}
812242
func (me *DefaultAdapter) SelectSql(buf *SqlBuilder, cols ColumnList) error {
	buf.Write(me.SelectClause)
	buf.WriteRune(space_rune)
	if len(cols.Columns()) == 0 {
		buf.WriteRune(star_rune)
	} else {
		return me.Literal(buf, cols)
	}
	return nil
}
1366935
func (me *DefaultAdapter) ColumnListSql(buf *SqlBuilder, columnList ColumnList) error {
	cols := columnList.Columns()
	colLen := len(cols)
	for i, col := range cols {
		if err := me.Literal(buf, col); err != nil {
			return err
		}
		if i < colLen-1 {
			buf.WriteRune(comma_rune)
			buf.WriteRune(space_rune)
		}
	}
	return nil
}
1144895
func (row *Row) GetUpdateColumns() []string {
	escapedColumns := make([]string, len(row.updateColumns))
	for i, updateColumn := range row.updateColumns {
		escapedColumns[i] = fmt.Sprintf("\"%s\"", updateColumn)
	}
	return escapedColumns
}
1169373
func Update(db DB, table string, src interface{}) error {
	return Default.Update(db, table, src)
}
364366
func (db *DB) Select(dest interface{}, query string, args ...interface{}) error {
	return Select(db, dest, query, args...)
}
407808
func (r *Release) Select(tx *sql.Tx) error {
	if !r.validBundle() {
		return r.errInvalidBundle()
	}

	query := fmt.Sprintf("SELECT released_at FROM %s_releases WHERE version=?", r.table())
	row := tx.QueryRow(query, r.Version)
	return row.Scan(&r.ReleasedAt)
}
942327
func (session *Session) Select(str string) *Session {
	session.statement.Select(str)
	return session
}
1043926
func (q *Query) Select(values ...interface{}) error {
	if q.stickyErr != nil {
		return q.stickyErr
	}

	model, err := q.newModel(values...)
	if err != nil {
		return err
	}

	q, err = model.BeforeSelectQuery(q.ctx, q.db, q)
	if err != nil {
		return err
	}

	res, err := q.query(model, newSelectQuery(q))
	if err != nil {
		return err
	}

	if res.RowsReturned() > 0 {
		if q.model != nil {
			if err := q.selectJoins(q.model.GetJoins()); err != nil {
				return err
			}
		}
		if err := model.AfterSelect(q.ctx, q.db); err != nil {
			return err
		}
	}

	return nil
}
58362
func Insert(selection Selectable, selections ...Selectable) (stmt InsertStmt) {
	columns := make([]ColumnElem, 0)
	for _, s := range append([]Selectable{selection}, selections...) {
		if s == nil {
			stmt.SetError("aspect: insert received a nil selectable - do the columns or tables you selected exist?")
			return
		}
		columns = append(columns, s.Selectable()...)
	}

	if len(columns) < 1 {
		stmt.SetError("aspect: no columns were selected for INSERT")
		return
	}

	// The table is set from the first column
	column := columns[0]
	if column.table == nil {
		stmt.SetError(
			"aspect: attempting to INSERT to a column unattached to a table",
		)
		return
	}
	stmt.table = column.table

	// Prepend the first column
	for _, c := range columns {
		// Columns must have a name or they wouldn't exist (and probably
		// don't if the name is missing - the most common error case will
		// be a mistyped name in table.C)
		if c.Name() == "" {
			stmt.SetError("aspect: cannot INSERT to a column that does not exist - are selected columns named correctly?")
			return
		}
		if c.table != stmt.table {
			stmt.SetError("aspect: columns of an INSERT must all belong to the same table")
			return
		}
		stmt.columns = append(stmt.columns, c)
	}
	return
}
866151
func (b *InsertBuilder) Columns(columns ...string) *InsertBuilder {
	b.lock.Lock()
	b.columns = columns
	b.query = fmt.Sprintf(`%s(`, b.query)
	for i, column := range columns {
		b.query = fmt.Sprintf(`%s%s`, b.query, column)
		if i < len(columns)-1 {
			b.query = fmt.Sprintf(`%s,`, b.query)
		}
	}
	b.query = fmt.Sprintf(`%s)`, b.query)
	b.lock.Unlock()
	return b
}
1207826
func (sess *Session) SelectBySql(query string, value ...interface{}) *SelectStmt {
	b := SelectBySql(query, value...)
	b.runner = sess
	b.EventReceiver = sess.EventReceiver
	b.Dialect = sess.Dialect
	return b
}
134455
func (l *List) Select(i int) {
	l.SetSelected(i)
	if l.onSelectionChanged != nil {
		l.onSelectionChanged(l)
	}
}
8598
func (q *Insert) toUpdateString(where *Where) string {
	var buffer bytes.Buffer
	buffer.WriteString("UPDATE ")
	buffer.WriteString(q.table)
	buffer.WriteString("\n")
	buffer.WriteString("SET ")
	
	if len(q.column) > 0 && len(q.column) == len(q.data) {
		for i:=0; i < len(q.column);i++ {
			buffer.WriteString( fmt.Sprintf("%s = %s", q.column[i], _s(q.data[i], q.raw[i])))	
		}
	}
	if len(q.output) > 0 {
		buffer.WriteString("OUTPUT")
		for i := 0; i < len(q.output); i++ {
			if i > 0 {
				buffer.WriteString(",")
			}
			s := q.output[i]
			buffer.WriteString(" inserted.")
			buffer.WriteString(s)
		}
		buffer.WriteString("\n")
	}
	if where != nil {
		
	}

	return buffer.String()
}