// InsertRecord tries to reuse deleted records, and only then add new record to the
// end of file if no delete slots exist.
// If you are looping over rows it is better to use AddRecord.
434916
func (dt *DbfTable) InsertRecord() int {
	if row := dt.findSpot(); row > -1 {
		// undelete selected row
		dt.dataStore[dt.getRowOffset(row)] = 0x20
		return row
	}
	return dt.AddRecord()
}
1014600
func (s *session) Insert(tables ...Table) error {
	for _, table := range tables {
		action, err := s.update(table, true)
		if err != nil {
			return s.catch("Insert: "+action, err)
		}
	}
	return nil
}
945980
func (eng *engine) AddRecord(key string, member interface{}, unixstamp int64) error {
	s := eng.newSession()
	defer s.Close()
	action, err := s.addRecord(key, member, unixstamp)
	if err != nil {
		return s.catch("AddRecord: "+action, err)
	}
	return nil
}
176634
func (d *decodeState) takeRecord() (int, int) {
	return d.scan.peekState(), d.scan.takePos()
}
985236
func (c *Client) PutRecord(request PutRecordRequest) (*PutRecordResponse, error) {
	resp := &PutRecordResponse{}
	err := c.kinesisReqWithResponse("PutRecord", request, resp)
	return resp, err
}
832505
func (a *recordSet) NewRecordBatch() *chunk.RecordBatch {
	return chunk.NewRecordBatch(a.executor.newFirstChunk())
}
1090715
func (s *CombinedMapSlice) UpsertRecorded(key MergeKeys, l interface{}) error {
	item, err := s.upsert(key, l)
	if err != nil {
		return err
	}
	item.SetRecorded(l)
	return nil
}
163675
func (m *GenericDriver) Insert(e MigrationRecord) error {

	err := transaction(m.DB, func(tx *sql.Tx) error {
		_, err := tx.Exec(m.Dialect.InsertSQL(),
			e.Version,
			e.Description,
			e.Checksum,
			e.AppliedAt.Unix(),
			e.ExecutionTime,
		)
		return err
	})

	return err
}
906377
func (db *Storage) Insert(ctxt Context, val interface{}) error {
	ctxt = debugContext(ctxt)
	t, _, err := db.findType(val, "Insert")
	if err != nil {
		return err
	}

	var args []interface{}
	rval := reflect.ValueOf(val).Elem()
	var rowcol *field
	for _, col := range t.fields {
		rv := rval.FieldByIndex(col.index)
		if col.rowid && rv.Int() == 0 {
			rowcol = col
			args = append(args, nil)
		} else {
			args = append(args, rval.FieldByIndex(col.index).Interface())
		}
	}

	var buf bytes.Buffer
	if t.fts4 {
		fmt.Fprintf(&buf, "update %q", t.name)
		fmt.Fprintf(&buf, " set ")
		sep := ""
		var args1 []interface{}
		for i, col := range t.fields {
			if !col.key {
				fmt.Fprintf(&buf, "%s%q = ?", sep, col.name)
				sep = ", "
				args1 = append(args1, args[i])
			}
		}
		fmt.Fprintf(&buf, " where ")
		sep = ""
		for i, col := range t.fields {
			if col.key {
				fmt.Fprintf(&buf, "%s%q = ?", sep, col.name)
				sep = ", "
				args1 = append(args1, args[i])
			}
		}

		res, err := ctxt.Exec(buf.String(), args1...)
		if err != nil {
			return err
		}
		count, err := res.RowsAffected()
		if err != nil {
			return err
		}
		if count > 0 {
			return nil
		}
		// fall through to ordinary insert command
		buf.Reset()
	}

	fmt.Fprintf(&buf, "insert or replace into %q (", t.name)
	for i, col := range t.fields {
		if i > 0 {
			fmt.Fprintf(&buf, ", ")
		}
		fmt.Fprintf(&buf, "%q", col.name)
	}
	fmt.Fprintf(&buf, ") values (")
	for i := range t.fields {
		if i > 0 {
			fmt.Fprintf(&buf, ", ")
		}
		fmt.Fprintf(&buf, "?")
	}
	fmt.Fprintf(&buf, ")")

	res, err := ctxt.Exec(buf.String(), args...)
	if err != nil {
		return err
	}
	if rowcol != nil {
		id, err := res.LastInsertId()
		if err != nil {
			return err
		}
		rval.FieldByIndex(rowcol.index).SetInt(id)
	}
	return nil
}
1180662
func (h *SessionHandle) AddBindRecord(record *BindRecord) error {
	record.CreateTime = types.Time{
		Time: types.FromGoTime(time.Now()),
		Type: mysql.TypeDatetime,
		Fsp:  3,
	}
	record.UpdateTime = record.CreateTime

	// update the BindMeta to the cache.
	hash, meta, err := h.newBindMeta(record)
	if err == nil {
		h.appendBindMeta(hash, meta)
	}
	return err
}
314534
func InsertBySql(query string, value ...interface{}) *InsertStmt {
	return &InsertStmt{
		raw: raw{
			Query: query,
			Value: value,
		},
	}
}
109875
func (dt *DbfTable) AddRecord() int {
	newRecord := make([]byte, dt.recordLength)
	dt.dataStore = appendSlice(dt.dataStore, newRecord)

	// since row numbers are "0" based first we set newRecordNumber
	// and then increment number of records in dbase table
	newRecordNumber := int(dt.numberOfRecords)

	dt.numberOfRecords++
	s := uint32ToBytes(dt.numberOfRecords)
	dt.dataStore[4] = s[0]
	dt.dataStore[5] = s[1]
	dt.dataStore[6] = s[2]
	dt.dataStore[7] = s[3]
	return newRecordNumber
}
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
}
848755
func (dal *DjangoAdminLog) Insert(db XODB) error {
	var err error

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

	// sql query
	const sqlstr = `INSERT INTO django.django_admin_log (` +
		`action_time, object_id, object_repr, action_flag, change_message, content_type_id, user_id` +
		`) VALUES (` +
		`:1, :2, :3, :4, :5, :6, :7` +
		`) RETURNING id /*lastInsertId*/ INTO :pk`

	// run query
	XOLog(sqlstr, dal.ActionTime, dal.ObjectID, dal.ObjectRepr, dal.ActionFlag, dal.ChangeMessage, dal.ContentTypeID, dal.UserID, nil)
	res, err := db.Exec(sqlstr, dal.ActionTime, dal.ObjectID, dal.ObjectRepr, dal.ActionFlag, dal.ChangeMessage, dal.ContentTypeID, dal.UserID, nil)
	if err != nil {
		return err
	}

	// retrieve id
	id, err := res.LastInsertId()
	if err != nil {
		return err
	}

	// set primary key and existence
	dal.ID = float64(id)
	dal._exists = true

	return nil
}
182825
func (c *LRUCache) addRecord(record *cacheRecord) bool {
	defer c.mutex.Unlock()
	c.mutex.Lock()

	// If the key already exist, set the new value
	if ee, ok := c.cache[record.key]; ok {
		c.ll.MoveToFront(ee)
		temp := ee.Value.(*cacheRecord)
		*temp = *record
		return true
	}

	ele := c.ll.PushFront(record)
	c.cache[record.key] = ele
	if c.MaxEntries != 0 && c.ll.Len() > c.MaxEntries {
		c.removeOldest()
	}
	return false
}
704999
func (t *tableCommon) UpdateRecord(ctx sessionctx.Context, h int64, oldData, newData []types.Datum, touched []bool) error {
	txn, err := ctx.Txn(true)
	if err != nil {
		return err
	}

	// TODO: reuse bs, like AddRecord does.
	bs := kv.NewBufferStore(txn, kv.DefaultTxnMembufCap)

	// rebuild index
	err = t.rebuildIndices(ctx, bs, h, touched, oldData, newData)
	if err != nil {
		return err
	}
	numColsCap := len(newData) + 1 // +1 for the extra handle column that we may need to append.

	var colIDs, binlogColIDs []int64
	var row, binlogOldRow, binlogNewRow []types.Datum
	colIDs = make([]int64, 0, numColsCap)
	row = make([]types.Datum, 0, numColsCap)
	if shouldWriteBinlog(ctx) {
		binlogColIDs = make([]int64, 0, numColsCap)
		binlogOldRow = make([]types.Datum, 0, numColsCap)
		binlogNewRow = make([]types.Datum, 0, numColsCap)
	}

	for _, col := range t.WritableCols() {
		var value types.Datum
		if col.State != model.StatePublic {
			// If col is in write only or write reorganization state we should keep the oldData.
			// Because the oldData must be the orignal data(it's changed by other TiDBs.) or the orignal default value.
			// TODO: Use newData directly.
			value = oldData[col.Offset]
		} else {
			value = newData[col.Offset]
		}
		if !t.canSkip(col, value) {
			colIDs = append(colIDs, col.ID)
			row = append(row, value)
		}
		if shouldWriteBinlog(ctx) && !t.canSkipUpdateBinlog(col, value) {
			binlogColIDs = append(binlogColIDs, col.ID)
			binlogOldRow = append(binlogOldRow, oldData[col.Offset])
			binlogNewRow = append(binlogNewRow, value)
		}
	}

	key := t.RecordKey(h)
	value, err := tablecodec.EncodeRow(ctx.GetSessionVars().StmtCtx, row, colIDs, nil, nil)
	if err != nil {
		return err
	}
	if err = bs.Set(key, value); err != nil {
		return err
	}
	if err = bs.SaveTo(txn); err != nil {
		return err
	}
	ctx.StmtAddDirtyTableOP(table.DirtyTableDeleteRow, t.physicalTableID, h, nil)
	ctx.StmtAddDirtyTableOP(table.DirtyTableAddRow, t.physicalTableID, h, newData)
	if shouldWriteBinlog(ctx) {
		if !t.meta.PKIsHandle {
			binlogColIDs = append(binlogColIDs, model.ExtraHandleID)
			binlogOldRow = append(binlogOldRow, types.NewIntDatum(h))
			binlogNewRow = append(binlogNewRow, types.NewIntDatum(h))
		}
		err = t.addUpdateBinlog(ctx, binlogOldRow, binlogNewRow, binlogColIDs)
		if err != nil {
			return err
		}
	}
	colSize := make(map[int64]int64)
	for id, col := range t.Cols() {
		val := int64(len(newData[id].GetBytes()) - len(oldData[id].GetBytes()))
		if val != 0 {
			colSize[col.ID] = val
		}
	}
	ctx.GetSessionVars().TxnCtx.UpdateDeltaForTable(t.physicalTableID, 0, 1, colSize)
	return nil
}
631517
func (c *Client) AddRecord(domainID int, body Record) (*Record, error) {
	uri := fmt.Sprintf("/%d/records/", domainID)
	req, err := c.newRequest(http.MethodPost, uri, body)
	if err != nil {
		return nil, err
	}

	record := &Record{}
	_, err = c.do(req, record)
	if err != nil {
		return nil, err
	}

	return record, nil
}