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
     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         sqlite3_stmt *_sql;
    15         int int_result = sqlite3_prepare_v2(session->db,
    16     ||
    17     indent(2); copy '$sql';
    18     ||
    19             , -1, &_sql, NULL);
    20         assert(int_result == SQLITE_OK);
    21         if (!(int_result == SQLITE_OK))
    22             return PEP_UNKNOWN_ERROR;
    23 
    24     ||
    25 }
    26 
    27 // exec_sql_* is returning _result
    28 
    29 function "exec_sql_int" {
    30     param "sql";
    31     call "init_sql" with "sql", "$sql";
    32     ||
    33         int _result = 0;
    34         int_result = Sqlite3_step(_sql);
    35         assert(int_result == SQLITE_ROW);
    36         if (int_result == SQLITE_ROW)
    37             _result = sqlite3_column_int(_sql, 0);
    38         sqlite3_finalize(_sql);
    39         if (int_result != SQLITE_ROW)
    40             return PEP_UNKNOWN_ERROR;
    41 
    42     ||
    43 }
    44