//Adds the columns list to an insert statement
554828
func (me *DefaultAdapter) InsertColumnsSql(buf *SqlBuilder, cols ColumnList) error {
	buf.WriteRune(space_rune)
	buf.WriteRune(left_paren_rune)
	if err := me.Literal(buf, cols); err != nil {
		return err
	}
	buf.WriteRune(right_paren_rune)
	return nil
}
994057
func (b *InsertBuilder) Values(columnValues ...interface{}) *InsertBuilder {
	b.lock.Lock()
	sqlValue := "("
	if b.prepared {
		for k, columnValue := range columnValues {
			switch v := columnValue.(type) {
			case string:
				sqlValue = fmt.Sprintf("%s'%s'", sqlValue, strings.Replace(v, "'", "''", -1))
			default:
				sqlValue = fmt.Sprintf("%s%v", sqlValue, v)
			}
			if k < len(columnValues)-1 {
				sqlValue = fmt.Sprintf("%s, ", sqlValue)
			}
		}
	} else {
		for k := range columnValues {
			sqlValue = fmt.Sprintf("%s?", sqlValue)
			if k < len(columnValues)-1 {
				sqlValue = fmt.Sprintf("%s, ", sqlValue)
			}
		}
	}
	b.sqlValues = append(b.sqlValues, fmt.Sprintf(`%s)`, sqlValue))

	b.lock.Unlock()

	return b
}
325837
func (d *Database) Columns(src interface{}, includePk bool) ([]string, error) {
	data, err := getFields(reflect.TypeOf(src))
	if err != nil {
		return nil, err
	}

	var names []string
	for _, elt := range data.columns {
		if !includePk && elt == data.pk {
			continue
		}
		names = append(names, elt)
	}

	return names, nil
}
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
}
503765
func (stmt *InsertStmt) updateColumns() {
	// TODO keep actual target columns separate from requested in case
	// the statement is updated?
	for _, column := range stmt.columns {
		if !stmt.fields.HasColumn(column.Name()) {
			// TODO pass an index to prevent further nesting of iteration
			stmt.columns = removeColumn(stmt.columns, column.Name())
		}
	}
}
119147
func (b *Builder) Insert(eq ...interface{}) *Builder {
	if len(eq) > 0 {
		var paramType = -1
		for _, e := range eq {
			switch t := e.(type) {
			case Eq:
				if paramType == -1 {
					paramType = 0
				}
				if paramType != 0 {
					break
				}
				for k, v := range t {
					b.insertCols = append(b.insertCols, k)
					b.insertVals = append(b.insertVals, v)
				}
			case string:
				if paramType == -1 {
					paramType = 1
				}
				if paramType != 1 {
					break
				}
				b.insertCols = append(b.insertCols, t)
			}
		}
	}

	if len(b.insertCols) == len(b.insertVals) {
		sort.Sort(insertColsSorter{
			cols: b.insertCols,
			vals: b.insertVals,
		})
	}
	b.optype = insertType
	return b
}
69852
func Insert(topic *db.Topic) string {
	return db.Conn.Insert(db.TopicCollection, topic)
}
808078
func (db *DB) Upsert(list ...interface{}) error {
	return insertObjects(db.Context(), db, db, getUpsert, list, opUpsert)
}
812058
func (builder *Builder) Insert(collection string, changes map[string]interface{}) (string, []interface{}) {
	length := len(changes)

	var buffer bytes.Buffer
	var args = make([]interface{}, 0, length)

	buffer.WriteString("INSERT INTO ")
	buffer.WriteString(builder.config.EscapeChar)
	buffer.WriteString(collection)
	buffer.WriteString(builder.config.EscapeChar)

	if len(changes) == 0 && builder.config.InsertDefaultValues {
		buffer.WriteString(" DEFAULT VALUES")
	} else {
		buffer.WriteString(" (")

		curr := 0
		for field, value := range changes {
			buffer.WriteString(builder.config.EscapeChar)
			buffer.WriteString(field)
			buffer.WriteString(builder.config.EscapeChar)

			args = append(args, value)

			if curr < length-1 {
				buffer.WriteString(",")
			}

			curr++
		}
		buffer.WriteString(") VALUES ")

		buffer.WriteString("(")
		for i := 0; i < length; i++ {
			buffer.WriteString(builder.ph())

			if i < length-1 {
				buffer.WriteString(",")
			}
		}
		buffer.WriteString(")")
	}

	if builder.returnField != "" {
		buffer.WriteString(" RETURNING ")
		buffer.WriteString(builder.config.EscapeChar)
		buffer.WriteString(builder.returnField)
		buffer.WriteString(builder.config.EscapeChar)
	}

	buffer.WriteString(";")

	return buffer.String(), args
}
234623
func (b *InsertBuilder) Add(vals ...interface{}) *InsertBuilder {
	var rows Values
	if b.Insert.Rows != nil {
		rows = b.Insert.Rows.(Values)
	}
	b.Insert.Rows = append(rows, makeValTuple(vals))
	return b
}
1000096
func (rc *SQLiteRows) Columns() []string {
	rc.s.mu.Lock()
	defer rc.s.mu.Unlock()
	if rc.s.s != nil && rc.nc != len(rc.cols) {
		rc.cols = make([]string, rc.nc)
		for i := 0; i < rc.nc; i++ {
			rc.cols[i] = C.GoString(C.sqlite3_column_name(rc.s.s, C.int(i)))
		}
	}
	return rc.cols
}
206526
func (m *Meta) InsertValues(i interface{}) []interface{} {
	values := make([]interface{}, len(m.insertIndexes))
	m.CopyInsertValues(i, values)
	return values
}
644153
func (d *Dataset) InsertValues(index int, values ...interface{}) error {
	return d.Insert(index, values[:])
}
357156
func (row *Row) GetInsertColumns() []string {
	escapedColumns := make([]string, len(row.insertColumns))
	for i, insertColumn := range row.insertColumns {
		escapedColumns[i] = fmt.Sprintf("\"%s\"", insertColumn)
	}
	return escapedColumns
}
687437
func (b *BaseBuilder) AddColumn(table, col, typ string) *Query {
	sql := fmt.Sprintf("ALTER TABLE %v ADD %v %v", b.db.QuoteTableName(table), b.db.QuoteColumnName(col), typ)
	return b.NewQuery(sql)
}
286433
func Columns(src interface{}, includePk bool) ([]string, error) {
	return Default.Columns(src, includePk)
}
760042
func (b *UpdateBuilder) Add(column string) *UpdateBuilder {
	return b.addValue(column, param(column))
}