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.
name ‘date_login’ not defined....
-
JonB:
Thanks for your prompt answer. I am a very very beginner coding in any language (Python inclusive). So, my problem is in the following lines:> def button2_tapped(sender): > c.execute("INSERT INTO logindata VALUES(?,?,?)", (date_login, user_name, pwd_user)) > conn.commit() > conn.close`````` There is where the code crash. Thanks again.
-
@sendog3c The code crashs for "name date_login is not defined".
And obviously, you have not defined the variables to be written in your db.
Then do this to get data you entereddate_login = '20190101' # or what you want user_name = sender.superview['t1'].text pwd_user = sender.superview['t2'].text
and this to give a name to the TextFields where you enter data
t1=ui.TextField(frame=(50,100,300,40),name='t1') t2=ui.TextField(frame=(50,200,300,40),name='t2')
-
@JonB said:
Also, note in one case you are trying to execute with variable names, but in the other case you use literals.
That is normal:
In the create statement, the variables names are littéral
In the insert statement, the variables names are variables -
Thank you both.
Where can I manipulate sqlite3. I mean, Browse data, delete columns, etc.
Regards;
-
@sendog3c said:
Where can I manipulate sqlite3
Do you want to say "where can I find how to..."?
If this is the question, there are a lot of docs, like this oneExample (be careful, your conn.close needs parentheses)
def button2_tapped(sender): date_login = '20190101' # or what you want user_name = sender.superview['t1'].text pwd_user = sender.superview['t2'].text c.execute("INSERT INTO logindata VALUES(?,?,?)", (date_login, user_name, pwd_user)) conn.commit() c.execute("SELECT * FROM logindata") rows = c.fetchall() print(rows) conn.close()
-
Yes I know there a lot docs here, but I mean if there is by example: a console to work with my DB alone or if there is way to use command line with specific sqilte3's instructions. supposing "sqlte3 /?".
Thanks.
-
@sendog3c you could write a little script like
import console import sqlite3 conn = sqlite3.connect("logindata.db", check_same_thread=False) c = conn.cursor() #c.execute("CREATE TABLE IF NOT EXISTS logindata (date_login, user_name, pwd_user)") while True: r = input() if r == 'close': break #PRAGMA table_info(logindata) #SELECT * FROM logindata c.execute(r) rows = c.fetchall() print(rows) c.close()
It will ask you a sql command, execute it, fetch the results and print them
Try with
PRAGMA table_info(logindata)
Or
SELECT * FROM logindataOf course, this is only valid for commands which can be followed by a fetch.
Up to you to modify the code to make it more generalized -
Thanks again
-
I bought the SQLed app for quick checking things. The downside is you have to "share..." the sqlite db between the apps.
Btw. in the PythonCheatSheet is a sqlite section.
-
Thank you Brumm. I a going to check it.
-
I haven't tried it, but there is https://forum.omz-software.com/topic/2326/sqlite3-browser