Sqlite from actions

Hello,

I need to read data from a sqlite database from inside the actiony.py file and return it as a message. Unfortunately, I always get an error message, saying the databse cannot be accessed. The sqlite database file is inside my actions/ folder.

Are there any recommendations on how to solve this?

Seems the path is wrong? Can you share a minimal example of your code?

Of course I can :slight_smile:

barcode = tracker.get_slot("barcode")

        try:
            BASE_DIR = os.path.dirname(os.path.abspath(__file__))
            db_path = os.path.join(BASE_DIR, "database.sqlite")
            sqliteConnection = sqlite3.connect(db_path)
            cursor = sqliteConnection.cursor()

            # Sqlite query ausfuehren
            query = "SELECT product_name FROM selections WHERE code={bc}".format(
                bc=barcode
            )
            cursor.execute(query)
            records = cursor.fetchall()

            print(records)
         ...

I tried sqlite3.connect( "database.sqlite") as well with the same result. My code always enters the catch block. The error message is no such table but the table does definitely exist.

Thanks for your help!

Hi @andileni, Here is how I performed a simple query in MySQL. Try this format. Be sure to put the DB connection code outside of the try-catch. Only the query operations should be in try-catch. I’m not sure if this will work for sqlite but do try it.

Here “varunsapre” is the username of the DB, “password” is the password for the user and “rasadb” is the database name.

import MySQLdb

Can you share the stack trace? And also the logs from your database?

Also, the title of this topic says sqlite and you’re using mysql?

@Tobias_Wochinger I am using sqite, verunsapre10 gave an example how he is doing it with mysql :slight_smile:

The problem is solved now. Unfortunately I cannot give a recommandation on what was wrong, because we don’t know either :frowning:

Probably a problem with a permission or a stopped and cached docker container.

Hi Tobias, i’m trying to run rasax on wsl(ubuntu).! i’m not getting chatbot prompt even project gets loaded .! i can see that sqllite3 is trying to insert and getting failed.! i don’t need any database for my project.! how can i disable this action.! and just run demo project on browser . please help.!

@suryakiran The sqlite database is essential for the functionality of Rasa X. On what error is it failing? I recommend creating a new forum thread as this is quite old.

Hi Tobias, issue got resolved after switching from wsl to wsl2 ! There is an issue with wsl sqllite. Thanks for your response

put your db file on the folder of your project, not inside of any subfolder