Пример #1
0
static SQRESULT sq_mysql_result_row_as_table(HSQUIRRELVM v){
	SQ_FUNC_VARS(v);
	GET_mysql_result_INSTANCE();
	SQ_OPT_INTEGER(v, 2, row, -1);
    if(row < 0){
        sq_pushstring(v, _curr_row_key, -1);
        if(sq_get(v, 1) == SQ_OK){
            sq_getinteger(v, -1, &row);
        }
    }
    int row_count = dlmysql_num_rows(self);
    if(row < 0 || row >= row_count) return sq_throwerror(v, _SC("invalid row (" _PRINT_INT_FMT ")"), row);

    int col_count = dlmysql_num_fields(self);
    sq_newtableex(v, col_count);
    dlmysql_data_seek(self, row);
    const MYSQL_ROW res_row = dlmysql_fetch_row(self);
    unsigned long *lengths = dlmysql_fetch_lengths(self);
    MYSQL_FIELD *fields = dlmysql_fetch_fields(self);
    for(int i=0; i < col_count; ++i){
        sq_pushstring(v, fields[i].name, -1);
        sq_pushstring(v, (const SQChar*)res_row[i], lengths[i]);
        sq_rawset(v, -3);
    }
	return 1;
}
static ngx_int_t
ngx_squ_tcp_request_module_init(ngx_cycle_t *cycle)
{
    int              n;
    SQRESULT         rc;
    ngx_squ_conf_t  *scf;

    ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0,
                   "squ tcp request module init");

    scf = (ngx_squ_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_squ_module);

    sq_pushroottable(scf->v);

    sq_pushstring(scf->v, NGX_SQU_TABLE, sizeof(NGX_SQU_TABLE) - 1);
    rc = sq_get(scf->v, -2);
    sq_pushstring(scf->v, NGX_SQU_TCP_TABLE, sizeof(NGX_SQU_TCP_TABLE) - 1);
    rc = sq_get(scf->v, -2);

    n = sizeof(ngx_squ_tcp_request_methods) / sizeof(SQRegFunction) - 1;

    sq_pushstring(scf->v, "request", sizeof("request") - 1);
    sq_newtableex(scf->v, n);

    for (n = 0; ngx_squ_tcp_request_methods[n].name != NULL; n++) {
        sq_pushstring(scf->v, ngx_squ_tcp_request_methods[n].name, -1);
	sq_newclosure(scf->v, ngx_squ_tcp_request_methods[n].f, 0);
	rc = sq_newslot(scf->v, -3, SQFalse);
    }

    rc = sq_newslot(scf->v, -3, SQFalse);

    sq_pop(scf->v, 3);

    return NGX_OK;
}