// Path: sqlite-android/src/main/java/io/requery/android/database/DatabaseErrorHandler.java
// public interface DatabaseErrorHandler {
// 
//     /**
//      * The method invoked when database corruption is detected.
//      * @param dbObj the {@link SQLiteDatabase} object representing the database on which corruption
//      * is detected.
//      */
//     void onCorruption(SQLiteDatabase dbObj);
// }
// 
// Path: sqlite-android/src/main/java/io/requery/android/database/DefaultDatabaseErrorHandler.java
// public final class DefaultDatabaseErrorHandler implements DatabaseErrorHandler {
// 
//     private static final String TAG = "DefaultDatabaseError";
// 
//     @Override
//     public void onCorruption(SQLiteDatabase dbObj) {
//         Log.e(TAG, "Corruption reported by sqlite on database: " + dbObj.getPath());
// 
//         // is the corruption detected even before database could be 'opened'?
//         if (!dbObj.isOpen()) {
//             // database files are not even openable. delete this database file.
//             // NOTE if the database has attached databases, then any of them could be corrupt.
//             // and not deleting all of them could cause corrupted database file to remain and 
//             // make the application crash on database open operation. To avoid this problem,
//             // the application should provide its own {@link DatabaseErrorHandler} impl class
//             // to delete ALL files of the database (including the attached databases).
//             deleteDatabaseFile(dbObj.getPath());
//             return;
//         }
// 
//         List<Pair<String, String>> attachedDbs = null;
//         try {
//             // Close the database, which will cause subsequent operations to fail.
//             // before that, get the attached database list first.
//             try {
//                 attachedDbs = dbObj.getAttachedDbs();
//             } catch (SQLiteException e) {
//                 /* ignore */
//             }
//             try {
//                 dbObj.close();
//             } catch (SQLiteException e) {
//                 /* ignore */
//             }
//         } finally {
//             // Delete all files of this corrupt database and/or attached databases
//             if (attachedDbs != null) {
//                 for (Pair<String, String> p : attachedDbs) {
//                     deleteDatabaseFile(p.second);
//                 }
//             } else {
//                 // attachedDbs = null is possible when the database is so corrupt that even
//                 // "PRAGMA database_list;" also fails. delete the main database file
//                 deleteDatabaseFile(dbObj.getPath());
//             }
//         }
//     }
// 
//     private void deleteDatabaseFile(String fileName) {
//         if (fileName.equalsIgnoreCase(":memory:") || fileName.trim().length() == 0) {
//             return;
//         }
//         Log.e(TAG, "deleting the database file: " + fileName);
//         try {
//             SQLiteDatabase.deleteDatabase(new File(fileName));
//         } catch (Exception e) {
//             /* print warning and ignore exception */
//             Log.w(TAG, "delete failed: " + e.getMessage());
//         }
//     }
// }


