Exemple #1
0
/*
 * The routine VALconvert transforms a value for interpretation in a
 * certain type. It uses some standard cast conventions to do this.
 * The result, a pointer to a value, is returned. If there are illegal
 * values, or type combinations involved, it gives up with an
 * ILLEGALVALUE.
 */
ptr
VALconvert(int typ, ValPtr t)
{
	int src_tpe = t->vtype;
	ValRecord dst;

	dst.vtype = typ;
	/* use base types for user types */
	if (src_tpe > TYPE_str)
		src_tpe = ATOMstorage(src_tpe);
	if (dst.vtype > TYPE_str)
		dst.vtype = ATOMstorage(dst.vtype);
	else if (dst.vtype == TYPE_void)
		dst.vtype = TYPE_oid;

	/* first convert into a new location */
	if (VARconvert(&dst, t, 0) == GDK_FAIL)
		return ILLEGALVALUE;

	/* then maybe free the old */
	if (src_tpe != dst.vtype &&
	    t->vtype != typ &&
	    dst.vtype != TYPE_void &&
	    (src_tpe >= TYPE_str || dst.vtype >= TYPE_str))
		VALclear(t);
	/* and finally copy the result */
	*t = dst;
	/* make sure we return the correct type (not the storage type) */
	t->vtype = typ;
	return VALget(t);
}
Exemple #2
0
void
stack_pop_until(mvc *sql, int top) 
{
	while(sql->topvars > top) {
		sql_var *v = &sql->vars[--sql->topvars];

		c_delete(v->name);
		VALclear(&v->value);
		v->value.vtype = 0;
	}
}
Exemple #3
0
void
stack_set_var(mvc *sql, const char *name, ValRecord *v)
{
	int i;

	for (i = sql->topvars-1; i >= 0; i--) {
		if (!sql->vars[i].frame && strcmp(sql->vars[i].name, name)==0) {
			VALclear(&sql->vars[i].value);
			VALcopy(&sql->vars[i].value, v);
		}
	}
}
Exemple #4
0
void 
stack_pop_frame(mvc *sql)
{
	while(!sql->vars[--sql->topvars].frame) {
		sql_var *v = &sql->vars[sql->topvars];

		c_delete(v->name);
		VALclear(&v->value);
		v->value.vtype = 0;
		if (v->t && v->view) 
			table_destroy(v->t);
		else if (v->rel)
			rel_destroy(v->rel);
	}
	if (sql->topvars && sql->vars[sql->topvars].name)  
		c_delete(sql->vars[sql->topvars].name);
	sql->frame--;
}
Exemple #5
0
void 
stack_pop_frame(mvc *sql)
{
	while(sql->vars[--sql->topvars].s) {
		sql_var *v = &sql->vars[sql->topvars];

		_DELETE(v->name);
		VALclear(&v->value);
		v->value.vtype = 0;
		if (v->type.comp_type && v->view) 
			table_destroy(v->type.comp_type);
		else if (v->s && v->view)
			rel_destroy(v->s);
	}
	if (sql->topvars && sql->vars[sql->topvars].name)  
		_DELETE(sql->vars[sql->topvars].name);
	sql->frame--;
}
Exemple #6
0
/* Convert (cast) the value in T to the type TYP, do this in place.
 * Return a pointer to the converted value, or NULL if the conversion
 * didn't succeed.  If the conversion didn't succeed, the original
 * value is not modified.  Also see VARconvert. */
ptr
VALconvert(int typ, ValPtr t)
{
	int src_tpe = t->vtype;
	ValRecord dst;

	dst.vtype = typ;

	/* first convert into a new location */
	if (VARconvert(&dst, t, 0) != GDK_SUCCEED)
		return NULL;

	/* then maybe free the old */
	if (src_tpe != dst.vtype &&
	    t->vtype != typ &&
	    dst.vtype != TYPE_void &&
	    (src_tpe >= TYPE_str || dst.vtype >= TYPE_str))
		VALclear(t);
	/* and finally copy the result */
	*t = dst;
	/* make sure we return the correct type (not the storage type) */
	t->vtype = typ;
	return VALget(t);
}