Page 1 of 1

List index out of bounds

Posted: Fri 24 Jan 2014 09:29
by a.alekizoglou
I upgraded to UniDAC 5.2.5 from the previous version. For some UniQueries on the when activating I get a 'List index out of bounds' error. Then error comes from procedure TUniSQL.WriteParams(WriteValue: boolean = True) when parsing parameters. Specifically I found a situation where FParamRefs FCount=1, FCapacity=4 and FICommand.GetParamCount = 4.

Code: Select all

...

    UseParamRefs := FParamRefs.Count > 0;
    for i := 0 to FICommand.GetParamCount - 1 do begin
      ParamDesc := FICommand.GetParam(i);
      if UseParamRefs then
        Param := TDAParam(FParamRefs[i])
      else begin
        Param := FindParam(ParamDesc.GetName);
        FParamRefs.Add(Param);
      end;

...

Re: List index out of bounds

Posted: Fri 24 Jan 2014 09:46
by a.alekizoglou
I am not sure if this change is correct

Code: Select all

//QUALISYS
        if i < FParamRefs.Count  then
           Param := TDAParam(FParamRefs[i])
        else
           Param := nil;

Re: List index out of bounds

Posted: Fri 24 Jan 2014 11:26
by AlexP
Hello,

Please provide the text of the query, which opening causes the error.

Re: List index out of bounds

Posted: Fri 24 Jan 2014 11:36
by a.alekizoglou

Code: Select all

SELECT
   	products.*,
        currencies.iExchangeRate AS iExchangeRate,
    (SELECT group_concat(productalternatives.strProductAlternativeID separator ', ')  
     FROM productalternatives
     WHERE productalternatives.strProductID = products.strProductID) AS strProductAlternativeID,

  &NEWROUND(IF(products.iProductTypeID = 702,
     IFNULL((SELECT SUM(productbundles.iRetailPrice) as iRetailPackagePrice
             FROM productbundles
             WHERE productbundles.strProductID = products.strProductID
             GROUP BY
             productbundles.strProductID),0)
            ,IF(products.bRetailSpecialPrice AND CURDATE() BETWEEN products.dRetailSpecialPriceFrom AND products.dRetailSpecialPriceTo, products.iRetailSpecialPrice, products.iRetailPrice) ), :CurrencyDecimal) AS iRetailPriceEuro,

  &NEWROUND(IF(products.iProductTypeID = 702,
     IFNULL((SELECT SUM(productbundles.iBundlePackage * mproducts.iBuyPrice * currencies.iExchangeRate) as iBuyPriceEuro
             FROM productbundles
             LEFT OUTER JOIN products as mproducts on (productbundles.strProductBundleID = mproducts.strProductID)
             LEFT OUTER JOIN currencies ON (mproducts.iCurrencyID = currencies.iCurrencyID)
             WHERE productbundles.strProductID = products.strProductID
             GROUP BY
             productbundles.strProductID),0)
            ,products.iBuyPrice * currencies.iExchangeRate), :CurrencyDecimal) AS iBuyPriceEuro,

  &NEWROUND(IF(products.iProductTypeID = 702,
     IFNULL((SELECT SUM(productbundles.iBundlePackage * mproducts.iBuyPrice) as iBuyPriceEuro
             FROM productbundles
             LEFT OUTER JOIN products as mproducts on (productbundles.strProductBundleID = mproducts.strProductID)
             LEFT OUTER JOIN currencies ON (mproducts.iCurrencyID = currencies.iCurrencyID)
             WHERE productbundles.strProductID = products.strProductID
             GROUP BY
             productbundles.strProductID),0)
            ,products.iBuyPrice), :CurrencyDecimal) AS iBaseCurrencyBuyPrice

FROM
  products
  LEFT OUTER JOIN currencies ON (products.iCurrencyID = currencies.iCurrencyID)
  LEFT OUTER JOIN vatcategories ON (products.iVATCategoryID = vatcategories.iVATCategoryID)
WHERE 
 products.bActive IS TRUE 
ORDER BY 
  products.iSortOrder,
  products.strProductName

Re: List index out of bounds

Posted: Fri 24 Jan 2014 12:36
by a.alekizoglou
AlexZ,

I changed that to and it worked. This also solved other problems I had with like http://forums.devart.com/viewtopic.php?f=28&t=28790 and floating point error in embedded MySQL. Can you check that

Code: Select all

        if i < FParamRefs.Count  then
           Param := TDAParam(FParamRefs[i])
        else
        begin
          Param := FindParam(ParamDesc.GetName);
          FParamRefs.Add(Param);
        end;

Re: List index out of bounds

Posted: Fri 24 Jan 2014 12:52
by AlexP
We have reproduced the problems, and will try to fix them as soon as possible