Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. How to deal with Dynamic data entry? how to work with this!
Qt 6.11 is out! See what's new in the release blog

How to deal with Dynamic data entry? how to work with this!

Scheduled Pinned Locked Moved Unsolved Brainstorm
9 Posts 2 Posters 4.6k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    import mysql.connector

    con = mysql.connector.connect(user="root",password="admingelo",host="localhost",database="dbinsert")

    m = con.cursor()

    keyword = 'heypeybeyday'

    m.execute("INSERT INTO spo (name) VALUES (%s)",(keyword))

    con.commit()

    i alway get an error when i add keyword

    raven-worxR 2 Replies Last reply
    0
    • ? A Former User

      import mysql.connector

      con = mysql.connector.connect(user="root",password="admingelo",host="localhost",database="dbinsert")

      m = con.cursor()

      keyword = 'heypeybeyday'

      m.execute("INSERT INTO spo (name) VALUES (%s)",(keyword))

      con.commit()

      i alway get an error when i add keyword

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Gelo

      i alway get an error when i add keyword

      may you tell us the error?

      and also you should provide a little bit more info, like what Qt version, what platform, or even what programming language you are using (even when most people may deduce it from pieces)

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      ? 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @Gelo

        i alway get an error when i add keyword

        may you tell us the error?

        and also you should provide a little bit more info, like what Qt version, what platform, or even what programming language you are using (even when most people may deduce it from pieces)

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        @raven-worx
        Traceback (most recent call last):
        File "C:\Users\angelo\Desktop\MySQLdb.py", line 11, in <module>
        m.execute(insert_this)
        File "C:\Python27\lib\site-packages\mysql\connector\cursor.py", line 529, in execute
        stmt = operation.encode(self._connection.python_charset)
        AttributeError: 'tuple' object has no attribute 'encode'

        pyqt4 python 2.713

        1 Reply Last reply
        0
        • ? A Former User

          import mysql.connector

          con = mysql.connector.connect(user="root",password="admingelo",host="localhost",database="dbinsert")

          m = con.cursor()

          keyword = 'heypeybeyday'

          m.execute("INSERT INTO spo (name) VALUES (%s)",(keyword))

          con.commit()

          i alway get an error when i add keyword

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Gelo
          try:

          m.execute("INSERT INTO spo (name) VALUES (%s)", (keyword, ) )
          

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          ? 1 Reply Last reply
          0
          • raven-worxR raven-worx

            @Gelo
            try:

            m.execute("INSERT INTO spo (name) VALUES (%s)", (keyword, ) )
            
            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @raven-worx i get the same error :\

            raven-worxR 1 Reply Last reply
            0
            • ? A Former User

              @raven-worx i get the same error :\

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @Gelo
              why are you using a tuple anyway when you only have one parameter in your query?

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              ? 1 Reply Last reply
              0
              • raven-worxR raven-worx

                @Gelo
                why are you using a tuple anyway when you only have one parameter in your query?

                ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                @raven-worx i try it with multiple entry but i got the same error again :3

                raven-worxR 1 Reply Last reply
                0
                • ? A Former User

                  @raven-worx i try it with multiple entry but i got the same error again :3

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  @Gelo
                  The following shouldn't give you the same error...

                  m.execute("INSERT INTO spo (name) VALUES (%s)", keyword )
                  

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  ? 1 Reply Last reply
                  0
                  • raven-worxR raven-worx

                    @Gelo
                    The following shouldn't give you the same error...

                    m.execute("INSERT INTO spo (name) VALUES (%s)", keyword )
                    
                    ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #9

                    @raven-worx can you help how to get data in QLineEdit going to my database by Clicking Submit button? here is my code i am using python 2.17.13

                    import os
                    import sys
                    import mysql.connector
                    from PyQt4.QtSql import *
                    from PyQt4.QtGui import *
                    from PyQt4.QtCore import *
                    from PyQt4 import QtGui, QtCore

                    class Window(QtGui.QMainWindow):
                    def init(self):
                    super(Window, self).init()
                    self.setGeometry(50,50,0,0)
                    self.setFixedSize(900,600)
                    self.setWindowTitle("IMS Delta EarthMoving")
                    self.setWindowIcon(QtGui.QIcon('delta.png'))
                    pic = QtGui.QLabel(self)
                    pic.setGeometry(240, -165, 698, 500)
                    pic.setPixmap(QtGui.QPixmap(os.getcwd() + "/delta2.png"))

                        self.Input()
                        self.search()
                        self.button()
                        self.database()
                             
                    def search(self):
                        assetSearch = QLabel("Asset search",self)
                        assetSearch.move(10,10)
                        AssetTag=QLineEdit(self)
                        fbox=QFormLayout() 
                        fbox.addRow(AssetTag)
                        AssetTag.move(75,15)#left-right and up-down
                        AssetTag.resize(150,20)
                    
                    def Input(self):
                        INPUT1LABEL = QLabel("INPUT1",self)
                        INPUT1LABEL.move(10,225)
                        INPUT1 = QLineEdit(self)
                        fbox=QFormLayout()
                        fbox.addRow(INPUT1)
                        INPUT1.move(75,230)
                        INPUT1.resize(150,20)
                      
                        btnSubmit = QtGui.QPushButton("Submit",self)
                        btnSubmit.clicked.connect(self.submit_function)
                        btnSubmit.resize(btnSubmit.minimumSizeHint())
                        btnSubmit.move(150,470)
                        
                    def button(self):
                        btnQuit = QtGui.QPushButton("Quit", self)
                        btnQuit.clicked.connect(self.close_application)
                        btnQuit.resize(btnQuit.minimumSizeHint())
                        btnQuit.move(150,138) #.move(left-right,top-bottom()
                    
                        btnSearch = QtGui.QPushButton("Search", self)
                        #btnSearch.clicked.connect(self.) #add function for this ButtonBox
                        btnSearch.resize(btnSearch.minimumSizeHint())
                        btnSearch.move(150,40)
                    
                        btnUpdate = QtGui.QPushButton("Update",self)
                        btnUpdate.clicked.connect(self.update_confirmation)
                        btnUpdate.resize(btnUpdate.minimumSizeHint())
                        btnUpdate.move(150,90)
                    
                        btnDelete = QtGui.QPushButton("Delete",self)
                        #btnDelete.clicked.connect(self.) add function for this ButtonBox
                        btnDelete.resize(btnDelete.minimumSizeHint())
                        btnDelete.move(150,114)
                    
                        self.show()
                    
                    def close_application(self):
                        choice = QtGui.QMessageBox.question(self, 'Exit',"Are you sure?",QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
                        if choice == QtGui.QMessageBox.Yes:
                            sys.exit()
                        else:
                            pass
                    
                    def update_confirmation(self):
                        choice = QtGui.QMessageBox.question(self,'Notice!',"Are you sure?",QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
                        if choice == QtGui.QMessageBox.Yes:
                            #put the function here!
                            choice = QtGui.QMessageBox.question(self,'IMS',"Query saved",QtGui.QMessageBox.Ok)
                            if choice == QtGui.QMessageBox.Ok:
                                pass
                        else:
                            pass
                     
                    def submit_function(self):
                        con = mysql.connector.connect(user="root",password="admingelo",host="localhost",database="test")
                        manager = con.cursor()
                        
                        Date = 'Ai'
                        Name = 'g'
                        Sex  = 'g'
                        
                        insert_this_data = ("INSERT INTO test_table(name,age,sex) VALUES(%s,%s,%s)")
                    
                        data = (Date,Name,Sex)
                    
                        manager.execute(insert_this_data,data)
                    
                        con.commit()
                        print "Insert Successful!"
                    
                    def database(self): #Table data view
                        table 	= QTableWidget(self)
                        db 	= QSqlDatabase.addDatabase("QMYSQL")
                    
                        db.setHostName("localhost")
                        db.setDatabaseName("test")
                        db.setUserName("root")
                        db.setPassword("admingelo")
                    
                        if (db.open()==False):     
                            QMessageBox.critical(None, "Database Error",
                    		    db.lastError().text())   
                    		    
                        query = QSqlQuery ("SELECT * FROM sfo")   
                    
                        table.setColumnCount(query.record().count())
                        table.setRowCount(query.size())
                    
                        index=0
                        while (query.next()):
                                table.setItem(index,0,QTableWidgetItem(query.value(0).toString()))
                                table.setItem(index,1,QTableWidgetItem(query.value(1).toString()))
                                table.setItem(index,2,QTableWidgetItem(query.value(2).toString()))
                                table.setItem(index,3,QTableWidgetItem(query.value(3).toString()))
                                table.setItem(index,4,QTableWidgetItem(query.value(4).toString()))
                                table.setItem(index,5,QTableWidgetItem(query.value(5).toString()))
                                index = index+1
                    
                        table.show()
                        table.resize(618,360)
                        table.move(240,230)
                    

                    def run():
                    app = QtGui.QApplication(sys.argv)
                    GUI = Window()
                    sys.exit(app.exec_())

                    run()

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved