<commit_before>/*
 * Copyright 2015, Yahoo Inc.
 * Copyrights licensed under the Apache 2.0 License.
 * See the accompanying LICENSE file for terms.
 */
package com.yahoo.squidb.sql;

import com.yahoo.squidb.utility.VersionCode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Builder class for a SQLite INSERT statement
 */
public class Insert extends TableStatement {

    private final SqlTable<?> table;
    private ConflictAlgorithm conflictAlgorithm = ConflictAlgorithm.NONE;
    private final List<String> columns = new ArrayList<String>();
    private final List<List<Object>> valuesToInsert = new ArrayList<List<Object>>();
    private Query query;
    private boolean defaultValues;

    private Insert(SqlTable<?> table) {
        this.table = table;
    }

    /**
     * Construct a new Insert statement on the specified {@link Table} or {@link VirtualTable}
     */
    public static Insert into(Table table) {
        return new Insert(table);
    }

    /**
     * Construct a new Insert statement on the specified {@link View}. Note that inserts into a View are only
     * permissible when an INSTEAD OF {@link com.yahoo.squidb.sql.Trigger} is constructed on that View.
     */
    public static Insert into(View view) {
        return new Insert(view);
    }

    @Override
    public SqlTable<?> getTable() {
        return table;
    }

    /**
     * Specify columns to insert into
     *
     * @param columns the columns to insert into
     * @return this Insert object, to allow chaining method calls
     */
    public Insert columns(Property<?>... columns) {
        for (Property<?> column : columns) {
            this.columns.add(column.getExpression());
        }
        defaultValues = false;
        invalidateCompileCache();
        return this;
    }

    /**
     * Specify a set of values to insert. The number of values must equal the number of columns specified and the order
     * must match the order of the columns.
     * <p>
     * On Android JellyBean (API 16) and later, you can call this method multiple times to insert multiple rows.
     * Otherwise, calling this method more than once will throw an exception.
     *
     * @param values the values to insert
     * @return this Insert object, to allow chaining method calls
     * @throws UnsupportedOperationException if called multiple times on Android versions lower than 16 (JellyBean)
     */
    public Insert values(Object... values) {
        valuesToInsert.add(Arrays.asList(values));
        query = null;
        defaultValues = false;
        invalidateCompileCache();
        return this;
    }

    /**
     * Insert the results of the specified query into the table
     *
     * @param select the Query to execute
     * @return this Insert object, to allow chaining method calls
     */
    public Insert select(Query select) {
        this.query = select;
        valuesToInsert.clear();
        defaultValues = false;
        invalidateCompileCache();<commit_msg>Fix some erroneous documentation in Insert<commit_after>/*
 * Copyright 2015, Yahoo Inc.
 * Copyrights licensed under the Apache 2.0 License.
 * See the accompanying LICENSE file for terms.
 */
package com.yahoo.squidb.sql;

import com.yahoo.squidb.utility.VersionCode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Builder class for a SQLite INSERT statement
 */
public class Insert extends TableStatement {

    private final SqlTable<?> table;
    private ConflictAlgorithm conflictAlgorithm = ConflictAlgorithm.NONE;
    private final List<String> columns = new ArrayList<String>();
    private final List<List<Object>> valuesToInsert = new ArrayList<List<Object>>();
    private Query query;
    private boolean defaultValues;

    private Insert(SqlTable<?> table) {
        this.table = table;
    }

    /**
     * Construct a new Insert statement on the specified {@link Table} or {@link VirtualTable}
     */
    public static Insert into(Table table) {
        return new Insert(table);
    }

    /**
     * Construct a new Insert statement on the specified {@link View}. Note that inserts into a View are only
     * permissible when an INSTEAD OF {@link com.yahoo.squidb.sql.Trigger} is constructed on that View.
     */
    public static Insert into(View view) {
        return new Insert(view);
    }

    @Override
    public SqlTable<?> getTable() {
        return table;
    }

    /**
     * Specify columns to insert into
     *
     * @param columns the columns to insert into
     * @return this Insert object, to allow chaining method calls
     */
    public Insert columns(Property<?>... columns) {
        for (Property<?> column : columns) {
            this.columns.add(column.getExpression());
        }
        defaultValues = false;
        invalidateCompileCache();
        return this;
    }

    /**
     * Specify a set of values to insert. The number of values must equal the number of columns specified and the order
     * must match the order of the columns.
     * <p>
     * If you are using a SQLite version < 3.7.11 (Android API < 16 for stock SQLite), you should not call this method
     * more than once, as inserting multiple rows with a single statement is only supported for SQLite version 3.7.11
     * and higher. Calling this method more than once may cause an exception to be thrown when trying to execute the
     * statement.
     *
     * @param values the values to insert
     * @return this Insert object, to allow chaining method calls
     */
    public Insert values(Object... values) {
        valuesToInsert.add(Arrays.asList(values));
        query = null;
        defaultValues = false;
        invalidateCompileCache();
        return this;
    }

    /**
     * Insert the results of the specified query into the table
     *
     * @param select the Query to execute
     * @return this Insert object, to allow chaining method calls
     */
    public Insert select(Query select) {
        this.query = select;
        valuesToInsert.clear();
        defaultValues = false;
        invalidateCompileCache();
{'fraction_non_alphanumeric': 0.08406647116324535, 'fraction_numerical': 0.004235907461713913, 'mean_word_length': 2.6607036374478237, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3215131', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1552, 'n_words': 631}