コード例 #1
0
ファイル: cli_fastdb.cpp プロジェクト: jiajw0426/easyscada
int cli_close_fdb(int session)
{
    statement_desc *stmt, *next;
    session_desc* s = sessions.get(session);
    if (s == NULL) { 
        return cli_bad_descriptor;
    }
    cli_request req;
    req.length = sizeof(req);
    req.cmd = cli_cmd_close_session;
    req.pack();
    int result = cli_ok;
    if (!s->sock->write(&req, sizeof req)) { 
        result = cli_network_error;
    }
    delete s->sock;
    s->sock = NULL;     
    for (stmt = s->stmts; stmt != NULL; stmt = next) {  
        next = stmt->next;
        stmt->deallocate();
        statements.deallocate(stmt);
    }
    sessions.deallocate(s);
    return result;
}
コード例 #2
0
ファイル: cli_fastdb.cpp プロジェクト: jiajw0426/easyscada
int cli_free_fdb(int statement)
{
    statement_desc* stmt = statements.get(statement);
    session_desc* s = stmt->session;
    if (s == NULL) { 
        return cli_bad_descriptor;
    }   
    statement_desc *sp, **spp = &s->stmts; 
    while ((sp = *spp) != stmt) { 
        if (sp == NULL) { 
            return cli_bad_descriptor;
        }
        spp = &sp->next;
    }
    *spp = stmt->next;
    stmt->deallocate();
    statements.deallocate(stmt);
    cli_request req;
    req.length  = sizeof(cli_request);
    req.cmd     = cli_cmd_free_statement;
    req.stmt_id = statement;
    req.pack();
    if (!s->sock->write(&req, sizeof req)) { 
        return cli_network_error;
    }
    return cli_ok;
}
コード例 #3
0
ファイル: cli_fastdb.cpp プロジェクト: jiajw0426/easyscada
int cli_statement_fdb(int session, char const* stmt_str)
{
    session_desc* s = sessions.get(session);
    if (s == NULL) { 
        return cli_bad_descriptor;
    }
    statement_desc* stmt = statements.allocate();
    stmt->stmt = new char[strlen(stmt_str)+1];
    stmt->columns = NULL;
    stmt->params = NULL;
    stmt->session = s;
    stmt->for_update = 0;
    stmt->prepared = false;
    stmt->n_params = 0;
    stmt->n_columns = 0;
    stmt->columns_len = 0;
    stmt->oid = 0;
    stmt->next = s->stmts;
    stmt->updated = false;
    s->stmts = stmt;
    char const* p = stmt_str;
    char* dst = stmt->stmt;
    parameter_binding** last = &stmt->params;
    while (*p != '\0') { 
        if (*p == '\'') { 
            do { 
                do { 
                    *dst++ = *p++;
                } while (*p != '\0' && *p != '\'');
                *dst++ = *p;
                if (*p == '\0') { 
                    *last = NULL;
                    stmt->deallocate();
                    statements.deallocate(stmt);
                    return cli_bad_statement;
                }
            } while (*++p == '\'');
        } else if (*p == '%') { 
            stmt->n_params += 1;
            char const* q = p++;
            while (isalnum((unsigned char)*p) || *p == '_') p += 1;
            if (*p == '%') { 
                *last = NULL;
                stmt->deallocate();
                statements.deallocate(stmt);
                return cli_bad_statement;
            }
            parameter_binding* pb = new parameter_binding;
            int len = p - q;
            pb->name = new char[len+1];
            memcpy(pb->name, q, len);
            pb->name[len] = '\0';
            *last = pb;
            last = &pb->next;
            pb->var_ptr = NULL;
            *dst++ = '\0';
        } else { 
            *dst++ = *p++;
        }
    }
    if (dst == stmt->stmt || *(dst-1) != '\0') { 
        *dst++ = '\0';
    }
    stmt->stmt_len = dst - stmt->stmt;
    *last = NULL;
    return stmt->id;
}