"""
This module caters all the database related classes

Contains
=======

* DatabaseConnection

Author: Sudhanshu Mishra
"""


from __future__ import division, print_function

import MySQLdb


class DatabaseConnection:

    """
    This class takes care of all the data related queries with the
    MySQL server.
    """

    def __init__(self, ahost, ausername, apassword, adb):
        """
        Connecting With MySQL
        """
        self.ahost = ahost
        self.ausername = ausername
        self.apassword = apassword
        self.adb = adb
        try:
            self.db = MySQLdb.connect(
                host=ahost,
                user=ausername,
                passwd=apassword,
                db=adb
            )

        except MySQLdb.Error as e:
            print("An error has been raised. %s" % e)

    def check_login(self, user_id, password):
        """
        This method checks the login credentials of the user.
        It takes user_id and password as arguments and returns
        a boolean value. True means that login is successful
        and False means that either the user is not available
        or the credentials provided are wrong.
        """
        return True
        with self.db:
            cur = self.db.cursor()
            query = "SELECT * FROM users where user_id = \'" + \
                user_id + "\' and pass = \'" + password + "\'"
            cur.execute(query)  # Executing the query
            data = cur.fetchall()  # Fetching the output of the executed query
            # Logic behind checking the number of returned rows is when
            if(len(data) == 0):
                # there are no users or the credentials didn't match, MySQL
                return False
            else:               # will not return any row.
                return True

@@ -170,16 +170,28 @@
 nction%0A%0A
+import time%0A
 import M
@@ -197,16 +197,16 @@
 MySQLdb%0A
-
 %0A%0Aclass 
@@ -424,24 +424,25 @@
  With MySQL%0A
+%0A
         %22%22%22%0A
@@ -433,32 +433,33 @@
 QL%0A%0A        %22%22%22%0A
+%0A
         self.aho
@@ -1189,16 +1189,17 @@
  wrong.%0A
+%0A
         
@@ -1202,36 +1202,17 @@
     %22%22%22%0A
-        return True
 %0A
+
         
@@ -1789,16 +1789,16 @@
 ny row.%0A
-
         
@@ -1817,8 +1817,1326 @@
 rn True%0A
+%0A    def get_current_rate(share_code):%0A        %22%22%22%0A        This method returns the current rate of the stock%0A        in the market.%0A        It takes share_code as a parameter and returns its%0A        current rate as a float.%0A%0A        %22%22%22%0A%0A        with self.db:%0A            cur = self.db.cursor()%0A            query = %22SELECT %60current_rate%60 FROM market WHERE %60share_code%60 = %22 + %5C%0A                share_code%0A            cur.execute(query)%0A            data = cur.fetchone()%0A            return data%5B0%5D%0A%0A    def add_purchase(share_code, purchase_rate):%0A        %22%22%22%0A        This method inserts a purchase transaction in the purchase%0A        table. It takes share_code and purchase_rate as parameters%0A        and return nothing.%0A%0A        %22%22%22%0A%0A        with self.db:%0A            cur = self.db.cursor()%0A            query = %22INSERT INTO purchase VALUES(%22 + share_code + %5C%0A                %22, %22 + purchase_rate + %22, %22 + time.ctime() + %22)%22%0A            cur.execute(query)%0A%0A    def delete_purchase(share_code):%0A        %22%22%22%0A        This method deletes a purchase record from the purchase%0A        table. It takes share_code as a parameter and returns nothing.%0A%0A        %22%22%22%0A%0A        with self.db:%0A            cur = self.db.cursor()%0A            query = %22DELETE FROM purchase WHERE share_code = %22 + share_code%0A            cur.execute(query)%0A

Add one select, insert and delete query