sync/sql_func.yml2
author Volker Birk <vb@pep.foundation>
Mon, 13 Aug 2018 16:45:23 +0200
branchsync
changeset 2844 6fce34991f7d
child 2845 d474c5ebfec8
permissions -rw-r--r--
...
vb@2844
     1
// prepare SQL statement
vb@2844
     2
vb@2844
     3
function "init_sql" {
vb@2844
     4
    param "sql";
vb@2844
     5
    ||
vb@2844
     6
        static const char *sql = `copy '$sql'`;
vb@2844
     7
        static const size_t len = sizeof(`copy '$sql'`);
vb@2844
     8
        sqlite3_stmt *_sql;
vb@2844
     9
        int int_result = sqlite3_prepare_v2(session->db, sql, (int) len, &_sql, NULL);
vb@2844
    10
        assert(int_result == SQLITE_OK);
vb@2844
    11
        if (!(int_result == SQLITE_OK))
vb@2844
    12
            return PEP_UNKNOWN_ERROR;
vb@2844
    13
vb@2844
    14
    ||
vb@2844
    15
}
vb@2844
    16
vb@2844
    17
// exec_sql_* is returning _result
vb@2844
    18
vb@2844
    19
function "exec_sql_int" {
vb@2844
    20
    param "sql";
vb@2844
    21
    call "init_sql" with "sql", "$sql";
vb@2844
    22
    ||
vb@2844
    23
        int _result = 0;
vb@2844
    24
        int_result = sqlite3_step(_sql);
vb@2844
    25
        assert(int_result == SQLITE_ROW);
vb@2844
    26
        if (int_result == SQLITE_ROW)
vb@2844
    27
            _result = sqlite3_column_int(_sql, 0);
vb@2844
    28
        sqlite3_finalize(_sql);
vb@2844
    29
        if (int_result != SQLITE_ROW)
vb@2844
    30
            return PEP_UNKNOWN_ERROR;
vb@2844
    31
vb@2844
    32
    ||
vb@2844
    33
}
vb@2844
    34