Exemple #1
0
/*{
** Name: adu_datenow	- Retrieve current time and date
**
** Description:
**	This routine will fill the result with the INGRES internal date
**	for the current date and time.
**	
** Inputs:
**	adf_scb				Pointer to an ADF session control block.
**	    .adf_errcb			ADF_ERROR struct.
**		.ad_ebuflen		The length, in bytes, of the buffer
**					pointed to by ad_errmsgp.
**		.ad_errmsgp		Pointer to a buffer to put formatted
**					error message in, if necessary.
**      adu_dv				Pointer to the data value to be filled:
**		.db_datatype		Must be DB_DTE_TYPE (non-nullable DATE).
**		.db_prec		Ignored (should be zero).
**		.db_length  		Must be sizeof(DB_DATE)
**		.db_data    		Pointer to result location to fill.
**
** Outputs:
**	adf_scb				Pointer to an ADF session control block.
**	    .adf_errcb			ADF_ERROR struct.  If an
**					error occurs the following fields will
**					be set.  NOTE: if .ad_ebuflen = 0 or
**					.ad_errmsgp = NULL, no error message
**					will be formatted.
**		.ad_errcode		ADF error code for the error.
**		.ad_errclass		Signifies the ADF error class.
**		.ad_usererr		If .ad_errclass is ADF_USER_ERROR,
**					this field is set to the corresponding
**					user error which will either map to
**					an ADF error code or a user-error code.
**		.ad_emsglen		The length, in bytes, of the resulting
**					formatted error message.
**		.adf_errmsgp		Pointer to the formatted error message.
**      adu_dv				Data value to be filled:
**	        .db_data    		INGRES date of "now".
**
**	Returns:
**	      The following DB_STATUS codes may be returned:
**	    E_DB_OK, E_DB_WARN, E_DB_ERROR, E_DB_SEVERE, E_DB_FATAL
**
**	      If a DB_STATUS code other than E_DB_OK is returned, the caller
**	    can look in the field adf_scb.adf_errcb.ad_errcode to determine
**	    the ADF error code.  The following is a list of possible ADF error
**	    codes that can be returned by this routine:
**
**	    E_AD0000_OK			Completed successfully.
**	    E_AD2004_BAD_DTID		Datatype passed in was not valid
**					(must be non-nullable DATE)
**	    E_AD2005_BAD_DTLEN		Length passed in was not valid
**					(must be sizeof(DB_DATE))
**					
**      Exceptions:
**          none
**
** Side Effects:
**          none
**
** History:
**	24-oct-89 (jrb)
**	    Created.
**	19-jun-2006 (gupsh01)
**	    Added support for new datetime datatypes.
**	01-aug-2006 (gupsh01)
**	    Supply nanosecond parameter in adu_cvtime() 
**	    call.
**	29-aug-2006 (gupsh01)
**	    Removed support for ANSI datetime datatypes.
**	    date(now) is only used for ingresdate types.
**	07-nov-2006 (gupsh01)
**	    Fixed the second calculations.
**	08-Feb-2008 (kiria01) b119885
**	    Change dn_time to dn_seconds to avoid the inevitable confusion with
**	    the dn_time in AD_DATENTRNL. Also ensure that the dn structure
**	    is fully iniialised.
*/
DB_STATUS
adu_datenow(
ADF_CB		    *adf_scb,
DB_DATA_VALUE	    *adu_dv)
{
    i4			bintim_secs;
    DB_DATA_VALUE	dv_tmp;
    DB_STATUS		db_stat;
    struct timevect	tv;
    AD_NEWDTNTRNL	dn;

    /* Check validity of inputs */
    if (adu_dv->db_datatype != DB_DTE_TYPE)
	return(adu_error(adf_scb, E_AD2004_BAD_DTID, 0));

    if (adu_dv->db_length != ADF_DTE_LEN)
	return(adu_error(adf_scb, E_AD2005_BAD_DTLEN, 0));


    dv_tmp.db_datatype = DB_INT_TYPE;
    dv_tmp.db_prec = 0;
    dv_tmp.db_length = 4;
    dv_tmp.db_data = (PTR) &bintim_secs;

    if (db_stat = adu_dbconst(adf_scb, &Adf_globs->Adk_bintim_map, &dv_tmp))
	return (db_stat);

    adu_cvtime((i4) bintim_secs, 0, &tv);

    dn.dn_year	= tv.tm_year + AD_TV_NORMYR_BASE;
    dn.dn_month    = tv.tm_mon + AD_TV_NORMMON;
    dn.dn_day   = tv.tm_mday;
    dn.dn_seconds = tv.tm_hour * AD_39DTE_ISECPERHOUR +
		      tv.tm_min * AD_10DTE_ISECPERMIN +
		      tv.tm_sec;
    dn.dn_nsecond = 0;
    AD_TZ_SETNEW(&dn, 0);
    dn.dn_status = AD_DN_ABSOLUTE | AD_DN_TIMESPEC;
    dn.dn_dttype = adu_dv->db_datatype;
    return (adu_7from_dtntrnl (adf_scb, adu_dv, &dn));
}
Exemple #2
0
DB_STATUS
adu_dbmsinfo(
ADF_CB             *adf_scb,
DB_DATA_VALUE      *dv1,
DB_DATA_VALUE      *rdv)
{
    i4			i = Adf_globs->Adi_num_dbis;
    i4			found = FALSE;
    ADF_DBMSINFO	*dbi = Adf_globs->Adi_dbi;
    i4			dbi_size = sizeof(dbi->dbi_reqname);
    i4			in_size  = ((DB_TEXT_STRING *)dv1->db_data)->db_t_count;
    char		*in_str  = (char *)
				    ((DB_TEXT_STRING *)dv1->db_data)->db_t_text;
    register i4	j;
    register char	*c1;
    register char	*c2;
    char		ch_tmp;
    ALIGN_RESTRICT	*tbuf;
    DB_STATUS		db_stat = E_DB_OK;
    i4			cmp;
    DB_DATA_VALUE	tmp_dv;
    DB_ERROR		err;
    ADK_MAP		*kmap;
    char		localbuf[2004];
    bool		uselocal = TRUE;


    if (in_size <= dbi_size)    /* No possible match if input is bigger */
    {
	/* Find the request in the dbmsinfo() request table */
	while (i--)
	{
	    cmp = TRUE;
	    c1  = dbi->dbi_reqname;
	    c2  = in_str;
	    j   = 0;
	    while (j < in_size  &&  *c1 != 0)
	    {
		CMtolower(c2, &ch_tmp);
		if (*c1 != ch_tmp)
		{
		    cmp = FALSE;
		    break;
		}
		c1++;
		c2++;
		j++;
	    }

	    if (    cmp
		&& (in_size == dbi_size  ||  (*c1 == 0  &&  j == in_size))
	       )
	    {
		found = TRUE;
		break;
	    }

	    dbi++;
	}
    }


    if (!found)
    {
	((DB_TEXT_STRING *)rdv->db_data)->db_t_count = 0;
	db_stat = E_DB_OK;
    }
    else
    {
	/* {@fix_me@} ... eventually, we have to handle 1 input, and
	**		    lenspecs that are not FIXED LENGTH
	*/
	if (dbi->dbi_num_inputs || dbi->dbi_lenspec.adi_lncompute != ADI_FIXED)
	    return(adu_error(adf_scb, E_AD9999_INTERNAL_ERROR, 0));

	tmp_dv.db_datatype = dbi->dbi_dtr;
	tmp_dv.db_length   = dbi->dbi_lenspec.adi_fixedsize;

	if (tmp_dv.db_length >= 2004)
	{
	    uselocal = FALSE;
	    tbuf = (ALIGN_RESTRICT *)MEreqmem(0,
					  ((DB_GW4_MAXSTRING + DB_CNTSIZE - 1) /
					  sizeof(ALIGN_RESTRICT)) + 1,
					  FALSE, NULL);
	    tmp_dv.db_data     = (PTR)tbuf;
	}
	else tmp_dv.db_data     = (PTR)&localbuf[0];

	/*
	** Is request one of the query constants?  If so, use adu_dbconst()
	** instead of the dbi function found in the dbi table.
	*/
	if      (dbi == Adf_globs->Adk_bintim_map.adk_dbi)
	    kmap = &Adf_globs->Adk_bintim_map;
	else if (dbi == Adf_globs->Adk_cpu_ms_map.adk_dbi)
	    kmap = &Adf_globs->Adk_cpu_ms_map;
	else if (dbi == Adf_globs->Adk_et_sec_map.adk_dbi)
	    kmap = &Adf_globs->Adk_et_sec_map;
	else if (dbi == Adf_globs->Adk_dio_cnt_map.adk_dbi)
	    kmap = &Adf_globs->Adk_dio_cnt_map;
	else if (dbi == Adf_globs->Adk_bio_cnt_map.adk_dbi)
	    kmap = &Adf_globs->Adk_bio_cnt_map;
	else if (dbi == Adf_globs->Adk_pfault_cnt_map.adk_dbi)
	    kmap = &Adf_globs->Adk_pfault_cnt_map;
	else if (dbi == Adf_globs->Adk_curr_date_map.adk_dbi)
	    kmap = &Adf_globs->Adk_curr_date_map;
	else if (dbi == Adf_globs->Adk_curr_time_map.adk_dbi)
	    kmap = &Adf_globs->Adk_curr_time_map;
	else if (dbi == Adf_globs->Adk_curr_tstmp_map.adk_dbi)
	    kmap = &Adf_globs->Adk_curr_tstmp_map;
	else if (dbi == Adf_globs->Adk_local_time_map.adk_dbi)
	    kmap = &Adf_globs->Adk_local_time_map;
	else if (dbi == Adf_globs->Adk_local_tstmp_map.adk_dbi)
	    kmap = &Adf_globs->Adk_local_tstmp_map;
	else
	    kmap = NULL;

	if (kmap == NULL)
	    db_stat = (*dbi->dbi_func)(dbi, NULL, &tmp_dv, &err);
	else
	    db_stat = adu_dbconst(adf_scb, kmap, &tmp_dv);
	
	if (DB_SUCCESS_MACRO(db_stat))
	{
	    db_stat = adu_ascii(adf_scb, &tmp_dv, rdv);
	}

	if (!uselocal)
	    MEfree((PTR)tbuf);
    }

    return (db_stat);
}