SupportSQLiteStatement.kt

/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.sqlite.db

/**
 * An interface to map the behavior of [android.database.sqlite.SQLiteStatement].
 */
interface SupportSQLiteStatement : SupportSQLiteProgram {
    /**
     * Execute this SQL statement, if it is not a SELECT / INSERT / DELETE / UPDATE, for example
     * CREATE / DROP table, view, trigger, index etc.
     *
     * @throws [android.database.SQLException] If the SQL string is invalid for
     * some reason
     */
    fun execute()

    /**
     * Execute this SQL statement, if the the number of rows affected by execution of this SQL
     * statement is of any importance to the caller - for example, UPDATE / DELETE SQL statements.
     *
     * @return the number of rows affected by this SQL statement execution.
     * @throws [android.database.SQLException] If the SQL string is invalid for
     * some reason
     */
    fun executeUpdateDelete(): Int

    /**
     * Execute this SQL statement and return the ID of the row inserted due to this call.
     * The SQL statement should be an INSERT for this to be a useful call.
     *
     * @return the row ID of the last row inserted, if this insert is successful. -1 otherwise.
     *
     * @throws [android.database.SQLException] If the SQL string is invalid for
     * some reason
     */
    fun executeInsert(): Long

    /**
     * Execute a statement that returns a 1 by 1 table with a numeric value.
     * For example, SELECT COUNT(*) FROM table;
     *
     * @return The result of the query.
     *
     * @throws [android.database.sqlite.SQLiteDoneException] if the query returns zero rows
     */
    fun simpleQueryForLong(): Long

    /**
     * Execute a statement that returns a 1 by 1 table with a text value.
     * For example, SELECT COUNT(*) FROM table;
     *
     * @return The result of the query.
     *
     * @throws [android.database.sqlite.SQLiteDoneException] if the query returns zero rows
     */
    fun simpleQueryForString(): String?
}