<commit_before>package com.mikifus.padland;

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;

import java.util.Date;
import java.util.HashMap;

/**
 * The content provider allows to store and read database information for the app.
 *
 * @author mikifus
 */
public class PadLandContentProvider extends ContentProvider {

    static final String PROVIDER_NAME = "com.mikifus.padland.padlandcontentprovider";
    static final String TAG = "PadLandContentProvider";
    static final String AUTHORITY = "content://" + PROVIDER_NAME + "/padlist";
    public static final Uri CONTENT_URI = Uri.parse( AUTHORITY );

    static final String _ID = "_id";
    static final String NAME = "name"; // Name of the pad, actually it is the last part of the url
    static final String SERVER = "server"; // server, might contain the suffix
    static final String URL = "url"; // the full address including server and name
    static final String LAST_USED_DATE = "last_used_date"; // Date the pad was accessed last time
    static final String CREATE_DATE = "create_date"; // Date when the pad was added into the app
    static final String ACCESS_COUNT = "access_count"; // How many times the document has been accessed in the app

    static final int PADLIST = 1;
    static final int PAD_ID = 2;

    private static HashMap<String, String> PROJECTION_MAP;

    static final UriMatcher uriMatcher;
    static{
        uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        uriMatcher.addURI(PROVIDER_NAME, "padlist", PADLIST);
        uriMatcher.addURI(PROVIDER_NAME, "padlist/#", PAD_ID);
    }

    /**
     * Database specific constant declarations
     */
    private SQLiteDatabase db;
    static final String DATABASE_NAME = "padland";
    static final String TABLE_NAME = "padlist";
    static final int DATABASE_VERSION = 4;
    static final String CREATE_DB_TABLE =
            " CREATE TABLE " + TABLE_NAME +
                    " ("+_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, " +
                    " "+NAME+" TEXT NOT NULL, " +
                    " "+SERVER+" TEXT NOT NULL, " +
                    " "+URL+" TEXT NOT NULL, " +
                    " "+LAST_USED_DATE+ " INTEGER NOT NULL DEFAULT (strftime('%s','now')), " +
                    " "+CREATE_DATE+ " INTEGER NOT NULL DEFAULT (strftime('%s','now'))," +
                    " "+ACCESS_COUNT+ "INTEGER NOT NULL DEFAULT 0 "+
                    ");";

    /**
     * Helper class that actually creates and manages
     * the provider's underlying data repository.
     */
    private static class DatabaseHelper extends SQLiteOpenHelper {
        DatabaseHelper(Context context){
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db)
        {
            db.execSQL(CREATE_DB_TABLE);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            if( oldVersion < 3 ) {
                Log.w(TAG, "Upgrading database. Existing contents will be deleted. [" + oldVersion + "]->[" + newVersion + "]");
                db.execSQL("DROP TABLE IF EXISTS " +  TABLE_NAME);
                onCreate(db);
            }
            if( oldVersion == 3 || newVersion == 4 ) {
                Log.w(TAG, "Upgrading database. Existing contents will be migrated. [" + oldVersion + "]->[" + newVersion + "]");
                db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + ACCESS_COUNT + " INTEGER NOT NULL DEFAULT 0;");
            }
        }
    }

    /**<commit_msg>Fixed a kind of database error.<commit_after>package com.mikifus.padland;

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;

import java.util.Date;
import java.util.HashMap;

/**
 * The content provider allows to store and read database information for the app.
 *
 * @author mikifus
 */
public class PadLandContentProvider extends ContentProvider {

    static final String PROVIDER_NAME = "com.mikifus.padland.padlandcontentprovider";
    static final String TAG = "PadLandContentProvider";
    static final String AUTHORITY = "content://" + PROVIDER_NAME + "/padlist";
    public static final Uri CONTENT_URI = Uri.parse( AUTHORITY );

    static final String _ID = "_id";
    static final String NAME = "name"; // Name of the pad, actually it is the last part of the url
    static final String SERVER = "server"; // server, might contain the suffix
    static final String URL = "url"; // the full address including server and name
    static final String LAST_USED_DATE = "last_used_date"; // Date the pad was accessed last time
    static final String CREATE_DATE = "create_date"; // Date when the pad was added into the app
    static final String ACCESS_COUNT = "access_count"; // How many times the document has been accessed in the app

    static final int PADLIST = 1;
    static final int PAD_ID = 2;

    private static HashMap<String, String> PROJECTION_MAP;

    static final UriMatcher uriMatcher;
    static{
        uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        uriMatcher.addURI(PROVIDER_NAME, "padlist", PADLIST);
        uriMatcher.addURI(PROVIDER_NAME, "padlist/#", PAD_ID);
    }

    /**
     * Database specific constant declarations
     */
    private SQLiteDatabase db;
    static final String DATABASE_NAME = "padland";
    static final String TABLE_NAME = "padlist";
    static final int DATABASE_VERSION = 5;
    static final String CREATE_DB_TABLE =
            " CREATE TABLE " + TABLE_NAME +
                    " ("+_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, " +
                    " "+NAME+" TEXT NOT NULL, " +
                    " "+SERVER+" TEXT NOT NULL, " +
                    " "+URL+" TEXT NOT NULL, " +
                    " "+LAST_USED_DATE+ " INTEGER NOT NULL DEFAULT (strftime('%s','now')), " +
                    " "+CREATE_DATE+ " INTEGER NOT NULL DEFAULT (strftime('%s','now'))," +
                    " "+ACCESS_COUNT+ "INTEGER NOT NULL DEFAULT 0 "+
                    ");";

    /**
     * Helper class that actually creates and manages
     * the provider's underlying data repository.
     */
    private static class DatabaseHelper extends SQLiteOpenHelper {
        DatabaseHelper(Context context){
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db)
        {
            db.execSQL(CREATE_DB_TABLE);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            if( oldVersion < 3 ) {
                Log.w(TAG, "Upgrading database. Existing contents will be deleted. [" + oldVersion + "]->[" + newVersion + "]");
                db.execSQL("DROP TABLE IF EXISTS " +  TABLE_NAME);
                onCreate(db);
            }
            if( oldVersion == 3 && (newVersion == 4 || newVersion == 5 ) ) {
                Log.w(TAG, "Upgrading database. Existing contents will be migrated. [" + oldVersion + "]->[" + newVersion + "]");
                db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + ACCESS_COUNT + " INTEGER NOT NULL DEFAULT 0;");
            }
        }
    }

    /**
{'fraction_non_alphanumeric': 0.09965251923554232, 'fraction_numerical': 0.002109704641350211, 'mean_word_length': 2.6532184950135993, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '7059236', 'n_tokens_mistral': 2292, 'n_tokens_neox': 2162, 'n_words': 687}