1

I am trying to write a backend that will be used for an IOS app. I know it will be technically the wrong way to do it but it wont be deployed.

My issues is i get the error

self.cursor(query)
TypeError: 'CMySQLCursor' object is not callable

This happens when i run the following from main.py

import database


db = database.database()

staff = db.getData("SELECT * FROM timesheets.staff")

Finally this is my database.py code

import mysql.connector

class database :
    conn = ""
    cursor = ""

    def __init__(self):
        self.conn = mysql.connector.connect(user='james',
                                       password='timeismoney',
                                       host='hallfamily.mycrestron.com',
                                       database='timesheets',
                                       port='6033')

        self.cursor = self.conn.cursor()

        print("Done")

    def getData(self, query):

        #Checking if the user has applied a string
        if isinstance(query, str):
            self.cursor(query)
        else:
            return "You have provided a request that cant be processed"

        #Fetching all the results
        result = self.cursor.fetchall()

        #Returning back to the user
        return result

    def postData(self):
        print("Coming soon")


    def close(self):
        self.conn.close()

1 Answer 1

2

Instead of:

self.cursor(query)

Try this:

self.cursor.execute(query)
Sign up to request clarification or add additional context in comments.

2 Comments

This has solved the issue. Many thanks. Is there any official documentation that i can use as i couldnt find the official docs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.