I am trying the following python code:
import sqlite3
class database:
def __init__(self):
self.conn = sqlite3.connect("warehousedb.db")
self.cursor = self.conn.cursor()
self.cursor.execute(
"CREATE TABLE IF NOT EXISTS `admin` (admin_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, username TEXT, password TEXT)")
self.cursor.execute(
"CREATE TABLE IF NOT EXISTS `product` (product_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, product_name TEXT, product_qty TEXT, product_price TEXT)")
self.cursor.execute("SELECT * FROM `admin` WHERE `username` = 'admin' AND `password` = 'admin'")
if self.cursor.fetchone() is None:
self.cursor.execute("INSERT INTO `admin` (username, password) VALUES('admin', 'admin')")
self.conn.commit()
def __del__(self):
self.cursor.close()
self.conn.close()
def Execute_SQL(self, sql):
self.cursor.execute(sql)
self.conn.commit()
def Get_SQL(self, sql):
self.cursor.execute(sql)
return self.cursor.fetchall()
def Get_SQL_One_Rec(self, sql):
self.cursor.execute(sql)
return self.cursor.fetchone()
Then when trying this code:
db = database()
st = "SELECT * FROM `admin` WHERE `username` = '" + USERNAME.get() + "' AND `password` = '" + PASSWORD.get() + "'"
rec = db.Get_SQL_One_Rec(st)
I am getting the following error:
rec = db.Get_SQL_One_Rec(st) TypeError: Get_SQL_One_Rec() missing 1 required positional argument: 'sql'
I can see from the Python Documentation that the Self object is automatically passed, so why I am getting this error? 
from Self is not passed to the class method in Python
No comments:
Post a Comment