<commit_before>#include <lightmediascanner_db.h>
#include "lightmediascanner_db_private.h"
#include <stdlib.h>
#include <stdio.h>

struct lms_db_playlist {
    sqlite3 *db;
    sqlite3_stmt *insert;
    unsigned int _references;
    unsigned int _is_started:1;
};

static lms_db_playlist_t *_singleton = NULL;

static int
_db_table_updater_playlists_0(sqlite3 *db, const char *table, unsigned int current_version, int is_last_run) {
    char *errmsg;
    int r, ret;

    errmsg = NULL;
    r = sqlite3_exec(db,
                     "CREATE TABLE IF NOT EXISTS playlists ("
                     "id INTEGER PRIMARY KEY, "
                     "title TEXT, "
                     "n_entries INTEGER NOT NULL"
                     ")",
                     NULL, NULL, &errmsg);
    if (r != SQLITE_OK) {
        fprintf(stderr, "ERROR: could not create 'playlists' table: %s\n",
                errmsg);
        sqlite3_free(errmsg);
        return -1;
    }

    ret = lms_db_create_trigger_if_not_exists(db,
        "delete_playlists_on_files_deleted "
        "DELETE ON files FOR EACH ROW BEGIN "
        " DELETE FROM playlists WHERE id = OLD.id; END;");
    if (ret != 0)
        goto done;

    ret = lms_db_create_trigger_if_not_exists(db,
        "delete_files_on_playlists_deleted "<commit_msg>Add playlist indexes<commit_after>#include <lightmediascanner_db.h>
#include "lightmediascanner_db_private.h"
#include <stdlib.h>
#include <stdio.h>

struct lms_db_playlist {
    sqlite3 *db;
    sqlite3_stmt *insert;
    unsigned int _references;
    unsigned int _is_started:1;
};

static lms_db_playlist_t *_singleton = NULL;

static int
_db_table_updater_playlists_0(sqlite3 *db, const char *table, unsigned int current_version, int is_last_run) {
    char *errmsg;
    int r, ret;

    errmsg = NULL;
    r = sqlite3_exec(db,
                     "CREATE TABLE IF NOT EXISTS playlists ("
                     "id INTEGER PRIMARY KEY, "
                     "title TEXT, "
                     "n_entries INTEGER NOT NULL"
                     ")",
                     NULL, NULL, &errmsg);
    if (r != SQLITE_OK) {
        fprintf(stderr, "ERROR: could not create 'playlists' table: %s\n",
                errmsg);
        sqlite3_free(errmsg);
        return -1;
    }

    r = sqlite3_exec(db,
                     "CREATE INDEX IF NOT EXISTS playlists_title_idx ON "
                     "playlists (title)",
                     NULL, NULL, &errmsg);
    if (r != SQLITE_OK) {
        fprintf(stderr,
                "ERROR: could not create 'playlists_title_idx' index: %s\n",
                errmsg);
        sqlite3_free(errmsg);
        return -2;
    }

    ret = lms_db_create_trigger_if_not_exists(db,
        "delete_playlists_on_files_deleted "
        "DELETE ON files FOR EACH ROW BEGIN "
        " DELETE FROM playlists WHERE id = OLD.id; END;");
    if (ret != 0)
        goto done;

    ret = lms_db_create_trigger_if_not_exists(db,
        "delete_files_on_playlists_deleted "
{'fraction_non_alphanumeric': 0.09151414309484193, 'fraction_numerical': 0.006988352745424293, 'mean_word_length': 2.1279916753381896, 'pattern_counts': {'":': 0, '<': 9, '<?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': '1774069', 'n_tokens_mistral': 1019, 'n_tokens_neox': 970, 'n_words': 239}