title: DBD::mysql::st fetchrow_array failed: fetch() without execute error?
body: <p>I am getting this error when running this perl script</p>
  
  <p>DBD::mysql::st fetchrow_array failed: fetch() without execute at ai_light_warehouse.pl line 174
  DBD::mysql::st fetchrow_array failed: fetch() without execute at ai_light_warehouse.pl line 187</p>
  
  <p>I can't seem to figure out why this is happening, and I am not well versed in perl. trying to figure it out but hit a roadblock after a few hours and figured i'd reach out to stackoverflow. </p>
  
  <pre><code> # reset warehouse table
      my $reset_handle = $dbh-&gt;prepare(qq{
        DELETE FROM ai_light_warehouse
      });
  
  my $select_handle = $dbh-&gt;prepare(qq{
      SELECT DISTINCT PROD.PRODUCT_ID      AS PRODUCT_ID,
            PROD.PRODUCT_NAME            AS PRODUCT_NAME,
            PROD.BRAND_NAME              AS BRAND_NAME,
            PC.DESCRIPTION               AS COLLECTION,
            PFA.DESCRIPTION        AS PRODUCT_FEATURE_ID,
            PROD.DEFAULT_SEQUENCE_NUM    AS POPULARITY,
            PA.PRODUCT_ID                AS VIRTUAL_PRODUCT_ID,
            PROD.IS_VIRTUAL              AS IS_VIRTUAL,
            "N"                          AS ON_SALE,
            CASE 
              WHEN PROD.TOTAL_TIMES_VIEWED IS NULL THEN 0
              ELSE PROD.TOTAL_TIMES_VIEWED
            END   AS TOTAL_TIMES_VIEWED,
            CASE 
              WHEN PROD.IS_CLEARANCE IS NULL THEN "N"
              ELSE PROD.IS_CLEARANCE
            END   AS IS_CLEARANCE,
            PROD.internal_Name
    FROM    PRODUCT PROD
    INNER JOIN Ai_Light_category AS PC
    ON      (PROD.PRODUCT_ID = PC.PRODUCT_ID)
    LEFT OUTER JOIN PRODUCT_ASSOC PA
    ON      PROD.PRODUCT_ID = PA.PRODUCT_ID_TO
    INNER JOIN AI_LIGHT_FEATURES PFA
    ON      PA.PRODUCT_ID_TO = PFA.PRODUCT_ID
    WHERE (PA.PRODUCT_ASSOC_TYPE_ID    = "PRODUCT_VARIANT"
        AND PFA.PRODUCT_FEATURE_TYPE_ID = "COLOR"
        AND PROD.PRODUCT_TYPE_ID IN ("LIGHTING")
        AND (PROD.IS_LIVE = "Y"
        OR PROD.IS_LIVE IS NULL)
        AND ((PROD.SALES_DISCONTINUATION_DATE &gt; NOW()
         OR PROD.SALES_DISCONTINUATION_DATE IS NULL)))
    GROUP BY PA.PRODUCT_ID,
            PFA.PRODUCT_FEATURE_ID
    ORDER BY PROD.DEFAULT_SEQUENCE_NUM DESC,
            UPPER(PROD.PRODUCT_NAME) ASC
  });
  # retrieve basic product information
  my $insert_handle = $dbh-&gt;prepare(qq{
    INSERT INTO ai_light_warehouse
            (
                    PRODUCT_ID,
                    PRODUCT_NAME,
                    BRAND_NAME,
                    COLLECTION,
                    PRODUCT_FEATURE_ID,
                    MIN_PRICE,
                    MAX_PRICE,
                    POPULARITY,
                    VIRTUAL_PRODUCT_ID,
                    IS_VIRTUAL,
                    TOTAL_TIMES_VIEWED,
                    IS_CLEARANCE,
                    INTERNAL_NAME,
                    ON_SALE,
                    SELECTOR
            )
            VALUES
            (
                    ?,
                    ?,
                    ?,
                    ?,
                    ?,
                    ?,
                    ?,
                    ?,
                    ?,
                    ?,
                    ?,
                    ?,
                    ?,
                    ?,
                    ?
            )
  
  });
  
  # save default and list prices
  my $price_handle = $dbh-&gt;prepare(qq{
   UPDATE AI_LIGHT_WAREHOUSE W,
          PRODUCT_PRICE PP1,
          PRODUCT_PRICE PP2
   SET    W.PRICE = PP1.PRICE,
          W.LIST_PRICE    = PP2.PRICE
   WHERE  W.PRODUCT_ID    = PP1.PRODUCT_ID
      AND W.PRODUCT_ID    = PP2.PRODUCT_ID
      AND PP1.PRODUCT_PRICE_TYPE_ID = "DEFAULT_PRICE"
      AND PP2.PRODUCT_PRICE_TYPE_ID = "LIST_PRICE"
  });
  
  my $selectWatt = $dbh-&gt;prepare(qq{
      SELECT PF.PRODUCT_FEATURE_ID, PF.DESCRIPTION FROM AI_LIGHT_FEATURES PF WHERE PF.PRODUCT_FEATURE_TYPE_ID = "WATT_CAT" AND PF.PRODUCT_ID = ? limit 1
  });
  
  my $watt_handle = $dbh-&gt;prepare(qq{
      UPDATE AI_LIGHT_WAREHOUSE SET WATT_CAT = ?, WATT_CAT_DESCRIPTION = ? WHERE PRODUCT_ID = ?
  });
  
  my $selectHEIGHT = $dbh-&gt;prepare(qq{
      SELECT PF.PRODUCT_FEATURE_ID, PF.DESCRIPTION FROM AI_LIGHT_FEATURES PF WHERE PF.PRODUCT_FEATURE_TYPE_ID = "HEIGHT_CAT" AND PF.PRODUCT_ID = ? limit 1
  });
  
  my $HEIGHT_handle = $dbh-&gt;prepare(qq{
      UPDATE AI_LIGHT_WAREHOUSE SET HEIGHT_CAT = ?, HEIGHT_CAT_DESCRIPTION = ? WHERE PRODUCT_ID = ?
  });
  
  
  my $selectType = $dbh-&gt;prepare(qq{
      SELECT PF.PRODUCT_FEATURE_ID, PF.DESCRIPTION FROM AI_LIGHT_FEATURES PF WHERE PF.PRODUCT_FEATURE_TYPE_ID = "TYPE" AND PF.PRODUCT_ID = ? LIMIT 1
  });
  
  my $type_handle = $dbh-&gt;prepare(qq{
      UPDATE AI_LIGHT_WAREHOUSE SET TYPE_CAT = ?, TYPE_CAT_DESCRIPTION = ? WHERE PRODUCT_ID = ?
  });
  
  my $selectMat = $dbh-&gt;prepare(qq{
      SELECT PF.PRODUCT_FEATURE_ID, PF.DESCRIPTION FROM AI_LIGHT_FEATURES PF WHERE PF.PRODUCT_FEATURE_TYPE_ID = "MATERIAL_CAT" AND PF.PRODUCT_ID = ? LIMIT 1
  });
  
  my $mat_handle = $dbh-&gt;prepare(qq{
      UPDATE AI_LIGHT_WAREHOUSE SET MAT_CAT = ?, MAT_CAT_DESCRIPTION = ? WHERE PRODUCT_ID = ?
  });
  
  my $select_Price = $dbh-&gt;prepare(qq{
      SELECT PRICE FROM PRODUCT_PRICE WHERE PRODUCT_ID = ? AND PRODUCT_PRICE_TYPE_ID = "DEFAULT_PRICE"
  });
  
  my $variants_handle = $dbh-&gt;prepare(qq{
      SELECT PA.PRODUCT_ID_TO FROM PRODUCT_ASSOC PA INNER JOIN PRODUCT PROD ON PROD.PRODUCT_ID = PA.PRODUCT_ID_TO WHERE PA.PRODUCT_ID = ? AND (PROD.SALES_DISCONTINUATION_DATE IS NULL OR PROD.SALES_DISCONTINUATION_DATE &gt; NOW())
  });
  
  my $rating_handle = $dbh-&gt;prepare(qq{
          SELECT PRODUCT_RATING FROM PRODUCT WHERE PRODUCT_ID = ?
      }); 
  
  die "Couldn't prepare queries; aborting"
    unless defined $reset_handle
      &amp;&amp; defined $insert_handle
      &amp;&amp; defined $price_handle;
  
  #------------------------------------------------------------
  my %virtualMinPriceMap = ();
  my %virtualMaxPriceMap = ();
  
  my $success = 1;
  $success &amp;&amp;= $reset_handle-&gt;execute();
  $success &amp;&amp;= $select_handle-&gt;execute();
  
  
  while (my($PRODUCT_ID, $PRODUCT_NAME, $BRAND_NAME, $COLLECTION, $PRODUCT_FEATURE_ID, $POPULARITY, $VIRTUAL_PRODUCT_ID, $IS_VIRTUAL, $ON_SALE, $TOTAL_TIMES_VIEWED, $IS_CLEARANCE, $internalName) = $select_handle-&gt;fetchrow_array())
  {
      $success &amp;&amp;= $rating_handle-&gt;execute($VIRTUAL_PRODUCT_ID);
      my $rating = $rating_handle-&gt;fetchrow_array();
      $PRODUCT_FEATURE_ID =~ s/^\s+//;
      $PRODUCT_FEATURE_ID =~ s/\s+$//;
      $PRODUCT_FEATURE_ID =~ s/ /-/g;
      $PRODUCT_FEATURE_ID =~ s/--/-/g;
      $PRODUCT_FEATURE_ID =~ s/[^0-9a-zA-Z_-]//g;
      $PRODUCT_FEATURE_ID =~ tr/A-Z/a-z/;
      my $selector = $VIRTUAL_PRODUCT_ID . $PRODUCT_FEATURE_ID;
      my $MAX_PRICE = -1;
      my $MIN_PRICE = -1;
      if (!exists($virtualMinPriceMap{$VIRTUAL_PRODUCT_ID}))
      {
          $success &amp;&amp;= $variants_handle-&gt;execute($VIRTUAL_PRODUCT_ID);
          while (my($variantId) = $variants_handle-&gt;fetchrow_array())
          {
              $success &amp;&amp;= $select_Price-&gt;execute($variantId);
              while (my($priceValue) = $select_Price-&gt;fetchrow_array())
              {
                  if($MIN_PRICE == -1 || $MIN_PRICE &gt; $priceValue)
                  {
                      $MIN_PRICE = $priceValue;
                  }
                  if($MAX_PRICE &lt; $priceValue)
                  {
                      $MAX_PRICE = $priceValue;
                  }
              }
          }
          $virtualMaxPriceMap{$VIRTUAL_PRODUCT_ID} = $MAX_PRICE;
          $virtualMinPriceMap{$VIRTUAL_PRODUCT_ID} = $MIN_PRICE;
      }
      else
      {
          $MAX_PRICE = $virtualMaxPriceMap{$VIRTUAL_PRODUCT_ID};
          $MIN_PRICE = $virtualMinPriceMap{$VIRTUAL_PRODUCT_ID};
      }
      $success &amp;&amp;= $insert_handle-&gt;execute($PRODUCT_ID, $PRODUCT_NAME, $BRAND_NAME, $COLLECTION, $PRODUCT_FEATURE_ID, $MIN_PRICE, $MAX_PRICE, $POPULARITY, $VIRTUAL_PRODUCT_ID, $IS_VIRTUAL, $TOTAL_TIMES_VIEWED, $IS_CLEARANCE, $internalName, $ON_SALE, $selector);
  
      $selectWatt-&gt;execute($PRODUCT_ID);
      my ($watt_ID, $watt_description) = $selectWatt-&gt;fetchrow_array();
      if(defined ($watt_ID))
      {
          $watt_handle-&gt;execute($watt_ID, $watt_description, $PRODUCT_ID);
      }
  
      $selectHEIGHT-&gt;execute($PRODUCT_ID);
      my ($HEIGHT_ID, $height_description) = $selectHEIGHT-&gt;fetchrow_array();
      if(defined ($HEIGHT_ID))
      {
          $HEIGHT_handle-&gt;execute($HEIGHT_ID, $height_description, $PRODUCT_ID);
      }
  
      $selectType-&gt;execute($PRODUCT_ID);
      my ($type_ID, $type_description) = $selectType-&gt;fetchrow_array();
      if(defined ($type_ID))
      {
          $type_handle-&gt;execute($type_ID, $type_description, $PRODUCT_ID);
      }
  
      $selectMat-&gt;execute($PRODUCT_ID);
      my ($Mat_ID, $Mat_description) = $selectMat-&gt;fetchrow_array();
      if(defined ($Mat_ID))
      {
          $mat_handle-&gt;execute($Mat_ID, $Mat_description, $PRODUCT_ID);
      }
  }
  
  $success &amp;&amp;= $price_handle-&gt;execute();
  $selectWatt-&gt;finish();
  $selectHEIGHT-&gt;finish();
  $rating_handle-&gt;finish();
  $selectMat-&gt;finish();
  $selectType-&gt;finish();
  
  my $result = ($success ? $dbh-&gt;commit : $dbh-&gt;rollback);
  
  unless($result) {
    die "Couldn't finish transaction: " . $dbh-&gt;errstr;
  }
  
  $dbh-&gt;disconnect();
  
  my $end_run = time();
  my $run_time = $end_run - $start_run;
  $run_time = $run_time/60;
  print "Job took $run_time minut
  </code></pre>
  
  <p>es\n";</p>