import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabaseCorruptException;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteTransactionListener;
import android.os.Build;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.text.TextUtils;
import android.util.EventLog;
import android.util.Log;
import android.util.Pair;
import android.util.Printer;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.os.CancellationSignal;
import androidx.core.os.OperationCanceledException;
import androidx.sqlite.db.SupportSQLiteDatabase;
import androidx.sqlite.db.SupportSQLiteQuery;
import io.requery.android.database.DatabaseErrorHandler;
import io.requery.android.database.DefaultDatabaseErrorHandler;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.WeakHashMap;

    /** Integer flag definition for the database open options */
    @SuppressLint("UniqueConstants") // duplicate values provided for compatibility
    @IntDef(flag = true, value = {
        OPEN_READONLY,
        OPEN_READWRITE,
        OPEN_CREATE,
        OPEN_URI,
        OPEN_NOMUTEX,
        OPEN_FULLMUTEX,
        OPEN_SHAREDCACHE,
        OPEN_PRIVATECACHE,
        CREATE_IF_NECESSARY,
        ENABLE_WRITE_AHEAD_LOGGING})
    @Retention(RetentionPolicy.SOURCE)
    public @interface OpenFlags {
    }

    /**
     * Absolute max value that can be set by {@link #setMaxSqlCacheSize(int)}.
     *
     * Each prepared-statement is between 1K - 6K, depending on the complexity of the
     * SQL statement & schema.  A large SQL cache may use a significant amount of memory.
     */
    public static final int MAX_SQL_CACHE_SIZE = 100;

    private SQLiteDatabase(SQLiteDatabaseConfiguration configuration,
                           CursorFactory cursorFactory,
                           DatabaseErrorHandler errorHandler) {
        mCursorFactory = cursorFactory;
// Path: sqlite-android/src/main/java/io/requery/android/database/DatabaseErrorHandler.java
// public interface DatabaseErrorHandler {
// 
//     /**
//      * The method invoked when database corruption is detected.
//      * @param dbObj the {@link SQLiteDatabase} object representing the database on which corruption
//      * is detected.
//      */
//     void onCorruption(SQLiteDatabase dbObj);
// }
// 
// Path: sqlite-android/src/main/java/io/requery/android/database/DefaultDatabaseErrorHandler.java
// public final class DefaultDatabaseErrorHandler implements DatabaseErrorHandler {
// 
//     private static final String TAG = "DefaultDatabaseError";
// 
//     @Override
//     public void onCorruption(SQLiteDatabase dbObj) {
//         Log.e(TAG, "Corruption reported by sqlite on database: " + dbObj.getPath());
// 
//         // is the corruption detected even before database could be 'opened'?
//         if (!dbObj.isOpen()) {
//             // database files are not even openable. delete this database file.
//             // NOTE if the database has attached databases, then any of them could be corrupt.
//             // and not deleting all of them could cause corrupted database file to remain and 
//             // make the application crash on database open operation. To avoid this problem,
//             // the application should provide its own {@link DatabaseErrorHandler} impl class
//             // to delete ALL files of the database (including the attached databases).
//             deleteDatabaseFile(dbObj.getPath());
//             return;
//         }
// 
//         List<Pair<String, String>> attachedDbs = null;
//         try {
//             // Close the database, which will cause subsequent operations to fail.
//             // before that, get the attached database list first.
//             try {
//                 attachedDbs = dbObj.getAttachedDbs();
//             } catch (SQLiteException e) {
//                 /* ignore */
//             }
//             try {
//                 dbObj.close();
//             } catch (SQLiteException e) {
//                 /* ignore */
//             }
//         } finally {
//             // Delete all files of this corrupt database and/or attached databases
//             if (attachedDbs != null) {
//                 for (Pair<String, String> p : attachedDbs) {
//                     deleteDatabaseFile(p.second);
//                 }
//             } else {
//                 // attachedDbs = null is possible when the database is so corrupt that even
//                 // "PRAGMA database_list;" also fails. delete the main database file
//                 deleteDatabaseFile(dbObj.getPath());
//             }
//         }
//     }
// 
//     private void deleteDatabaseFile(String fileName) {
//         if (fileName.equalsIgnoreCase(":memory:") || fileName.trim().length() == 0) {
//             return;
//         }
//         Log.e(TAG, "deleting the database file: " + fileName);
//         try {
//             SQLiteDatabase.deleteDatabase(new File(fileName));
//         } catch (Exception e) {
//             /* print warning and ignore exception */
//             Log.w(TAG, "delete failed: " + e.getMessage());
//         }
//     }
// }


// Path: sqlite-android/src/main/java/io/requery/android/database/sqlite/SQLiteDatabase.java
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabaseCorruptException;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteTransactionListener;
import android.os.Build;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.text.TextUtils;
import android.util.EventLog;
import android.util.Log;
import android.util.Pair;
import android.util.Printer;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.os.CancellationSignal;
import androidx.core.os.OperationCanceledException;
import androidx.sqlite.db.SupportSQLiteDatabase;
import androidx.sqlite.db.SupportSQLiteQuery;
import io.requery.android.database.DatabaseErrorHandler;
import io.requery.android.database.DefaultDatabaseErrorHandler;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.WeakHashMap;


    /** Integer flag definition for the database open options */
    @SuppressLint("UniqueConstants") // duplicate values provided for compatibility
    @IntDef(flag = true, value = {
        OPEN_READONLY,
        OPEN_READWRITE,
        OPEN_CREATE,
        OPEN_URI,
        OPEN_NOMUTEX,
        OPEN_FULLMUTEX,
        OPEN_SHAREDCACHE,
        OPEN_PRIVATECACHE,
        CREATE_IF_NECESSARY,
        ENABLE_WRITE_AHEAD_LOGGING})
    @Retention(RetentionPolicy.SOURCE)
    public @interface OpenFlags {
    }

    /**
     * Absolute max value that can be set by {@link #setMaxSqlCacheSize(int)}.
     *
     * Each prepared-statement is between 1K - 6K, depending on the complexity of the
     * SQL statement & schema.  A large SQL cache may use a significant amount of memory.
     */
    public static final int MAX_SQL_CACHE_SIZE = 100;

    private SQLiteDatabase(SQLiteDatabaseConfiguration configuration,
                           CursorFactory cursorFactory,
                           DatabaseErrorHandler errorHandler) {
        mCursorFactory = cursorFactory;
        mErrorHandler = errorHandler != null ? errorHandler : new DefaultDatabaseErrorHandler();