~aleteoryx/muditaos

ref: cc151403c58f91d6ee33115422091e176a04db76 muditaos/module-db/Tables/CountryCodesTable.cpp -rw-r--r-- 1.2 KiB
cc151403 — patrycja-paczkowska [MOS-188] Fix notes window title 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "CountryCodesTable.hpp"

CountryCodesTable::CountryCodesTable(Database *db) : Table(db)
{}

CountryCodesTable::~CountryCodesTable()
{}

bool CountryCodesTable::create()
{
    return db->execute(createTableQuery);
}

CodesTableRow CountryCodesTable::GetByMCC(uint32_t mcc)
{
    auto retQuery = db->query("SELECT * FROM codes WHERE mcc= %lu LIMIT 1;", mcc);

    if ((retQuery == nullptr) || (retQuery->getRowCount() == 0)) {
        return CodesTableRow();
    }

    return CodesTableRow{
        (*retQuery)[0].getUInt32(), /* _id */
        (*retQuery)[1].getUInt32(), /* mcc */
        (*retQuery)[2].getUInt32(), /* mnc */
        (*retQuery)[3].getString(), /* iso */
        (*retQuery)[4].getString(), /* country name */
        (*retQuery)[5].getUInt32(), /* country code */
        (*retQuery)[5].getString()  /* network name */
    };
}

uint32_t CountryCodesTable::count()
{
    auto queryRet = db->query("SELECT COUNT(*) FROM codes;");

    if (!queryRet || queryRet->getRowCount() == 0) {
        return 0;
    }

    return uint32_t{(*queryRet)[0].getUInt32()};
}