sync/sql_func.yml2
author Volker Birk <vb@pep.foundation>
Wed, 29 Aug 2018 21:49:28 +0200
branchsync
changeset 2903 33549a7c7191
parent 2845 d474c5ebfec8
child 3060 910548a84da0
permissions -rw-r--r--
safeguards
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 // Copyleft (c) 2017, 2018, p≡p foundation
     5 
     6 // Written by Volker Birk
     7 
     8 
     9 // prepare SQL statement
    10 
    11 function "init_sql" {
    12     param "sql";
    13     ||
    14         static const char *sql = `copy '$sql'`;
    15         static const size_t len = sizeof(`copy '$sql'`);
    16         sqlite3_stmt *_sql;
    17         int int_result = sqlite3_prepare_v2(session->db, sql, (int) len, &_sql, NULL);
    18         assert(int_result == SQLITE_OK);
    19         if (!(int_result == SQLITE_OK))
    20             return PEP_UNKNOWN_ERROR;
    21 
    22     ||
    23 }
    24 
    25 // exec_sql_* is returning _result
    26 
    27 function "exec_sql_int" {
    28     param "sql";
    29     call "init_sql" with "sql", "$sql";
    30     ||
    31         int _result = 0;
    32         int_result = sqlite3_step(_sql);
    33         assert(int_result == SQLITE_ROW);
    34         if (int_result == SQLITE_ROW)
    35             _result = sqlite3_column_int(_sql, 0);
    36         sqlite3_finalize(_sql);
    37         if (int_result != SQLITE_ROW)
    38             return PEP_UNKNOWN_ERROR;
    39 
    40     ||
    41 }
    42