Ejemplo n.º 1
0
int
p_session_sql_dml(
		/* + */ value v_session, type t_session,
		/* + */ value v_SQL, type t_SQL,
		/* - */ value v_rows, type t_rows
		)
{
	session_t * session;
	cursor_t * cursor;
	char * SQL;
	word rows, *prows;
	int res;

	Check_String(t_SQL);
	Check_Output_Integer(t_rows);
	Get_Typed_Object(v_session,t_session,&session_handle_tid,session);


	cursor = session_sql_prepare(session, StringStart(v_SQL), StringLength(v_SQL), 0);
	if (NULL == cursor)
	    Bip_Error(dbi_errno);

	if (res = cursor_sql_execute(cursor, 1))
	{
	    cursor_free(cursor);
	    Bip_Error(Error_Code(res));
	}

	cursor_field_value(cursor, rows_processed_count, (void **)&prows);
	rows = *prows;

	cursor_free(cursor);

	Return_Unify_Integer(v_rows, t_rows, rows);
}
Ejemplo n.º 2
0
static int
p_atom_length(value aval, type atag, value nval, type ntag)
{
        Check_Output_Integer(ntag);
	if (IsRef(atag))
	    { Bip_Error(PDELAY_1); }
	Check_Output_Atom_Or_Nil(aval, atag);
	Return_Unify_Integer(nval, ntag, DidLength(aval.did));
}
Ejemplo n.º 3
0
static int
p_string_length(value sval, type stag, value nval, type ntag)
{
        Check_Output_Integer(ntag);
	if (IsRef(stag))
	    { Bip_Error(PDELAY_1); }
	else if (!IsString(stag))
	    { Bip_Error(TYPE_ERROR); }

	Return_Unify_Integer(nval, ntag, StringLength(sval));
}
Ejemplo n.º 4
0
int
p_session_error_value(
		/* + */ value v_session, type t_session,
		/* + */ value v_code, type t_code,
		/* + */ value v_message, type t_message
		)
{
	int code;
	char * message;
	pword p;
	session_t * session;
	Prepare_Requests;

	Check_Output_Integer(t_code);
	Check_Output_String(t_message);
	Get_Typed_Object(v_session,t_session,&session_handle_tid,session);

	session_error_value(session, &code, &message);

	Make_String(&p,message);
	Request_Unify_Integer(v_code, t_code, code);
	Request_Unify_Pw(v_message, t_message, p.val, p.tag);
	Succeed;
}
Ejemplo n.º 5
0
static int
p_max_error(value val1, type tag1)
{
	Check_Output_Integer(tag1);
	Return_Unify_Integer(val1, tag1, MAX_ERRORS - 1);
}
Ejemplo n.º 6
0
static int
p_substring(value val1, type tag1, value val2, type tag2, value valp, type tagp)
{
	char	*p1, *p2;
	word	length1, length2;
	word	i, j;

        /* string1 and string2 must be strings; posn an integer/variable. */ 

	Check_Output_Integer(tagp);
        Check_Output_String(tag1);
        Check_String(tag2);
	Error_If_Ref(tag1);

	length1 = StringLength(val1);
	length2 = StringLength(val2);

	if (!IsRef(tagp))
	{
		if (valp.nint <= 0 || valp.nint > length1 + 1)
		{
		    Bip_Error(RANGE_ERROR);
		}
		if (valp.nint > length1 - length2 + 1)
		{
		    Fail_;	/* string 2 is too long to match */
		}

		p1 = StringStart(val1) + valp.nint - 1;
		p2 = StringStart(val2);
		for(j = 0; j < length2; ++j)
		{
		    if (p1[j] != p2[j])
		    {
			Fail_;
		    }
		}
		Succeed_;
	}
	else
	{
		p1 = StringStart(val1);
		p2 = StringStart(val2);
		for (i = 1; i <= length1 - length2 + 1; i++)
		{
			/*
	         	 * search through p (i.e. string1) 'length2' characters
		 	 * at a time for val2.str (i.e. string2), till the end
		 	 * of string1. 
			 */ 
			for(j = 0; j < length2; ++j)
			{
			    if (p1[j] != p2[j])
				break;
			}
			if (j == length2)
			{
			    Return_Unify_Integer(valp, tagp, i);
			}
			p1++;
		}
		/* if not found, fail. */	
		Fail_;
	}	
}