omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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....

    Pythonista
    name not define
    4
    13
    4688
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • sendog3c
      sendog3c last edited by

      Hello there:

      Having problems defining names when:

      c.execute('''CREATE TABLE IF NOT EXISTS logindata (date_login, user_name, pwd_user)''')

      Thank you.

      import ui
      import sqlite3
      import console
      
      equis = 0
      yee = 0
      ancho = 800
      alto = 800
      bgcolor = 'white'
      bordercolor = '#7c1a80'
      borderwide = 5
      nameapp = 'WELCOME TO HABITFUN'
      
      class mainscreen(ui.View):
          def __init__(self, *args, **kwargs):
              self.frame = (equis,yee,ancho,alto)
              self.background_color = bgcolor
              self.border_color = bordercolor
              self.border_width = borderwide
              self.name = nameapp
              
              
      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)''')
      
      vanimation = mainscreen()
      vanimation.present('sheet')
      
      def chge_name():
          vanimation.name = 'HABITFUN'
      ui.delay(chge_name,2)
      
      v=ui.View(name='LOGIN',background_color='#4b8040' ,frame=(400,0,400,400))
      v1=ui.View(name='LOGIN',background_color='#2d5f80' ,frame=(0,0,400,800))
      	
      def button1_tapped(sender):
      		sender.superview.close()
      		vanimation.close()
      	
      def button2_tapped(sender):
      		c.execute("INSERT INTO logindata VALUES(?,?,?)", (date_login, user_name, pwd_user))
      		conn.commit()
      		conn.close
      		
      button1 = ui.Button(title = 'SALIR', alignment=ui.ALIGN_CENTER, bg_color = '#fff2f2', font_color = 'black')
      button1.frame = (50,250,100,50)
      button1.tint_color = 'black'
      button1.border_width = 1
      button1.action = button1_tapped
      
      button2 = ui.Button(title = 'ACEPTAR', alignment=ui.ALIGN_CENTER, bg_color = '#fb99ff', font_color = 'black')
      button2.frame = (250,250,100,50)
      button2.tint_color = 'black'
      button2.border_width = 1
      button2.action = button2_tapped
      
      label1 = ui.Label(alignment=ui.ALIGN_CENTER,bg_color='#fafafa',border_color='black',border_width=1,frame=(50, 50, 300, 40),name='User',text='User Name', text_color = '#0d60fd')
      label2 = ui.Label(alignment=ui.ALIGN_CENTER,bg_color='#fafafa',border_color='black',border_width=1,frame=(50, 150, 300, 40),name='Password',text='Password', text_color = '#0d60fd')
      
      t1=ui.TextField(frame=(50,100,300,40))
      t2=ui.TextField(frame=(50,200,300,40))
      
      v.add_subview(label1)
      v.add_subview(label2)
      v.add_subview(button1)
      v.add_subview(button2)
      v.add_subview(t1)
      v.add_subview(t2)
      
      t1.begin_editing()
      
      #vanimation.add_subview(v)
      vanimation.add_subview(v1)
      
      vanimation.add_subview(v)
      v.present('sheet')
      
      
      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        Doesn't look like you defined those names... Do a search through your code, and see if you can find where those are defined!

        Perhaps you meant to define those names from the text field values, but the code you posted doesn't.

        Also, note in one case you are trying to execute with variable names, but in the other case you use literals.

        cvp 1 Reply Last reply Reply Quote 0
        • sendog3c
          sendog3c last edited by

          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.
          cvp 1 Reply Last reply Reply Quote 0
          • cvp
            cvp @sendog3c last edited by cvp

            @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 entered

                    date_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')
            
            1 Reply Last reply Reply Quote 0
            • cvp
              cvp @JonB last edited by

              @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

              1 Reply Last reply Reply Quote 0
              • sendog3c
                sendog3c last edited by

                Thank you both.

                Where can I manipulate sqlite3. I mean, Browse data, delete columns, etc.

                Regards;

                cvp 1 Reply Last reply Reply Quote 0
                • cvp
                  cvp @sendog3c last edited by cvp

                  @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 one

                  Example (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()
                  
                  1 Reply Last reply Reply Quote 0
                  • sendog3c
                    sendog3c last edited by

                    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.

                    cvp 1 Reply Last reply Reply Quote 0
                    • cvp
                      cvp @sendog3c last edited by

                      @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 logindata

                      Of 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

                      1 Reply Last reply Reply Quote 1
                      • sendog3c
                        sendog3c last edited by

                        Thanks again

                        1 Reply Last reply Reply Quote 0
                        • brumm
                          brumm last edited by

                          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.

                          1 Reply Last reply Reply Quote 0
                          • sendog3c
                            sendog3c last edited by

                            Thank you Brumm. I a going to check it.

                            1 Reply Last reply Reply Quote 0
                            • JonB
                              JonB last edited by

                              I haven't tried it, but there is https://forum.omz-software.com/topic/2326/sqlite3-browser

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post
                              Powered by NodeBB Forums | Contributors