<commit_before>#include "dbi.h"

DBI::DBI() : QObject(NULL)
{	
	db = QSqlDatabase::addDatabase("QSQLITE");
	db.setHostName("localhost");
    db.setDatabaseName("music.db");
	//TODO: Fix possible 'missing expected db file' w/ try catch
    db.open();
    //This has to match the DB. ORMs are for bitches.
    songCols << "sid" << "name" << "tracknum" << "album" << "artist" << "length" << "path" << "numplays" << "genre" << "year";
    //Setup watcher on root dirs
    watcher = std::unique_ptr<QFileSystemWatcher>(new QFileSystemWatcher(this));
    connect(watcher.get(),
            SIGNAL(directoryChanged(QString)), SLOT(processDir(QString)));
}

QMap<QString, QPair<int, QString>> DBI::search(QString query, searchFlag)
{
	QSqlQueryModel qm;
	query = sanitize(query);
    QString quer = "select alid as id, 'album' as tbn, name from album where name like '%"+query+"%'";
	quer += " UNION";
    quer += " select arid as id, 'artist' as tbn, name from artist WHERE arid IN ("
        "SELECT arid "
          "FROM artist "
               "LEFT JOIN album ON artist.arid == album.artist "
         "WHERE album.alid IS NOT NULL "
    ") AND name LIKE '%"+query+"%'";
	quer += " UNION";
    quer += " select sid as id, 'song' as tbn, name from song where name like '%"+query+"%'";
    quer += " ORDER BY id COLLATE NOCASE ASC";
	qm.setQuery(quer);	
    QMap<QString, QPair<int, QString>> ret;
	for(int i = 0; i < qm.rowCount(); i++)
	{
        QString type = qm.record(i).field(1).value().toString();
        QPair<int, QString> id_name = QPair<int, QString>(
                    qm.record(i).field(0).value().toInt(),
                    qm.record(i).field(2).value().toString());
        ret.insertMulti(type, id_name);
	}
    return ret;
}

QList<Alb> DBI::extractAlbums(QSqlQueryModel* qm)
{
    QList<Alb> retme;
    for(int i = qm->rowCount()-1; i >= 0; i--)
    {
        Alb a;
        QSqlRecord qr = qm->record(i);
        a.name = qr.value("name").toString();
        a.alid = qr.value("alid").toString();
        a.artist = getArtistNameFromId(qr.value("artist").toInt());
        a.tracks = getTrackColFromAlbum(qr.value(0).toInt(), 1);
        a.imguri = getOrFindAlbumArt(a);
        a.year = qr.value("year").toString();
        retme.append(a);
    }
    return retme;
}<commit_msg>Add default name for unnamed albums<commit_after>#include "dbi.h"

DBI::DBI() : QObject(NULL)
{	
	db = QSqlDatabase::addDatabase("QSQLITE");
	db.setHostName("localhost");
    db.setDatabaseName("music.db");
	//TODO: Fix possible 'missing expected db file' w/ try catch
    db.open();
    //This has to match the DB. ORMs are for bitches.
    songCols << "sid" << "name" << "tracknum" << "album" << "artist" << "length" << "path" << "numplays" << "genre" << "year";
    //Setup watcher on root dirs
    watcher = std::unique_ptr<QFileSystemWatcher>(new QFileSystemWatcher(this));
    connect(watcher.get(),
            SIGNAL(directoryChanged(QString)), SLOT(processDir(QString)));
}

QMap<QString, QPair<int, QString>> DBI::search(QString query, searchFlag)
{
	QSqlQueryModel qm;
	query = sanitize(query);
    QString quer = "select alid as id, 'album' as tbn, name from album where name like '%"+query+"%'";
	quer += " UNION";
    quer += " select arid as id, 'artist' as tbn, name from artist WHERE arid IN ("
        "SELECT arid "
          "FROM artist "
               "LEFT JOIN album ON artist.arid == album.artist "
         "WHERE album.alid IS NOT NULL "
    ") AND name LIKE '%"+query+"%'";
	quer += " UNION";
    quer += " select sid as id, 'song' as tbn, name from song where name like '%"+query+"%'";
    quer += " ORDER BY id COLLATE NOCASE ASC";
	qm.setQuery(quer);	
    QMap<QString, QPair<int, QString>> ret;
	for(int i = 0; i < qm.rowCount(); i++)
	{
        QString type = qm.record(i).field(1).value().toString();
        QPair<int, QString> id_name = QPair<int, QString>(
                    qm.record(i).field(0).value().toInt(),
                    qm.record(i).field(2).value().toString());
        ret.insertMulti(type, id_name);
	}
    return ret;
}

QList<Alb> DBI::extractAlbums(QSqlQueryModel* qm)
{
    QList<Alb> retme;
    for(int i = qm->rowCount()-1; i >= 0; i--)
    {
        Alb a;
        QSqlRecord qr = qm->record(i);
        a.name = qr.value("name").toString();
        if(a.name == "")  // For blank album fields.
            a.name = "Unknown Album";
        a.alid = qr.value("alid").toString();
        a.artist = getArtistNameFromId(qr.value("artist").toInt());
        a.tracks = getTrackColFromAlbum(qr.value(0).toInt(), 1);
        a.imguri = getOrFindAlbumArt(a);
        a.year = qr.value("year").toString();
        retme.append(a);
    }
    return retme;
}
{'fraction_non_alphanumeric': 0.17377466581795034, 'fraction_numerical': 0.003394865266284744, 'mean_word_length': 2.8894389438943895, 'pattern_counts': {'":': 0, '<': 63, '<?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': '1823892', 'n_tokens_mistral': 1687, 'n_tokens_neox': 1654, 'n_words': 399}