How can you use SQL queries on pydroid app?

Answers 1
  • # This code demonstrates a SQLite connection on Android.
    # You can use it in the Code Playground or another app like Pydroid3.
    import sqlite3
    conn = sqlite3.connect('pythonexample.db')
    # If running in Pydroid, the above will save to the Pydroid directory on your device
    # You could also specify a folder on your device if you have permission to save there. For example:
    # conn = sqlite3.connect('/storage/emulated/0/Download/pythonexample.db')
    # Change the above to whatever your download folder is on your device. You'll usually have permission to write there on Android.
    c = conn.cursor()
    # Create a table
    c.execute('''CREATE TABLE trainingclass
                 (sitename text, classname text, classrating text, userscore real)''')
    # Insert a row of sample data
    c.execute("INSERT INTO trainingclass VALUES ('Sololearn','Python','5 Stars',70.12)")
    # Save the changes
    t = ('Python',)
    c.execute('SELECT * FROM trainingclass WHERE classname=?', t)
    # Close the connection
    # After running this code, I was able to open the database from a SQLite client on Android.
    After creating the database in Python, I was able to open it and view the data in a SQLite client on Android.
  • Back to code snippet queries related python