From 5dd5ed8757c36a91e5031a3a55ea8a4291714691 Mon Sep 17 00:00:00 2001 From: jwansek Date: Fri, 28 Apr 2023 13:11:44 +0100 Subject: Added searching for businesses --- database.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'database.py') diff --git a/database.py b/database.py index 26d2683..53d755e 100644 --- a/database.py +++ b/database.py @@ -120,6 +120,9 @@ class PayGapDatabase: self.__connection.commit() return self.__connection + def _wrap_percent(self, word): + return "%%%s%%" % (word) + def append_sic_sections(self, section_id, description): # print("Section ID: '%s', Description: '%s'" % (section_id, description)) with self.__connection.cursor() as cursor: @@ -204,3 +207,16 @@ class PayGapDatabase: cursor.execute("SELECT * FROM sic WHERE sic_code = %s", (sic, )) if cursor.fetchone() != None: cursor.execute("INSERT INTO employer_sic VALUES (%s, %s);", (company_number, sic)) + + def search_company(self, company_prefix): + with self.__connection.cursor() as cursor: + cursor.execute(""" + SELECT name, company_number FROM employer + WHERE name LIKE '%s' OR current_name LIKE '%s' + LIMIT 10; + """ % ( + self._wrap_percent(company_prefix), + self._wrap_percent(company_prefix) + )) + + return [(i[0].title(), i[1]) for i in cursor.fetchall()] -- cgit v1.2.3