// INSERT INTO <table> (...) VALUES ...
970993
func (h *sqlHelper) Insert(
	logger lager.Logger,
	q Queryable,
	table string,
	attributes SQLAttributes,
) (sql.Result, error) {
	attributeCount := len(attributes)
	if attributeCount == 0 {
		return nil, nil
	}

	query := fmt.Sprintf("INSERT INTO %s\n", table)
	attributeNames := make([]string, 0, attributeCount)
	attributeBindings := make([]string, 0, attributeCount)
	bindings := make([]interface{}, 0, attributeCount)

	for column, value := range attributes {
		attributeNames = append(attributeNames, column)
		attributeBindings = append(attributeBindings, "?")
		bindings = append(bindings, value)
	}
	query += fmt.Sprintf("(%s)", strings.Join(attributeNames, ", "))
	query += fmt.Sprintf("VALUES (%s)", strings.Join(attributeBindings, ", "))

	return q.Exec(h.Rebind(query), bindings...)
}
984466
func (t *Table) InsertRow(row int) *Table {
	if row >= len(t.cells) {
		return t
	}
	t.cells = append(t.cells, nil)       // Extend by one.
	copy(t.cells[row+1:], t.cells[row:]) // Shift down.
	t.cells[row] = nil                   // New row is uninitialized.
	return t
}
411038
func (s Int32) Insert(items ...int32) {
	for _, item := range items {
		s[item] = Empty{}
	}
}
1370038
func (t *Tree) Insert(k []byte, v interface{}) (*Tree, interface{}, bool) {
	txn := t.Txn()
	old, ok := txn.Insert(k, v)
	return txn.Commit(), old, ok
}
363405
func (t Term) Insert(arg interface{}, optArgs ...InsertOpts) Term {
	opts := map[string]interface{}{}
	if len(optArgs) >= 1 {
		opts = optArgs[0].toMap()
	}
	return constructMethodTerm(t, "Insert", p.Term_INSERT, []interface{}{Expr(arg)}, opts)
}
811948
func (l *ByteIntervalList) insert(e, at *ByteIntervalElement) *ByteIntervalElement {
	n := at.next
	at.next = e
	e.prev = at
	e.next = n
	n.prev = e
	e.list = l
	l.len++
	return e
}
584249
func (s *nodeStack) insert(i int, n *Node) {
	(*s) = append(*s, nil)
	copy((*s)[i+1:], (*s)[i:])
	(*s)[i] = n
}
822426
func Insert(s aspect.Selectable, ss ...aspect.Selectable) RetInsertStmt {
	return RetInsertStmt{
		InsertStmt: aspect.Insert(s, ss...),
	}
}
730792
func (ds *DjangoSession) Insert(db XODB) error {
	var err error

	// if already exist, bail
	if ds._exists {
		return errors.New("insert failed: already exists")
	}

	// sql insert query, primary key must be provided
	const sqlstr = `INSERT INTO public.django_session (` +
		`session_key, session_data, expire_date` +
		`) VALUES (` +
		`$1, $2, $3` +
		`)`

	// run query
	XOLog(sqlstr, ds.SessionKey, ds.SessionData, ds.ExpireDate)
	err = db.QueryRow(sqlstr, ds.SessionKey, ds.SessionData, ds.ExpireDate).Scan(&ds.SessionKey)
	if err != nil {
		return err
	}

	// set existence
	ds._exists = true

	return nil
}
1137833
func (l *list) insert(e, at *element) *element {
	n := at.next
	at.next = e
	e.prev = at
	e.next = n
	n.prev = e
	e.list = l
	l.len++
	return e
}
903616
func (ipt *IPTables) Insert(table, chain string, pos int, rulespec ...string) error {
	cmd := append([]string{"-t", table, "-I", chain, strconv.Itoa(pos)}, rulespec...)
	return ipt.run(cmd...)
}
417339
func (aia *AIA) Insert(tx *sql.Tx) error {
	_, err := tx.Exec(`INSERT INTO aia (ski, url) values (?, ?)`, aia.SKI, aia.URL)
	return err
}
1301639
func (session *Session) Insert(beans ...interface{}) (int64, error) {
	var affected int64
	var err error

	if session.IsAutoClose {
		defer session.Close()
	}

	for _, bean := range beans {
		sliceValue := reflect.Indirect(reflect.ValueOf(bean))
		if sliceValue.Kind() == reflect.Slice {
			size := sliceValue.Len()
			if size > 0 {
				if session.Engine.SupportInsertMany() {
					cnt, err := session.innerInsertMulti(bean)
					session.resetStatement()
					if err != nil {
						return affected, err
					}
					affected += cnt
				} else {
					for i := 0; i < size; i++ {
						cnt, err := session.innerInsert(sliceValue.Index(i).Interface())
						session.resetStatement()
						if err != nil {
							return affected, err
						}
						affected += cnt
					}
				}
			}
		} else {
			cnt, err := session.innerInsert(bean)
			session.resetStatement()
			if err != nil {
				return affected, err
			}
			affected += cnt
		}
	}

	return affected, err
}
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
}
1214653
func PreparedInsert(table string) *InsertBuilder {
	i := Insert(table)
	i.prepared = true
	return i
}
205720
func (l *list) Insert(val interface{}, pos uint) (PersistentList, error) {
	if pos == 0 {
		return l.Add(val), nil
	}
	nl, err := l.tail.Insert(val, pos-1)
	if err != nil {
		return nil, err
	}
	return nl.Add(l.head), nil
}
606004
func (c *C) Insert(o []byte) error {
	c.m.Lock()
	defer c.m.Unlock()
	f, err := c.file()
	if err != nil {
		return err
	}
	f.Seek(0, os.SEEK_END)
	f.Write(o)
	f.WriteString(fmt.Sprintln())
	return nil
}