Esempio n. 1
0
double get_estoque(requisicao_estoque *req) {

	double saldo;
	OCI_Statement *stmt = OCI_StatementCreate(oracledb);
	check_ociliberror(stmt);

	OCI_Prepare(stmt, "select sum(SALD_CTR) from table(saldo_inicial_tipoest(:emp, :est, :prod, :data, 'S', null, 0))");
	OCI_BindShort(stmt, ":emp", &req->empresa);
	OCI_BindShort(stmt, ":est", &req->controle);
	OCI_BindString(stmt, ":prod", req->produto, 0);
	OCI_Date *d = OCI_DateCreate(NULL);
	OCI_DateSetDate(d, req->data_ano, req->data_mes, req->data_dia);
	OCI_BindDate(stmt, ":data", d);
	
	check_ociliberrorb(OCI_Execute(stmt));
	OCI_Resultset *rs = OCI_GetResultset(stmt);
	check_ociliberror(rs);

	if (OCI_FetchNext(rs)) {
		saldo = OCI_GetDouble(rs, 1);
	}
	else {
		saldo = 0.0;
	}

	OCI_FreeStatement(stmt);
	return saldo;
}
Esempio n. 2
0
int main(void)
{
    OCI_Date *d1, *d2;

    char str[SIZE_STR+1];
   
    if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT))
        return EXIT_FAILURE;

    d1 = OCI_DateCreate(NULL);
    d2 = OCI_DateCreate(NULL);

    strcpy(str, "13041978 20:20:12");

    OCI_DateFromText(d1, str, "DDMMYYYY HH24:MI:SS");
    OCI_DateToText(d1, "DD/MM/YYYY HH24:MI:SS", SIZE_STR, str);
    printf("\nDate is %s\n", str);

    OCI_DateSysDate(d1);
    OCI_DateToText(d1, "DD/MM/YYYY HH24:MI:SS", SIZE_STR, str);
    printf("\nSysdate is %s\n", str);

    OCI_DateAddDays(d1, 5);
    OCI_DateAddMonths(d1, 2);
    OCI_DateToText(d1, "DD/MM/YYYY HH24:MI:SS", SIZE_STR, str);
    printf("\nDate + 5 days and 2 months is %s\n", str);

    OCI_DateAssign(d2, d1);
    OCI_DateLastDay(d1);
    OCI_DateToText(d1, "DD/MM/YYYY HH24:MI:SS", SIZE_STR, str);
    printf("\nLast day of the month : %s\n", str);

    printf("\nNumber of days until the end of the months : %i\n",
            OCI_DateDaysBetween(d1, d2));

    OCI_DateFree(d1);
    OCI_DateFree(d2);

    OCI_Cleanup();
 
    return EXIT_SUCCESS;
}