Near show syntax error

I am building a table in pyqt5 which will show the output of SQL in the table. First you have to type the command in command line and then press the button to update the table. Although, the comm...

I am building a table in pyqt5 which will show the output of SQL in the table. First you have to type the command in command line and then press the button to update the table.

Although, the commands like insert into table are working but when i type show databases; in the command line it is showing me this error:

Traceback (most recent call last):
  File "c:/Users/intel/Desktop/table.py", line 24, in load_data
    result = connection.execute(inp)
sqlite3.OperationalError: near "show": syntax error

Here is my code:

import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QAction, QTableWidget,QTableWidgetItem,QVBoxLayout
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
from PyQt5 import QtWidgets
import sqlite3

inp = input('>> ')

class App(QWidget):
    def __init__(self):
        super().__init__()
        self.title = 'PyQt5 table - pythonspot.com'
        self.left = 0
        self.top = 0
        self.width = 300
        self.height = 200
        self.initUI()
#CREATE TABLE employees(email varchar(30), password(30));
    def load_data(self):
        connection = sqlite3.connect('my_db.db')
        #connection.execute(inp)
        #
        result = connection.execute(inp)
        self.tableWidget.setRowCount(0)

        for row_number, row_data in enumerate(result):
            self.tableWidget.insertRow(row_number)
            for column_number, data in enumerate(row_data):
                self.tableWidget.setItem(row_number, column_number, QTableWidgetItem(str(data)))

        connection.close()

    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)

        self.createTable()

        # Add box layout, add table to box layout and add box layout to widget
        self.layout = QVBoxLayout()
        self.layout.addWidget(self.tableWidget) 
        self.setLayout(self.layout) 

        self.btn = QtWidgets.QPushButton(self)
        self.btn.move(100,600)
        self.btn.setText("Hello")
        self.btn.clicked.connect(self.load_data)
        # Show widget
        self.show()

    def createTable(self):

        self.tableWidget = QTableWidget()
        self.tableWidget.setRowCount(1) ##set number of rows 
        self.tableWidget.setColumnCount(8) ##this is fixed for myTableWidget, ensure that both of your tables, sql and qtablewidged have the same number of columns 


        self.tableWidget.move(1,1)

        # table selection change
        self.tableWidget.doubleClicked.connect(self.on_click)

    @pyqtSlot()
    def on_click(self):
        print("n")
        for currentQTableWidgetItem in self.tableWidget.selectedItems():
            print(currentQTableWidgetItem.row(), currentQTableWidgetItem.column(), currentQTableWidgetItem.text())

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_()) 

Any help would be appreciated!!

Technical Problem Cluster First Answered On
June 19, 2020

Popularity
10/10

Helpfulness
2/10

Contents

Code Examples

  • sqlite3.OperationalError: near «7»: syntax error
  • sqlite3.OperationalError: near «7»: syntax error
  • sqlite3.OperationalError: near «WHERE»: syntax error
  • sqlite3.OperationalError: near «7»: syntax error
  • Related Problems

  • sqlite3.operationalerror: near «)»: syntax error
  • TPC Matrix View Full Screen

    sqlite3.OperationalError: near «7»: syntax error


    Popularity

    9/10 Helpfulness
    2/10
    Language
    sql

    Defeated Dove

    Contributed on Jun 19 2020

    Defeated Dove

    12 Answers  Avg Quality 8/10


    sqlite3.OperationalError: near «7»: syntax error


    Popularity

    10/10 Helpfulness
    2/10
    Language
    sql

    Defeated Dove

    Contributed on Jun 19 2020

    Defeated Dove

    12 Answers  Avg Quality 8/10


    sqlite3.OperationalError: near «WHERE»: syntax error


    Popularity

    9/10 Helpfulness
    1/10
    Language
    sql

    Good Gnu

    Contributed on Aug 11 2020

    Good Gnu

    11 Answers  Avg Quality 5/10


    sqlite3.OperationalError: near «7»: syntax error


    Popularity

    9/10 Helpfulness
    1/10
    Language
    sql

    Defeated Dove

    Contributed on Jun 19 2020

    Defeated Dove

    12 Answers  Avg Quality 8/10


    I am getting an error trying to connect to my SQLite database. I have tried several things and it is not working. I cannot figure out where the syntax error is, near self.Rating_var.get()))

    #=======CONNECT TO SQLITE==========
        def add_film(self):
            conn = connect('patrick.db')
            c = conn.cursor()
            c.execute("insert into patrick values(%s,%s,%s,%s,%s,%s,%s,%s)",(self.Title_var.get(),
                                                                              self.Actors_var.get(),
                                                                              self.Directors_var.get(),
                                                                              self.Genre_var.get(),
                                                                              self.Summary_var.get(),
                                                                              self.Year_var.get(),
                                                                              self.Length_var.get(),
                                                                              self.Rating_var.get())
                                                                              
                                                                              
            con.commit()
            con.close()

    Error:

    Exception in Tkinter callback Traceback (most recent call last): File "C:UsersGamingAppDataLocalProgramsPythonPython37libtkinter__init__.py", line 1705, in __call__ return self.func(*args) File "C:/Film-Classic-Database/film1.py", line 147, in add_film self.Rating_var.get())) sqlite3.OperationalError: near "%": syntax error

    stullis

    Minister of Silly Walks


    Posts: 444

    Threads: 1

    Joined: Sep 2018

    Reputation:
    62

    I see a missing paren to close out c.execute. Other than that, everything looks syntactically correct.

    Posts: 14

    Threads: 9

    Joined: Feb 2018

    Reputation:
    0

    Thank you. Yes, I added that parenthesis but still cannot figure out why it is not writing to my database when I click on add. It just gives me that error. Thank you for your help.

    Like this post? Please share to your friends:
  • Mysql rise error
  • Mysql replica skip error
  • Mysql password syntax error
  • Mysql outer join error
  • Near limit syntax error sqlite