sync/sql_func.yml2
author Thomas
Fri, 07 Jun 2019 07:41:36 +0200
branchsequoia_windows
changeset 3819 0c1bcfa6f9f3
parent 3739 523fb9710660
child 4142 3053a46b8b56
permissions -rw-r--r--
Merge with sync
vb@2845
     1
// This file is under GNU General Public License 3.0
vb@2845
     2
// see LICENSE.txt
vb@2845
     3
vb@2845
     4
// Copyleft (c) 2017, 2018, p≡p foundation
vb@2845
     5
vb@2845
     6
// Written by Volker Birk
vb@2845
     7
vb@2845
     8
vb@2844
     9
// prepare SQL statement
vb@2844
    10
vb@2844
    11
function "init_sql" {
vb@2844
    12
    param "sql";
vb@2844
    13
    ||
vb@2844
    14
        sqlite3_stmt *_sql;
vb@3102
    15
        int int_result = sqlite3_prepare_v2(session->db,
vb@3102
    16
    ||
vb@3102
    17
    indent(2); copy '$sql';
vb@3102
    18
    ||
vb@3102
    19
            , -1, &_sql, NULL);
vb@2844
    20
        assert(int_result == SQLITE_OK);
vb@2844
    21
        if (!(int_result == SQLITE_OK))
vb@2844
    22
            return PEP_UNKNOWN_ERROR;
vb@2844
    23
vb@2844
    24
    ||
vb@2844
    25
}
vb@2844
    26
vb@2844
    27
// exec_sql_* is returning _result
vb@2844
    28
vb@2844
    29
function "exec_sql_int" {
vb@2844
    30
    param "sql";
vb@2844
    31
    call "init_sql" with "sql", "$sql";
vb@2844
    32
    ||
vb@2844
    33
        int _result = 0;
vb@3739
    34
        int_result = Sqlite3_step(_sql);
vb@2844
    35
        assert(int_result == SQLITE_ROW);
vb@2844
    36
        if (int_result == SQLITE_ROW)
vb@2844
    37
            _result = sqlite3_column_int(_sql, 0);
vb@2844
    38
        sqlite3_finalize(_sql);
vb@2844
    39
        if (int_result != SQLITE_ROW)
vb@2844
    40
            return PEP_UNKNOWN_ERROR;
vb@2844
    41
vb@2844
    42
    ||
vb@2844
    43
}
vb@2844
    44