[svn:dbd-oracle] r14882 - dbd-oracle/branches/new_lobs
[email protected] Wed, 1 Jun 2011 07:47:33 -0700 (PDT)
| Newsgroups | perl.dbd.oracle.changes |
|---|---|
| Message-ID | <[email protected]> |
Author: byterock
Date: Wed Jun 1 07:47:33 2011
New Revision: 14882
Modified:
dbd-oracle/branches/new_lobs/dbdimp.c
dbd-oracle/branches/new_lobs/dbdimp.h
dbd-oracle/branches/new_lobs/oci8.c
Log:
Working version. This got rid of a whole whack of code
Modified: dbd-oracle/branches/new_lobs/dbdimp.c
==============================================================================
--- dbd-oracle/branches/new_lobs/dbdimp.c (original)
+++ dbd-oracle/branches/new_lobs/dbdimp.c Wed Jun 1 07:47:33 2011
@@ -4055,9 +4055,6 @@
/* Free off contents of imp_sth */
- if (imp_sth->lob_refetch)
- ora_free_lob_refetch(sth, imp_sth);
-
fields = DBIc_NUM_FIELDS(imp_sth);
imp_sth->in_cache = 0;
imp_sth->eod_errno = 1403;
Modified: dbd-oracle/branches/new_lobs/dbdimp.h
==============================================================================
--- dbd-oracle/branches/new_lobs/dbdimp.h (original)
+++ dbd-oracle/branches/new_lobs/dbdimp.h Wed Jun 1 07:47:33 2011
@@ -85,7 +85,6 @@
-typedef struct lob_refetch_st lob_refetch_t; /* Define sth implementor data structure */
/*statement structure */
@@ -109,7 +108,6 @@
ub4 piece_size; /*used in callback to set the size of the piece to get*/
int has_lobs; /*Statement has bound LOBS */
int ret_lobs; /*Statement returns LOBS */
- lob_refetch_t *lob_refetch;
int nested_cursor; /* cursors fetched from SELECTs */
AV *bind_tuples; /* Bind tuples in array execute, or NULL */
int rowwise; /* If true, bind_tuples is list of */
@@ -365,7 +363,6 @@
SV * ora_create_xml _((SV *dbh, char *source));
-void ora_free_lob_refetch _((SV *sth, imp_sth_t *imp_sth));
void dbd_phs_avsv_complete _((phs_t *phs, I32 index, I32 debug));
void dbd_phs_sv_complete _((phs_t *phs, SV *sv, I32 debug));
int post_execute_lobs _((SV *sth, imp_sth_t *imp_sth, ub4 row_count));
Modified: dbd-oracle/branches/new_lobs/oci8.c
==============================================================================
--- dbd-oracle/branches/new_lobs/oci8.c (original)
+++ dbd-oracle/branches/new_lobs/oci8.c Wed Jun 1 07:47:33 2011
@@ -1581,104 +1581,111 @@
D_imp_dbh_from_sth ;
sword status;
ub4 lobEmpty = 0;
- if (phs->desc_h && phs->desc_t == OCI_DTYPE_LOB)
- ora_free_templob(sth, imp_sth, (OCILobLocator*)phs->desc_h);
- if (!phs->desc_h) {
- ++imp_sth->has_lobs;
- phs->desc_t = OCI_DTYPE_LOB;
- OCIDescriptorAlloc_ok(imp_sth->envhp,
- &phs->desc_h, phs->desc_t);
- }
-
- OCIAttrSet_log_stat(phs->desc_h, phs->desc_t,
- &lobEmpty, 0, OCI_ATTR_LOBEMPTY, imp_sth->errhp, status);
-
- if (status != OCI_SUCCESS)
- return oci_error(sth, imp_sth->errhp, status, "OCIAttrSet OCI_ATTR_LOBEMPTY");
+ if ( imp_sth->auto_lob && (imp_sth->stmt_type != OCI_STMT_BEGIN &&
+ imp_sth->stmt_type != OCI_STMT_DECLARE)){
- if (!SvPOK(phs->sv)) { /* normalizations for special cases */
- if (SvOK(phs->sv)) { /* ie a number, convert to string ASAP */
- if (!(SvROK(phs->sv) && phs->is_inout))
- sv_2pv(phs->sv, &PL_na);
+ if (phs->ftype == SQLT_BLOB) {
+ phs->ftype = SQLT_BIN;
}
- else { /* ensure we're at least an SVt_PV (so SvPVX etc work) */
- if(SvUPGRADE(phs->sv, SVt_PV)){} /* For GCC not to warn on unused result */
+ else{
+ phs->ftype = SQLT_CHR;
}
- }
-
- phs->indp = (SvOK(phs->sv)) ? 0 : -1;
- phs->progv = (char*)&phs->desc_h;
- phs->maxlen = sizeof(OCILobLocator*);
-
- if (phs->is_inout)
- phs->out_prepost_exec = lob_phs_post_execute;
- /* accept input LOBs */
-
- if (sv_isobject(phs->sv) && sv_derived_from(phs->sv, "OCILobLocatorPtr")) {
-
- OCILobLocator *src;
- OCILobLocator **dest;
- src = INT2PTR(OCILobLocator *, SvIV(SvRV(phs->sv)));
- dest = (OCILobLocator **) phs->progv;
-
- OCILobLocatorAssign_log_stat(imp_dbh->svchp, imp_sth->errhp, src, dest, status);
- if (status != OCI_SUCCESS) {
- oci_error(sth, imp_sth->errhp, status, "OCILobLocatorAssign");
- return 0;
+ if(SvPOK(phs->sv)){/* just a check to make sure it is not NULL*/
+ phs->maxlen=(long)SvLEN(phs->sv);
}
+ return 1;
}
-
- /* create temporary LOB for PL/SQL placeholder */
- else if (imp_sth->stmt_type == OCI_STMT_BEGIN ||
- imp_sth->stmt_type == OCI_STMT_DECLARE) {
- ub4 amtp;
-
- if(SvUPGRADE(phs->sv, SVt_PV)){/* For GCC not to warn on unused result */}; /* just in case */
-
- amtp = SvCUR(phs->sv); /* XXX UTF8? */
-
- /* Create a temp lob for non-empty string */
-
- if (amtp > 0) {
- ub1 lobtype = (phs->ftype == 112 ? OCI_TEMP_CLOB : OCI_TEMP_BLOB);
- OCILobCreateTemporary_log_stat(imp_dbh->svchp, imp_sth->errhp,
- (OCILobLocator *) phs->desc_h, (ub2) OCI_DEFAULT,
- (ub1) OCI_DEFAULT, lobtype, TRUE, OCI_DURATION_SESSION, status);
+ else {
+ if (phs->desc_h && phs->desc_t == OCI_DTYPE_LOB)
+ ora_free_templob(sth, imp_sth, (OCILobLocator*)phs->desc_h);
+ if (!phs->desc_h) {
+ ++imp_sth->has_lobs;
+ phs->desc_t = OCI_DTYPE_LOB;
+ OCIDescriptorAlloc_ok(imp_sth->envhp,
+ &phs->desc_h, phs->desc_t);
+ }
+ OCIAttrSet_log_stat(phs->desc_h, phs->desc_t,
+ &lobEmpty, 0, OCI_ATTR_LOBEMPTY, imp_sth->errhp, status);
+ if (status != OCI_SUCCESS)
+ return oci_error(sth, imp_sth->errhp, status, "OCIAttrSet OCI_ATTR_LOBEMPTY");
+ if (!SvPOK(phs->sv)) { /* normalizations for special cases */
+ if (SvOK(phs->sv)) { /* ie a number, convert to string ASAP */
+ if (!(SvROK(phs->sv) && phs->is_inout))
+ sv_2pv(phs->sv, &PL_na);
+ }
+ else { /* ensure we're at least an SVt_PV (so SvPVX etc work) */
+ if(SvUPGRADE(phs->sv, SVt_PV)){} /* For GCC not to warn on unused result */
+ }
+ }
+ phs->indp = (SvOK(phs->sv)) ? 0 : -1;
+ phs->progv = (char*)&phs->desc_h;
+ phs->maxlen = sizeof(OCILobLocator*);
+ if (phs->is_inout)
+ phs->out_prepost_exec = lob_phs_post_execute;
+ /* accept input LOBs */
+ if (sv_isobject(phs->sv) && sv_derived_from(phs->sv, "OCILobLocatorPtr")) {
+
+ OCILobLocator *src;
+ OCILobLocator **dest;
+ src = INT2PTR(OCILobLocator *, SvIV(SvRV(phs->sv)));
+ dest = (OCILobLocator **) phs->progv;
+ OCILobLocatorAssign_log_stat(imp_dbh->svchp, imp_sth->errhp, src, dest, status);
if (status != OCI_SUCCESS) {
- oci_error(sth, imp_sth->errhp, status, "OCILobCreateTemporary");
+ oci_error(sth, imp_sth->errhp, status, "OCILobLocatorAssign");
return 0;
}
+ }
+ /* create temporary LOB for PL/SQL placeholder */
+ else if (imp_sth->stmt_type == OCI_STMT_BEGIN ||
+ imp_sth->stmt_type == OCI_STMT_DECLARE) {
+ ub4 amtp;
+ if(SvUPGRADE(phs->sv, SVt_PV)){/* For GCC not to warn on unused result */}; /* just in case */
+
+ amtp = SvCUR(phs->sv); /* XXX UTF8? */
+
+ /* Create a temp lob for non-empty string */
+
+ if (amtp > 0) {
+ ub1 lobtype = (phs->ftype == 112 ? OCI_TEMP_CLOB : OCI_TEMP_BLOB);
+ OCILobCreateTemporary_log_stat(imp_dbh->svchp, imp_sth->errhp,
+ (OCILobLocator *) phs->desc_h, (ub2) OCI_DEFAULT,
+ (ub1) OCI_DEFAULT, lobtype, TRUE, OCI_DURATION_SESSION, status);
+ if (status != OCI_SUCCESS) {
+ oci_error(sth, imp_sth->errhp, status, "OCILobCreateTemporary");
+ return 0;
+ }
- if( ! phs->csid ) {
- ub1 csform = SQLCS_IMPLICIT;
- ub2 csid = 0;
- OCILobCharSetForm_log_stat( imp_sth->envhp, imp_sth->errhp, (OCILobLocator*)phs->desc_h, &csform, status );
- if (status != OCI_SUCCESS)
- return oci_error(sth, imp_sth->errhp, status, "OCILobCharSetForm");
+ if( ! phs->csid ) {
+ ub1 csform = SQLCS_IMPLICIT;
+ ub2 csid = 0;
+ OCILobCharSetForm_log_stat( imp_sth->envhp, imp_sth->errhp, (OCILobLocator*)phs->desc_h, &csform, status );
+ if (status != OCI_SUCCESS)
+ return oci_error(sth, imp_sth->errhp, status, "OCILobCharSetForm");
#ifdef OCI_ATTR_CHARSET_ID
/* Effectively only used so AL32UTF8 works properly */
- OCILobCharSetId_log_stat( imp_sth->envhp, imp_sth->errhp, (OCILobLocator*)phs->desc_h, &csid, status );
- if (status != OCI_SUCCESS)
- return oci_error(sth, imp_sth->errhp, status, "OCILobCharSetId");
+ OCILobCharSetId_log_stat( imp_sth->envhp, imp_sth->errhp, (OCILobLocator*)phs->desc_h, &csid, status );
+ if (status != OCI_SUCCESS)
+ return oci_error(sth, imp_sth->errhp, status, "OCILobCharSetId");
#endif /* OCI_ATTR_CHARSET_ID */
/* if data is utf8 but charset isn't then switch to utf8 csid */
- csid = (SvUTF8(phs->sv) && !CS_IS_UTF8(csid)) ? utf8_csid : CSFORM_IMPLIED_CSID(csform);
- phs->csid = csid;
- phs->csform = csform;
- }
+ csid = (SvUTF8(phs->sv) && !CS_IS_UTF8(csid)) ? utf8_csid : CSFORM_IMPLIED_CSID(csform);
+ phs->csid = csid;
+ phs->csform = csform;
+ }
- if (DBIS->debug >= 3 || dbd_verbose >= 3 )
- PerlIO_printf(DBILOGFP, " calling OCILobWrite phs->csid=%d phs->csform=%d amtp=%d\n",
- phs->csid, phs->csform, amtp );
+ if (DBIS->debug >= 3 || dbd_verbose >= 3 )
+ PerlIO_printf(DBILOGFP, " calling OCILobWrite phs->csid=%d phs->csform=%d amtp=%d\n",
+ phs->csid, phs->csform, amtp );
/* write lob data */
- OCILobWrite_log_stat(imp_sth->svchp, imp_sth->errhp,
- (OCILobLocator*)phs->desc_h, &amtp, 1, SvPVX(phs->sv), amtp, OCI_ONE_PIECE,
- 0,0, phs->csid, phs->csform, status);
- if (status != OCI_SUCCESS) {
- return oci_error(sth, imp_sth->errhp, status, "OCILobWrite in dbd_rebind_ph_lob");
+ OCILobWrite_log_stat(imp_sth->svchp, imp_sth->errhp,
+ (OCILobLocator*)phs->desc_h, &amtp, 1, SvPVX(phs->sv), amtp, OCI_ONE_PIECE,
+ 0,0, phs->csid, phs->csform, status);
+ if (status != OCI_SUCCESS) {
+ return oci_error(sth, imp_sth->errhp, status, "OCILobWrite in dbd_rebind_ph_lob");
+ }
}
}
}
@@ -4146,358 +4153,17 @@
-struct lob_refetch_st {
- OCIStmt *stmthp;
- OCIBind *bindhp;
- OCIRowid *rowid;
- OCIParam *parmdp_tmp;
- OCIParam *parmdp_lob;
- int num_fields;
- SV *fbh_ary_sv;
- imp_fbh_t *fbh_ary;
-};
-
-
-static int
-init_lob_refetch(SV *sth, imp_sth_t *imp_sth)
-{
- dTHX;
- SV *sv;
- SV *sql_select;
- HV *lob_cols_hv = NULL;
- sword status;
- OCIError *errhp = imp_sth->errhp;
- OCIParam *parmhp = NULL, *collisthd = NULL, *colhd = NULL;
- ub2 numcols = 0;
- imp_fbh_t *fbh;
- int unmatched_params;
- I32 i,j;
- char *p;
- lob_refetch_t *lr = NULL;
- STRLEN tablename_len;
- char *tablename;
- char new_tablename[100];
- switch (imp_sth->stmt_type) {
- case OCI_STMT_UPDATE:
- tablename = find_ident_after(imp_sth->statement,
- "update", &tablename_len, 1);
- break;
- case OCI_STMT_INSERT:
- tablename = find_ident_after(imp_sth->statement,
- "into", &tablename_len, 1);
- break;
- default:
- return oci_error(sth, errhp, OCI_ERROR,
- "LOB refetch attempted for unsupported statement type (see also ora_auto_lob attribute)");
- }
-
- if (!tablename)
- return oci_error(sth, errhp, OCI_ERROR,
- "Unable to parse table name for LOB refetch");
-
- if (!imp_sth->dschp){
- OCIHandleAlloc_ok(imp_sth->envhp, &imp_sth->dschp, OCI_HTYPE_DESCRIBE, status);
- if (status != OCI_SUCCESS) {
- oci_error(sth,imp_sth->errhp, status, "OCIHandleAlloc");
- }
-
- }
-
- OCIDescribeAny_log_stat(imp_sth->svchp, errhp, tablename, strlen(tablename),
- (ub1)OCI_OTYPE_NAME, (ub1)1, (ub1)OCI_PTYPE_SYN, imp_sth->dschp, status);
-
- if (status == OCI_SUCCESS) { /* There is a synonym, get the schema */
- char *syn_schema=NULL;
- char syn_name[100];
- ub4 tn_len = 0, syn_schema_len = 0;
-
- strncpy(syn_name,tablename,strlen(tablename));
- /* Put the synonym name here for later user */
-
- OCIAttrGet_log_stat(imp_sth->dschp, OCI_HTYPE_DESCRIBE,
- &parmhp, 0, OCI_ATTR_PARAM, errhp, status);
-
- OCIAttrGet_log_stat(parmhp, OCI_DTYPE_PARAM,
- &syn_schema, &syn_schema_len, OCI_ATTR_SCHEMA_NAME, errhp, status);
-
-
- OCIAttrGet_log_stat(parmhp, OCI_DTYPE_PARAM,
- &tablename, &tn_len, OCI_ATTR_NAME, errhp, status);
-
- strncpy(new_tablename,syn_schema,syn_schema_len);
- new_tablename[syn_schema_len+1] = '\0';
- new_tablename[syn_schema_len]='.';
- strncat(new_tablename, tablename,tn_len);
-
- tablename=new_tablename;
-
- if (DBIS->debug >= 3 || dbd_verbose >= 3 )
- PerlIO_printf(DBILOGFP, " lob refetch using a synonym named=%s for %s \n", syn_name,tablename);
-
-
- }
- OCIDescribeAny_log_stat(imp_sth->svchp, errhp, tablename, strlen(tablename),
- (ub1)OCI_OTYPE_NAME, (ub1)1, (ub1)OCI_PTYPE_TABLE, imp_sth->dschp, status);
-
- if (status != OCI_SUCCESS) {
- /* XXX this OCI_PTYPE_TABLE->OCI_PTYPE_VIEW fallback should actually be */
- /* a loop that includes synonyms etc */
- OCIDescribeAny_log_stat(imp_sth->svchp, errhp, tablename, strlen(tablename),
- (ub1)OCI_OTYPE_NAME, (ub1)1, (ub1)OCI_PTYPE_VIEW, imp_sth->dschp, status);
- if (status != OCI_SUCCESS) {
- OCIHandleFree_log_stat(imp_sth->dschp, OCI_HTYPE_DESCRIBE, status);
- return oci_error(sth, errhp, status, "OCIDescribeAny(view)/LOB refetch");
- }
- }
-
- OCIAttrGet_log_stat(imp_sth->dschp, OCI_HTYPE_DESCRIBE,
- &parmhp, 0, OCI_ATTR_PARAM, errhp, status);
- if (!status ) {
- OCIAttrGet_log_stat(parmhp, OCI_DTYPE_PARAM,
- &numcols, 0, OCI_ATTR_NUM_COLS, errhp, status);
- }
-
- if (!status ) {
- OCIAttrGet_log_stat(parmhp, OCI_DTYPE_PARAM,
- &collisthd, 0, OCI_ATTR_LIST_COLUMNS, errhp, status);
- }
-
- if (status != OCI_SUCCESS) {
- OCIHandleFree_log_stat(imp_sth->dschp, OCI_HTYPE_DESCRIBE, status);
- return oci_error(sth, errhp, status, "OCIDescribeAny/OCIAttrGet/LOB refetch");
- }
-
- if (DBIS->debug >= 3 || dbd_verbose >= 3 )
- PerlIO_printf(DBILOGFP, " lob refetch from table %s, %d columns:\n", tablename, numcols);
-
- for (i = 1; i <= (long)numcols; i++) {
- ub2 col_dbtype;
- char *col_name;
- ub4 col_name_len;
- OCIParamGet_log_stat(collisthd, OCI_DTYPE_PARAM, errhp, (dvoid**)&colhd, i, status);
- if (status)
- break;
-
- OCIAttrGet_log_stat(colhd, OCI_DTYPE_PARAM, &col_dbtype, 0,
- OCI_ATTR_DATA_TYPE, errhp, status);
- if (status)
- break;
-
- OCIAttrGet_log_stat(colhd, OCI_DTYPE_PARAM, &col_name, &col_name_len,
- OCI_ATTR_NAME, errhp, status);
- if (status)
- break;
-
- if (DBIS->debug >= 3 || dbd_verbose >= 3 )
- PerlIO_printf(DBILOGFP, " lob refetch table col %d: '%.*s' otype %d\n",
- (int)i, (int)col_name_len,col_name, col_dbtype);
-
- if (col_dbtype != SQLT_CLOB && col_dbtype != SQLT_BLOB)
- continue;
-
- if (!lob_cols_hv)
- lob_cols_hv = newHV();
-
- sv = newSViv(col_dbtype);
- (void)sv_setpvn(sv, col_name, col_name_len);
-
- if (CSFORM_IMPLIES_UTF8(SQLCS_IMPLICIT))
- SvUTF8_on(sv);
-
- (void)SvIOK_on(sv); /* "what a wonderful hack!" */
- (void)hv_store(lob_cols_hv, col_name,col_name_len, sv,0);
- OCIDescriptorFree(colhd, OCI_DTYPE_PARAM);
- colhd = NULL;
- }
-
- if (colhd)
- OCIDescriptorFree(colhd, OCI_DTYPE_PARAM);
-
- if (status != OCI_SUCCESS) {
- oci_error(sth, errhp, status,
- "OCIDescribeAny/OCIParamGet/OCIAttrGet/LOB refetch");
- OCIHandleFree_log_stat(imp_sth->dschp, OCI_HTYPE_DESCRIBE, status);
- return 0;
- }
-
- if (!lob_cols_hv)
- return oci_error(sth, errhp, OCI_ERROR,
- "LOB refetch failed, no lobs in table");
-
- /* our bind params are in %imp_sth->all_params_hv
- our table cols are in %lob_cols_hv
- we now iterate through our bind params
- and allocate them to the appropriate table columns
- */
- Newz(1, lr, 1, lob_refetch_t);
- unmatched_params = 0;
- lr->num_fields = 0;
- lr->fbh_ary = (imp_fbh_t*)alloc_via_sv(sizeof(imp_fbh_t) * HvKEYS(lob_cols_hv)+1,
- &lr->fbh_ary_sv, 0);
-
- sql_select = sv_2mortal(newSVpv("select ",0));
-
- hv_iterinit(imp_sth->all_params_hv);
- while( (sv = hv_iternextsv(imp_sth->all_params_hv, &p, &i)) != NULL ) {
- int matched = 0;
- phs_t *phs = (phs_t*)(void*)SvPVX(sv);
-
- if (sv == &PL_sv_undef || !phs)
- croak("panic: unbound params");
-
- if (phs->ftype != SQLT_CLOB && phs->ftype != SQLT_BLOB)
- continue;
-
- hv_iterinit(lob_cols_hv);
-
- while( (sv = hv_iternextsv(lob_cols_hv, &p, &j)) != NULL ) {
- char sql_field[200];
- if (phs->ora_field) { /* must match this phs by field name */
- char *ora_field_name = SvPV(phs->ora_field,PL_na);
- if (SvCUR(phs->ora_field) != SvCUR(sv)
- || ibcmp(ora_field_name, SvPV(sv,PL_na), (I32)SvCUR(sv) ) )
- continue;
- }
- else { /* basic dumb match by type */
- if (phs->ftype != SvIV(sv)){
- continue;
- }
- else { /* got a type match - check it's safe */
- SV *sv_other;
- char *p_other;
- /* would any other lob field match this type? */
- while( (sv_other = hv_iternextsv(lob_cols_hv, &p_other, &i)) != NULL ) {
- if (phs->ftype != SvIV(sv_other))
- continue;
- if (DBIS->debug >= 3 || dbd_verbose >= 3 )
- PerlIO_printf(DBILOGFP,
- " both %s and %s have type %d - ambiguous\n",
- neatsvpv(sv,0), neatsvpv(sv_other,0), (int)SvIV(sv_other));
- Safefree(lr);
- sv_free((SV*)lob_cols_hv);
- return oci_error(sth, errhp, OCI_ERROR,
- "Need bind_param(..., { ora_field=>... }) attribute to identify table LOB field names");
- }
- }
- }
-
- matched = 1;
- sprintf(sql_field, "%s%s \"%s\"",
- (SvCUR(sql_select)>7)?", ":"", p, &phs->name[1]);
- sv_catpv(sql_select, sql_field);
- if (DBIS->debug >= 3 || dbd_verbose >= 3 )
- PerlIO_printf(DBILOGFP,
- " lob refetch %s param: otype %d, matched field '%s' %s(%s)\n",
- phs->name, phs->ftype, p,
- (phs->ora_field) ? "by name " : "by type ", sql_field);
- (void)hv_delete(lob_cols_hv, p, i, G_DISCARD);
- fbh = &lr->fbh_ary[lr->num_fields++];
- fbh->name = phs->name;
- fbh->ftype = phs->ftype;
- fbh->dbtype = phs->ftype;
- fbh->disize = 99;
- fbh->desc_t = OCI_DTYPE_LOB;
- OCIDescriptorAlloc_ok(imp_sth->envhp, &fbh->desc_h, fbh->desc_t);
- break; /* we're done with this placeholder now */
- }
- if (!matched) {
- ++unmatched_params;
- if (DBIS->debug >= 3 || dbd_verbose >= 3 )
- PerlIO_printf(DBILOGFP,
- " lob refetch %s param: otype %d, UNMATCHED\n",
- phs->name, phs->ftype);
- }
- }
- sv_free((SV*)lob_cols_hv);
-
- if (unmatched_params) {
- Safefree(lr);
- return oci_error(sth, errhp, OCI_ERROR,
- "Can't match some parameters to LOB fields in the table, check type and name");
- }
-
- sv_catpv(sql_select, " from ");
- sv_catpv(sql_select, tablename);
- sv_catpv(sql_select, " where rowid = :rid for update"); /* get row with lock */
- if (DBIS->debug >= 3 || dbd_verbose >= 3 )
- PerlIO_printf(DBILOGFP,
- " lob refetch sql: %s\n", SvPVX(sql_select));
- lr->stmthp = NULL;
- lr->bindhp = NULL;
- lr->rowid = NULL;
- lr->parmdp_tmp = NULL;
- lr->parmdp_lob = NULL;
- OCIHandleAlloc_ok(imp_sth->envhp, &lr->stmthp, OCI_HTYPE_STMT, status);
- OCIStmtPrepare_log_stat(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->envhp, &lr->rowid, OCI_DTYPE_ROWID);
- OCIBindByName_log_stat(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(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 (DBIS->debug >= 3 || dbd_verbose >= 3 )
- PerlIO_printf(DBILOGFP,
- " 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(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(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->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 */
-{
+post_execute_lobs(SV *sth, imp_sth_t *imp_sth, ub4 row_count){
- /* 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. */
+ /* Now only works for PSLQ statements */
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);
@@ -4530,122 +4196,10 @@
}
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->svchp, lr->stmthp, errhp,1, 0, NULL, NULL, OCI_DEFAULT, status); /* execute and fetch */
-
- if (status != OCI_SUCCESS)
- return oci_error(sth, errhp, status,
-
- ora_sql_error(imp_sth,"OCIStmtExecute/LOB refetch"));
-
- for(i=0; i < lr->num_fields; ++i) {
- imp_fbh_t *fbh = &lr->fbh_ary[i];
- int rc = fbh->fb_ary->arcode[0];
- phs_t *phs = (phs_t*)fbh->special;
- ub4 amtp;
-
- if(SvUPGRADE(phs->sv, SVt_PV)){/* For GCC not to warn on unused result */ }; /* just in case */
-
- amtp = SvCUR(phs->sv); /* XXX UTF8? */
- if (rc == 1405) { /* NULL - return undef */
- sv_set_undef(phs->sv);
- status = OCI_SUCCESS;
- }
- else if (amtp > 0) { /* since amtp==0 & OCI_ONE_PIECE fail (OCI 8.0.4) */
- if( ! fbh->csid ) {
- ub1 csform = SQLCS_IMPLICIT;
- ub2 csid = 0;
- OCILobCharSetForm_log_stat( imp_sth->envhp, errhp, (OCILobLocator*)fbh->desc_h, &csform, status );
- if (status != OCI_SUCCESS)
- return oci_error(sth, errhp, status, "OCILobCharSetForm");
-#ifdef OCI_ATTR_CHARSET_ID
- /* Effectively only used so AL32UTF8 works properly */
- OCILobCharSetId_log_stat( imp_sth->envhp, errhp, (OCILobLocator*)fbh->desc_h, &csid, status );
- if (status != OCI_SUCCESS)
- return oci_error(sth, errhp, status, "OCILobCharSetId");
-#endif /* OCI_ATTR_CHARSET_ID */
- /* if data is utf8 but charset isn't then switch to utf8 csid */
- csid = (SvUTF8(phs->sv) && !CS_IS_UTF8(csid)) ? utf8_csid : CSFORM_IMPLIED_CSID(csform);
- fbh->csid = csid;
- fbh->csform = csform;
- }
-
- if (DBIS->debug >= 3 || dbd_verbose >= 3 )
- PerlIO_printf(DBILOGFP, " calling OCILobWrite fbh->csid=%d fbh->csform=%d amtp=%d\n",
- fbh->csid, fbh->csform, amtp );
-
- OCILobWrite_log_stat(imp_sth->svchp, errhp,
- (OCILobLocator*)fbh->desc_h, &amtp, 1, SvPVX(phs->sv), amtp, OCI_ONE_PIECE,
- 0,0, fbh->csid ,fbh->csform, status);
-
- if (status != OCI_SUCCESS) {
- return oci_error(sth, errhp, status, "OCILobWrite in post_execute_lobs");
- }
-
- } else { /* amtp==0 so truncate LOB to zero length */
- OCILobTrim_log_stat(imp_sth->svchp, errhp, (OCILobLocator*)fbh->desc_h, 0, status);
-
- if (status != OCI_SUCCESS) {
- return oci_error(sth, errhp, status, "OCILobTrim in post_execute_lobs");
- }
-
- }
-
- if (DBIS->debug >= 3 || dbd_verbose >= 3 )
- PerlIO_printf(DBILOGFP,
- " lob refetch %d for '%s' param: ftype %d, len %ld: %s %s\n",
- i+1,fbh->name, fbh->dbtype, ul_t(amtp),
- (rc==1405 ? "NULL" : (amtp > 0) ? "LobWrite" : "LobTrim"), oci_status_name(status));
-
- if (status != OCI_SUCCESS) {
- return oci_error(sth, errhp, status, "OCILobTrim/OCILobWrite/LOB refetch");
- }
- }
-
- if (DBIc_has(imp_dbh,DBIcf_AutoCommit))
- dbd_db_commit(dbh, imp_dbh);
-
- return 1;
+ return 0;/*something is wrong here one should never get here afer 1.29_1*/
}
-void
-ora_free_lob_refetch(SV *sth, imp_sth_t *imp_sth)
-{
- dTHX;
- lob_refetch_t *lr = imp_sth->lob_refetch;
- int i;
- sword status;
- if (lr->rowid)
- OCIDescriptorFree(lr->rowid, OCI_DTYPE_ROWID);
- OCIHandleFree_log_stat(lr->stmthp, OCI_HTYPE_STMT, status);
-
- if (status != OCI_SUCCESS)
- oci_error(sth, imp_sth->errhp, status, "ora_free_lob_refetch/OCIHandleFree");
-
- for(i=0; i < lr->num_fields; ++i) {
- imp_fbh_t *fbh = &lr->fbh_ary[i];
- ora_free_fbh_contents(fbh);
- }
- sv_free(lr->fbh_ary_sv);
- Safefree(imp_sth->lob_refetch);
- imp_sth->lob_refetch = NULL;
-}
+
ub4
ora_db_version(SV *dbh, imp_dbh_t *imp_dbh)