sync/sql_func.yml2
branchsync
changeset 2844 6fce34991f7d
child 2845 d474c5ebfec8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sync/sql_func.yml2	Mon Aug 13 16:45:23 2018 +0200
     1.3 @@ -0,0 +1,34 @@
     1.4 +// prepare SQL statement
     1.5 +
     1.6 +function "init_sql" {
     1.7 +    param "sql";
     1.8 +    ||
     1.9 +        static const char *sql = `copy '$sql'`;
    1.10 +        static const size_t len = sizeof(`copy '$sql'`);
    1.11 +        sqlite3_stmt *_sql;
    1.12 +        int int_result = sqlite3_prepare_v2(session->db, sql, (int) len, &_sql, NULL);
    1.13 +        assert(int_result == SQLITE_OK);
    1.14 +        if (!(int_result == SQLITE_OK))
    1.15 +            return PEP_UNKNOWN_ERROR;
    1.16 +
    1.17 +    ||
    1.18 +}
    1.19 +
    1.20 +// exec_sql_* is returning _result
    1.21 +
    1.22 +function "exec_sql_int" {
    1.23 +    param "sql";
    1.24 +    call "init_sql" with "sql", "$sql";
    1.25 +    ||
    1.26 +        int _result = 0;
    1.27 +        int_result = sqlite3_step(_sql);
    1.28 +        assert(int_result == SQLITE_ROW);
    1.29 +        if (int_result == SQLITE_ROW)
    1.30 +            _result = sqlite3_column_int(_sql, 0);
    1.31 +        sqlite3_finalize(_sql);
    1.32 +        if (int_result != SQLITE_ROW)
    1.33 +            return PEP_UNKNOWN_ERROR;
    1.34 +
    1.35 +    ||
    1.36 +}
    1.37 +