# Failed to retrevie rows from SQL in Action

**URL:** <https://forum.rasa.com/t/failed-to-retrevie-rows-from-sql-in-action/46186>\
**Category:** Rasa Open Source\
**Created:** [July 26, 2021, 8:59pm UTC](https://forum.rasa.com/t/failed-to-retrevie-rows-from-sql-in-action/46186 "2021-07-26T20:59:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BELIEVEIT](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/believeit/32/15170_2.png) [@BELIEVEIT](https://forum.rasa.com/u/BELIEVEIT)\
**Post date:** [July 26, 2021, 8:59pm UTC](https://forum.rasa.com/t/failed-to-retrevie-rows-from-sql-in-action/46186/1 "2021-07-26T20:59:52Z")

</div>

Hi guys , i faced some challenge to retreive product from database using my sqlite

i’m not sure why in actions i am unable to retreive a row for specific product\_name when my enitity value was extracted for e.g pants and shoes but it works for others(e.g basketball and shirt) to return price. I had tested to query using WHERE alias product\_name = “shoes” , it is working fine i had a entity called product with value should be obtain based on the lookup table during training. Can anyone help me to out of this ? Thanks

```
nlu:
- intent: check_product_price

  examples: |

    - how much does the [shirt](product) cost 

    - what is the price for [shoes](product)

    - price for [pants]

    - [basketball](product) cost how much

    - the cost for [shirt](product) cost

- lookup: product

  examples: |

    - shirt

    - shoes

    - pants

    - basketball

```

action.py

class Action\_Find\_Product\_Price(Action):

```
def name(self) -> Text:
    return "action_find_product_price"

def run(self, dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

    # connect to DB
    connection = sqlite3.connect("retailDB.db")
    cursor = connection.cursor()

    # get slots and save as tuple
    product_t = tracker.get_slot("product")

    product = [(product_t)]

    # place cursor on correct row based on search criteria
    cursor.execute("SELECT * FROM product WHERE product_name=? ", product)
    
    # retrieve sqlite row
    data_row = cursor.fetchone()

    # retreive from cursor save as variable 
    
    if data_row:
        product_name_r = data_row[0]
        product_price_r = data_row[1]
        # provide in stock message
        dispatcher.utter_message(template="utter_product_price", product_name=product_name_r ,product_price=product_price_r)
        connection.commit()
        connection.close()
        slots_to_reset = ["product"]
        return [SlotSet(slot, None) for slot in slots_to_reset]
        
    else:
        # provide out of stock message
        dispatcher.utter_message(template="utter_no_stock")
        connection.commit()
        connection.close()
        slots_to_reset = ["product"]
        # reset slot
        return [SlotSet(slot, None) for slot in slots_to_reset]

```

stories.yml

```
   - story: check product price
  steps:
  - intent: check_product_price
  - action: action_find_product_price

```

database

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/e/1/e1b324c8b7db46d05049c3e3e6cd9f9ebb8003b1.png)

result :

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/5/0/50cc1b841f754cb3dc4dfe6827dcd94d2448f43b.png)

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [July 26, 2021, 9:05pm UTC](https://forum.rasa.com/t/failed-to-retrevie-rows-from-sql-in-action/46186/2 "2021-07-26T21:05:38Z")

</div>

> [@BELIEVEIT](#):
>
> `product_price=product_price_r`

@BELIEVEIT

` - price for [pants](product)`

give some more example for others

`product_price=product_price_r`

Should be

```
product_price_range=product_price_r

```

try

But you getting the the price of shirt 🧐

@BELIEVEITTry delete the old model and train again please.

---

<div class="post-metadata">

**Author:** ![BELIEVEIT](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/believeit/32/15170_2.png) [@BELIEVEIT](https://forum.rasa.com/u/BELIEVEIT)\
**Post date:** [July 27, 2021, 8:40am UTC](https://forum.rasa.com/t/failed-to-retrevie-rows-from-sql-in-action/46186/3 "2021-07-27T08:40:15Z")

</div>

Thanks , i managed to solve to problem by giving more training example
