Beispiel #1
0
static inline const void *
read_bytes(lua_State *L, struct bson_reader *br, int sz) {
	const void * r = br->ptr;
	check_reader(L, br, sz);
	br->ptr+=sz;
	br->size-=sz;
	return r;
}
Beispiel #2
0
std::string sqlite3_reader::getstring(int index) {
	check_reader(index);
    const int l_size = sqlite3_column_bytes(this->cmd->stmt, index);
    if(l_size) //[+]PPA
   	   return std::string((const char*)sqlite3_column_text(this->cmd->stmt, index), l_size);
    else
       return "";   
}
Beispiel #3
0
static inline int32_t
read_int32(lua_State *L, struct bson_reader *br) {
	check_reader(L, br, 4);
	const uint8_t * b = br->ptr;
	uint32_t v = b[0] | b[1]<<8 | b[2]<<16 | b[3]<<24;
	br->ptr+=4;
	br->size-=4;
	return (int32_t)v;
}
Beispiel #4
0
void sqlite3_reader::getblob(int index, std::vector<uint8_t>& p_result)
{
	check_reader(index);
	const int l_size = sqlite3_column_bytes(this->cmd->stmt, index);
    p_result.resize(l_size);
	if(l_size)
	   memcpy(&p_result[0],sqlite3_column_blob(this->cmd->stmt, index),l_size);
	return;
}
Beispiel #5
0
static inline int
read_byte(lua_State *L, struct bson_reader *br) {
	check_reader(L, br, 1);
	const uint8_t * b = br->ptr;
	int r =  b[0];
	++br->ptr;
	--br->size;

	return r;
}
Beispiel #6
0
static inline int64_t
read_int64(lua_State *L, struct bson_reader *br) {
	check_reader(L, br, 8);
	const uint8_t * b = br->ptr;
	uint32_t lo = b[0] | b[1]<<8 | b[2]<<16 | b[3]<<24;
	uint32_t hi = b[4] | b[5]<<8 | b[6]<<16 | b[7]<<24;
	uint64_t v = (uint64_t)lo | (uint64_t)hi<<32;
	br->ptr+=8;
	br->size-=8;
	return (int64_t)v;
}
Beispiel #7
0
bool sqlite3_reader::getblob(int index, void* p_result, int p_size)
{
	check_reader(index);
	const void* l_blob = sqlite3_column_blob(this->cmd->stmt, index);
	if(l_blob)
	{
		memcpy(p_result,l_blob,p_size);
	    return true;
	}
	else
		return false;
}
Beispiel #8
0
/* closing */
static int
qaff_r_close(lua_State *L)
{
    mAffReader *b = qlua_checkAffReader(L, 1);

    check_reader(L, b);
    qlua_Aff_enter(L);
    aff_reader_close(b->ptr);
    b->ptr = 0;
    qlua_Aff_leave();
    
    return 0;
}
Beispiel #9
0
static inline lua_Number
read_double(lua_State *L, struct bson_reader *br) {
	check_reader(L, br, 8);
	union {
		uint64_t i;
		double d;
	} v;
	const uint8_t * b = br->ptr;
	uint32_t lo = b[0] | b[1]<<8 | b[2]<<16 | b[3]<<24;
	uint32_t hi = b[4] | b[5]<<8 | b[6]<<16 | b[7]<<24;
	v.i = (uint64_t)lo | (uint64_t)hi<<32;
	br->ptr+=8;
	br->size-=8;
	return v.d;
}
Beispiel #10
0
static int
qaff_r_status(lua_State *L)
{
    mAffReader *b = qlua_checkAffReader(L, 1);
    const char *s;

    check_reader(L, b);

    qlua_Aff_enter(L);
    s = aff_reader_errstr(b->ptr);
    qlua_Aff_leave();
        
    if (s == 0)
        lua_pushnil(L);
    else
        lua_pushstring(L, s);

    return 1;
}
Beispiel #11
0
static int
qaff_r_chpath(lua_State *L)
{
    mAffReader *b = qlua_checkAffReader(L, 1);
    const char *p = luaL_checkstring(L, 2);
    struct AffNode_s *r;

    check_reader(L, b);

    qlua_Aff_enter(L);
    r = qlua_AffReaderChPath(b, p);
    b->dir = r;
    qlua_Aff_leave();

    if (r != NULL)
        return 0;
    else
        return luaL_error(L, aff_reader_errstr(b->ptr));
}
Beispiel #12
0
static int
qaff_r_list(lua_State *L)
{
    mAffReader *b = qlua_checkAffReader(L, 1);
    struct AffNode_s *r;
    const char *p = luaL_checkstring(L, 2);
    qAffDir dir;
    
    check_reader(L, b);

    qlua_Aff_enter(L);
    r = qlua_AffReaderChPath(b, p);
    if (r == 0)
        return luaL_error(L, aff_reader_errstr(b->ptr));
    lua_newtable(L);
    dir.L = L;
    dir.k = 1;
    aff_node_foreach(r, qar_get_list, &dir);
    qlua_Aff_leave();

    return 1;
}
Beispiel #13
0
long long sqlite3_reader::getint64(int index) {
	check_reader(index);
	return sqlite3_column_int64(this->cmd->stmt, index);
}
Beispiel #14
0
std::wstring sqlite3_reader::getcolname16(int index) {
	check_reader(index);
	return (const wchar_t*)sqlite3_column_name16(this->cmd->stmt, index);
}
Beispiel #15
0
std::wstring sqlite3_reader::getstring16(int index) {
	check_reader(index);
	return std::wstring((const wchar_t*)sqlite3_column_text16(this->cmd->stmt, index), sqlite3_column_bytes16(this->cmd->stmt, index)/2);
}
Beispiel #16
0
std::string sqlite3_reader::getcolname(int index) {
	check_reader(index);
	return sqlite3_column_name(this->cmd->stmt, index);
}
Beispiel #17
0
static int
qaff_r_read(lua_State *L)
{
    mAffReader *b = qlua_checkAffReader(L, 1);
    const char *p = luaL_checkstring(L, 2);
    struct AffNode_s *n;
    uint32_t size;

    check_reader(L, b);

    qlua_Aff_enter(L);
    n = qlua_AffReaderChPath(b, p);
    if (n == 0)
        goto end;
    size = aff_node_size(n);

    switch (aff_node_type(n)) {
    case affNodeVoid:
        lua_pushboolean(L, 1);
        qlua_Aff_leave();
        return 1;
    case affNodeChar: {
		char *d = qlua_malloc(L, size + 1);

        if (aff_node_get_char(b->ptr, n, d, size) == 0) {
            d[size] = 0;
            lua_pushstring(L, d);
            qlua_Aff_leave();
			qlua_free(L, d);

            return 1;
        }
		qlua_free(L, d);
        break;
    }
    case affNodeInt: {
		uint32_t *d = qlua_malloc(L, size * sizeof (uint32_t));

        if (aff_node_get_int(b->ptr, n, d, size) == 0) {
            mVecInt *v = qlua_newVecInt(L, size);
            int i;

            for (i = 0; i < size; i++)
                v->val[i] = d[i];
            qlua_Aff_leave();
			qlua_free(L, d);

            return 1;
        }
		qlua_free(L, d);
        break;
    }
    case affNodeDouble: {
		double *d = qlua_malloc(L, size * sizeof (double));

        if (aff_node_get_double(b->ptr, n, d, size) == 0) {
            mVecReal *v = qlua_newVecReal(L, size);
            int i;

            for (i = 0; i < size; i++)
                v->val[i] = d[i];
            qlua_Aff_leave();
			qlua_free(L, d);
			
            return 1;
        }
		qlua_free(L, d);
        break;
    }
    case affNodeComplex: {
		double _Complex *d = qlua_malloc(L, size * sizeof (double _Complex));

        if (aff_node_get_complex(b->ptr, n, d, size) == 0) {
            mVecComplex *v = qlua_newVecComplex(L, size);
            int i;

            for (i = 0; i < size; i++) {
                QLA_real(v->val[i]) = creal(d[i]);
                QLA_imag(v->val[i]) = cimag(d[i]);
            }
            qlua_Aff_leave();
			qlua_free(L, d);

            return 1;
        }
		qlua_free(L, d);
        break;
    }
    default:
        goto end;
    }
    qlua_Aff_leave();
    return luaL_error(L, aff_reader_errstr(b->ptr));

end:
    qlua_Aff_leave();
    return luaL_error(L, "bad arguments for AFF read");
}
Beispiel #18
0
double sqlite3_reader::getdouble(int index) {
	check_reader(index);
	return sqlite3_column_double(this->cmd->stmt, index);
}