DBD-Solid

 view release on metacpan or  search on metacpan

dbdimp.c  view on Meta::CPAN

   solid_error( sth, rc, "st_execute/SQLExecute" );
   if( rc != SQL_SUCCESS )
      { return -1; }

   imp_sth->RowCount = -1;
   rc = SQLRowCount( imp_sth->hstmt, &imp_sth->RowCount );
   solid_error( sth, rc, "st_execute/SQLRowCount" );
   if( rc != SQL_SUCCESS )
      { return -1; }

   if( imp_sth->n_result_cols > 0 )
      {
      /* @@@ assume only SELECT returns columns */
      DBIc_ACTIVE_on(imp_sth);
      }
   imp_sth->eod = SQL_SUCCESS;

   return 1;
   }

/* --------------------------------------------------------
* Decide whether solid_error should set error for DBI
* SQL_NO_DATA_FOUND is never an error.
* SUCCESS_WITH_INFO errors depend on some other conditions.
* --------------------------------------------------------- */
static int S_IsFetchError( SV* sth, RETCODE rc, char* sqlstate,
                           const void* par)
   {
   D_imp_sth( sth );
   dTHR;

   if( rc == SQL_SUCCESS_WITH_INFO )
      {
      /* data truncated */
      /* Check this error code -- ODBC may change at any time!  --mms */
      /* Checked.  01004 is still data truncation in Solid 3.5 --mms */
      /* if (strEQ(sqlstate, "01004"))  */
      
      if( strEQ(sqlstate, S_SQL_ST_DATA_TRUNC) )
         {      
         /* without par: error when LongTruncOk is false */
         if( par == NULL )
            return DBIc_is( imp_sth, DBIcf_LongTruncOk ) == 0;
         
         /* with par: is always OK, *par gets SQL_SUCCESS */
         *(RETCODE*)par = SQL_SUCCESS;

         return 0;
         }
	   }
   else if( rc == SQL_NO_DATA_FOUND )
      { return 0; }

   return 1;
   }

/*----------------------------------------
* running $sth->fetchrow()
*
* Note:
* There is a commented hack here used to allow for unicode chars to 
* be rendered properly.  If you use Solid 3.52, leave everything alone.
* If you use 3.51, uncomment the hack and re-build dbd-solid.
*
* Explanation of the hack:
* All unicode formats (UTF-8, -16, and -32) require at most 
* four bytes per char.  Since the Solid 3.51 libs (spec. SQLColAttribute)
* returned number of bytes (and not number of chars), then we 
* had to divide the data length by four when we wanted the length of
* any of the three unicode types WCHAR, WVARCHAR, and WLONGVARCHAR.
* As of Solid 3.52, this is no longer necessary, but I'm leaving it
* here, in case things change (again?!).  --mms
*---------------------------------------- */
AV* dbd_st_fetch( SV* sth )
   {
   D_imp_sth( sth );
   int debug = dbis->debug;
   int i;
   AV* av;
   RETCODE rc;
   dTHR;
   int num_fields;
   char cvbuf[512];
   char* p;
   int LongTruncOk = DBIc_is( imp_sth, DBIcf_LongTruncOk );
   int warn_flag = DBIc_is( imp_sth, DBIcf_WARN );
   const char* sqlstate = NULL;

   /* Check that execute() was executed sucessfully. This also implies
   * that dbd_describe() executed sucessfuly so the memory buffers
   * are allocated and bound. */
   if( !DBIc_ACTIVE(imp_sth) )
      {
      solid_error(sth, 0, "no statement executing");
      return Nullav;
      }
    
   rc = SQLFetch( imp_sth->hstmt );
   if( dbis->debug >= 2 )
      fprintf(DBILOGFP, "SQLFetch() returns %d\n", rc);

   switch( rc )
      {
      case SQL_SUCCESS:
         imp_sth->eod = rc;
      break;
      
      case SQL_SUCCESS_WITH_INFO:
         sqlstate = solid_error5(sth, rc, "st_fetch/SQLFetch", S_IsFetchError, NULL);
         imp_sth->eod = SQL_SUCCESS;
      break;
      
      case SQL_NO_DATA_FOUND:
         imp_sth->eod = rc;
         sqlstate = solid_error5(sth, rc, "st_fetch/SQLFetch", S_IsFetchError, NULL);
         return Nullav;

      default:
         solid_error(sth, rc, "st_fetch/SQLFetch");
         return Nullav;
      }

   if( imp_sth->RowCount == -1 )
      imp_sth->RowCount = 0;

   imp_sth->RowCount++;

   av = DBIS->get_fbav( imp_sth );
   num_fields = AvFILL(av)+1;	/* ??? */



( run in 2.036 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )