コード例 #1
0
/*{
** Name:	IIAG4i4Inq4GL	- EXEC 4GL INQUIRE_4GL
**
** Description:
**	Return data for the various possible inquiries.  Note that some 
**	parameters are unused for some inquiries.
**
** Inputs:
**	i4	isvar		data passed by reference?
**	type	i4		ADF type of user's variable
**	length	i4		size of user's variable
**	i4	object		object to inquire about
**	code	i4		Which inquire to perform
**
** Outputs:
**	ind	i2 *		User's null indicator
**	data	PTR		User's data buffer
**
**	Returns:
**		STATUS
**
** History:
**	22-dec-92 (davel)
**		Initial version, based on W4GL version developed by MikeS.
**	25-Aug-1993 (fredv)
**		Included <st.h>.
*/
STATUS
IIAG4i4Inq4GL
(i2 *ind, i4  isvar, i4  type, i4  length, PTR data, i4 object, i4  code)
{
    STATUS		status;
    G4ERRDEF		g4errdef;
    i4			access;
    DB_DATA_VALUE	dbv, odbv;
    i4			intout;
    i4		count, dcount;
    AB_TYPENAME		buf;

    /* Check object, if it applies */
    switch(code)
    {
	case G4IQallrows:
	case G4IQlastrow:
	case G4IQfirstrow:
	    access = G4OA_ARRAY;
	    break;

	case G4IQisarray:
	case G4IQclassname:
	    access = G4OA_OBJECT;
	    break;

	default:
	    access = G4OA_INVALID;
    }
    if (access != G4OA_INVALID)
    {
	if ((status = IIAG4chkobj(object, access, 0, G4INQUIRE_ID)) != OK)
	    return status;
    }

    /* save the object in DBV form */
    IIAG4dbvFromObject(iiAG4savedObject, &odbv);

    /* Set up the output  DBV.  Almost everything is integer */
    switch (code)
    {
	case G4IQclassname:
	case G4IQerrtext:
	    dbv.db_datatype = DB_CHA_TYPE;
	    dbv.db_prec = 0;
	    break;

	default:
	    dbv.db_datatype = DB_INT_TYPE;
	    dbv.db_prec = 0;
	    dbv.db_length = 4;
	    dbv.db_data = (PTR)&intout;
	    break;
    }

    /* Do the right thing for each inquiry */
    switch (code)
    {
	case G4IQerrtext:
	    dbv.db_data = iiAG4errtext;
	    dbv.db_length = STlength(iiAG4errtext);
	    break;

	case G4IQerrno:
	    intout = iiAG4errno & MSGMASK;
	    break;
	
	case G4IQallrows:
	    (void) iiarArAllCount( &odbv, &count, &dcount );
	    intout = count + dcount;
	    break;

	case G4IQlastrow:
	    (void) iiarArAllCount( &odbv, &count, &dcount );
	    intout = count;
	    break;

	case G4IQfirstrow:
	    (void) iiarArAllCount( &odbv, &count, &dcount );
	    intout = 1 - dcount;
	    break;

	case G4IQisarray:
	    intout = (iiarIarIsArray( &odbv ) ? 1 : 0);
	    break;

	case G4IQclassname:
	    iiarCcnClassName( &odbv, buf, FALSE );
	    dbv.db_data = (PTR)buf;
	    dbv.db_length = STlength(buf);
	    break;
    }

    if ((status = IIAG4get_data(&dbv, ind, type, length, data)) != OK)
    {
	g4errdef.errmsg = status;
	g4errdef.numargs = 3;
	g4errdef.args[0] = iiAG4routineNames[G4INQUIRE_ID];
	g4errdef.args[1] = iiAG4routineNames[G4INQUIRE_ID];
	g4errdef.args[2] = iiAG4inqtypes[code];
	IIAG4semSetErrMsg(&g4errdef, TRUE);
    }

    return status;
}
コード例 #2
0
/*{
** Name:	IIAG4set_data   copy data from program variables
**
** Description:
**	Copy data to a DB_DATA_VALUE from the user's program variables.
**	If the target is an object, we validate that the user has specified
**	a valid object handle, and that the types match.
**
**	Most of the error returns use the same set of arguments, which are
**	passed in as part of the G4ERRDEF argument:
**
**	arg[0] = caller name
**	arg[1] = type of data (constant, global, or attribute)
**	arg[2] = name of constant, global, or attribute
**
**	If further arguments are needed, they are filled in.  If a completely
**	differnet set of arguments are needed, we overwrite them here.  The
**	caller will not try to set arguments after calling this function.
**
** Inputs:
**	dbdv		DB_DATA_VALUE *	Data to put
**      ind             i2 *             NULL indicator
**	isvar		i4		Pased by reference?
**      type            i4              ADF type of user variable
**      length          i4              data size of user variable
**      data            PTR             user variable pointer
**
** Outputs:
**	g4errdef	G4ERRDEF *	Error descriptor
**	
**	Returns:
**		STATUS
**					OK
**					E_G4271C_DATA_CONVERSION_SET
**					E_G4271D_NULL_VALUE
**
** History:
**	15-dec-92 (davel)
**		 Initial version, based on W4GL version developed by MikeS.
*/
STATUS
IIAG4set_data
(DB_DATA_VALUE *dbdv, i2 *ind, i4  isvar, i4  type, i4  length, PTR data, 
G4ERRDEF *g4errdef)
{
    STATUS status = OK;
    DB_DATA_VALUE int_dbdv;
    DB_DATA_VALUE *target;
    DB_EMBEDDED_DATA edv;
    i4 objno;
    PTR rowptr;
    ADF_CB *cb = FEadfcb();

    /* 
    ** See if the 4GL target is an object
    */
    if (dbdv->db_datatype == DB_DMY_TYPE)
    {
	/* Yes.  Make an i4 DBDV for the user's specification to go into */
	int_dbdv.db_datatype = DB_INT_TYPE;
	int_dbdv.db_length = sizeof(i4);
	int_dbdv.db_prec = 0;
	int_dbdv.db_data = (PTR)&objno;

	target = &int_dbdv;
    }
    else
    {
	target = dbdv;
    }

    /* Get the data */
    edv.ed_type = type;
    edv.ed_length = length;
    edv.ed_data = isvar ? data : (PTR)&data;
    edv.ed_null = ind;

    if (adh_evcvtdb(cb, &edv, target) != OK)
    {
	if (cb->adf_errcb.ad_errcode == E_AD1012_NULL_TO_NONNULL)
	    status = E_G4271D_NULL_VALUE;
	else
	    status = E_G4271C_DATA_CONVERSION_SET;
    }

    /*
    ** If we got an object number, use it.
    */
    if (status == OK && target == &int_dbdv)
    {
	if (IIAG4gkoGetKnownObject(objno, &rowptr) != OK)
	{
	    g4errdef->numargs = 4;
	    g4errdef->args[3] = ERx("object");
    	    status = E_G4271E_BAD_OBJECT;
	}
	else
	{
	    DB_DATA_VALUE rdbv;

	    IIAG4dbvFromObject(rowptr, &rdbv);

	    /* an error in IIARoasObjAssign() is pretty much always a type
	    ** mismatch.
	    */
	    status = IIARoasObjAssign(&rdbv, dbdv);
	    if (status != OK)
	    {
		/* re-construct the error message.  leave args[0] alone,
		** and fetch the two record type names.
		*/
		AB_TYPENAME aname, rname;

		iiarCcnClassName(dbdv, aname, FALSE);
		iiarCcnClassName(&rdbv, rname, FALSE);
		g4errdef->numargs = 3;
		g4errdef->args[1] = (PTR)rname;
	        g4errdef->args[2] = (PTR)aname;

        	status = E_G42714_BADROWTYPE;
	    }
	}
    }
    return status;
}