Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
help loading data (sqlite) into tableview
-
Yes I do. The app has binder Icon? If it is positive, I can see the DBA file I have created in SQLED. That is what are you referring?
-
@sendog3c Yes, to be sure you could open the file in Pythonista as a path.
-
Yes I have opened it and I am seeing the icon and the name of the SQLite file. Named “voluntariado”.
-
@sendog3c just to be sure that I understand, how did you open it? Via open external files?
-
How do I do to obtains the file path? Thanks
-
@cvp correct, via external file
-
@sendog3c do you know how to get the file path for use in my script?
-
-
@sendog3c just to be sure you get the correct path of your .db file when it is defined as an external file,
- create this little script as a Pythonista tool
import editor def main(): print(editor.get_path()) if __name__ == '__main__': main()
- édit your .db file in a Pythonista tab and execute the tool
-
Ready:
/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/Voluntariado/voluntariado.sqlite
-
I copied the path and run the script. It is working. But is repeating the records. My table only have 3 records.
-
@sendog3c sorry error of indentation (script also updated in first post)
lst = [] for table in tables: table_name = table[0] print(table_name) cursor.execute("PRAGMA table_info("+table_name+")") columns = cursor.fetchall() # ex: [(index, 'name', '', 0, None, 0),...] t = '' for column in columns: column_name = column[1] print(column_name) t = t + column_name + ',' #cursor.execute("SELECT "+t[:-1]+" FROM " + table_name) cursor.execute("SELECT * FROM " + table_name) rows = cursor.fetchall() t = table_name + ':' + t + ' [' + str(len(rows)) + ' rows]' for row in rows: lst.append(row) # (field,field,...)
-
Thank you very much. Now I am going to see how your code fit into the tableview methods
-