DBD-Oracle

 view release on metacpan or  search on metacpan

oci8.c  view on Meta::CPAN

	OCIStmtPrepare_log_stat(imp_sth, lr->stmthp, errhp,
		(text*)SvPVX(sql_select), SvCUR(sql_select), OCI_NTV_SYNTAX,
			OCI_DEFAULT, status);

	if (status != OCI_SUCCESS) {
		OCIHandleFree(lr->stmthp, OCI_HTYPE_STMT);
		Safefree(lr);
		return oci_error(sth, errhp, status, "OCIStmtPrepare/LOB refetch");
	}

	/* bind the rowid input */
	OCIDescriptorAlloc_ok(imp_sth, imp_sth->envhp, &lr->rowid, OCI_DTYPE_ROWID);
	OCIBindByName_log_stat(imp_sth, lr->stmthp, &lr->bindhp, errhp, (text*)":rid", 4,
		&lr->rowid, sizeof(OCIRowid*), SQLT_RDD, 0,0,0,0,0, OCI_DEFAULT, status);
	if (status != OCI_SUCCESS) {
		OCIDescriptorFree_log(imp_sth, lr->rowid, OCI_DTYPE_ROWID);
		OCIHandleFree(lr->stmthp, OCI_HTYPE_STMT);
		Safefree(lr);
		return oci_error(sth, errhp, status, "OCIBindByPos/LOB refetch");
	}

		/* define the output fields */
	for(i=0; i < lr->num_fields; ++i) {
		OCIDefine *defnp = NULL;
		imp_fbh_t *fbh = &lr->fbh_ary[i];
		phs_t *phs;
		SV **phs_svp = hv_fetch(imp_sth->all_params_hv, fbh->name,strlen(fbh->name), 0);
		if (!phs_svp)
			croak("panic: LOB refetch for '%s' param (%ld) - name not found",fbh->name,(unsigned long)i+1);
		phs = (phs_t*)(void*)SvPVX(*phs_svp);
		fbh->special = phs;
		if (DBIc_DBISTATE(imp_sth)->debug >= 3 || dbd_verbose >= 3 )
			PerlIO_printf(
                DBIc_LOGPIO(imp_sth),
				"		lob refetch %d for '%s' param: ftype %d setup\n",
		(int)i+1,fbh->name, fbh->dbtype);
		fbh->fb_ary = fb_ary_alloc(fbh->disize, 1);
		OCIDefineByPos_log_stat(imp_sth, lr->stmthp, &defnp, errhp, (ub4)i+1,
			&fbh->desc_h, -1, (ub2)fbh->ftype,
		fbh->fb_ary->aindp, 0, fbh->fb_ary->arcode, OCI_DEFAULT, status);
		if (status != OCI_SUCCESS) {
			OCIDescriptorFree_log(imp_sth, lr->rowid, OCI_DTYPE_ROWID);
			OCIHandleFree(lr->stmthp, OCI_HTYPE_STMT);
			Safefree(lr);
			fb_ary_free(fbh->fb_ary);
			fbh->fb_ary = NULL;
			return oci_error(sth, errhp, status, "OCIDefineByPos/LOB refetch");
		}
	}

	OCIHandleFree_log_stat(imp_sth, imp_sth->dschp, OCI_HTYPE_DESCRIBE, status);

	imp_sth->lob_refetch = lr;	/* structure copy */
	return 1;
}

int
post_execute_lobs(SV *sth, imp_sth_t *imp_sth, ub4 row_count)	/* XXX leaks handles on error */
{

	/* To insert a new LOB transparently (without using 'INSERT . RETURNING .')	*/
	/* we have to insert an empty LobLocator and then fetch it back from the	*/
	/* server before we can call OCILobWrite on it! This function handles that.	*/
	dTHX;
	sword status;
	int i;
	OCIError *errhp = imp_sth->errhp;
	lob_refetch_t *lr;
	D_imp_dbh_from_sth;
	SV *dbh = (SV*)DBIc_MY_H(imp_dbh);

	if (!imp_sth->auto_lob)
		 return 1;	/* application doesn't want magical lob handling */

	if (imp_sth->stmt_type == OCI_STMT_BEGIN || imp_sth->stmt_type == OCI_STMT_DECLARE){
	/* PL/SQL is handled by lob_phs_ora_free_templobpost_execute */
		if (imp_sth->has_lobs) { 	  /*get rid of OCILob Temporary used in non inout bind*/
			SV *phs_svp;
			I32 i;
			char *p;
			hv_iterinit(imp_sth->all_params_hv);
			while( (phs_svp = hv_iternextsv(imp_sth->all_params_hv, &p, &i)) != NULL ) {
				phs_t *phs = (phs_t*)(void*)SvPVX(phs_svp);



				if (phs->desc_h && !phs->is_inout){
                    OCILobFreeTemporary_log_stat(imp_sth, imp_sth->svchp, imp_sth->errhp, phs->desc_h, status);


				/*	boolean lobEmpty=1;*/
				/*	OCIAttrSet_log_stat(phs->desc_h, phs->desc_t,&lobEmpty, 0, OCI_ATTR_LOBEMPTY, imp_sth->errhp, status);*/
				/*	OCIHandleFree_log_stat(phs->desc_h, phs->desc_t, status);*/
				}
				/*this seem to cause an error later on so I just got rid of it for Now does */
				/* not seem to kill anything */
			}
		}
		return 1;
	}

	if (row_count == 0)
		return 1;	/* nothing to do */
	if (row_count  > 1)
		return oci_error(sth, errhp, OCI_ERROR, "LOB refetch attempted for multiple rows");

	if (!imp_sth->lob_refetch) {
		if (!init_lob_refetch(sth, imp_sth))
			return 0;	/* init_lob_refetch already called oci_error */
	}
	lr = imp_sth->lob_refetch;

	OCIAttrGet_stmhp_stat(imp_sth, lr->rowid, 0, OCI_ATTR_ROWID,status);

	if (status != OCI_SUCCESS)
		return oci_error(sth, errhp, status, "OCIAttrGet OCI_ATTR_ROWID /LOB refetch");

	OCIStmtExecute_log_stat(imp_sth, imp_sth->svchp, lr->stmthp, errhp,1, 0, NULL, NULL, OCI_DEFAULT, status);	/* execute and fetch */

	if (status != OCI_SUCCESS)
		return oci_error(sth, errhp, status,



( run in 1.329 second using v1.01-cache-2.11-cpan-39bf76dae61 )