diff options
author | jwansek <eddie.atten.ea29@gmail.com> | 2023-04-28 13:11:44 +0100 |
---|---|---|
committer | jwansek <eddie.atten.ea29@gmail.com> | 2023-04-28 13:11:44 +0100 |
commit | 5dd5ed8757c36a91e5031a3a55ea8a4291714691 (patch) | |
tree | a9426e13aa051248c418b98dfbc10b6f403e1b9c /database.py | |
parent | 43ba613b9e1ea9dbf6f94361d43418c91c8c0785 (diff) | |
download | UKGenderPayGap-5dd5ed8757c36a91e5031a3a55ea8a4291714691.tar.gz UKGenderPayGap-5dd5ed8757c36a91e5031a3a55ea8a4291714691.zip |
Added searching for businesses
Diffstat (limited to 'database.py')
-rw-r--r-- | database.py | 16 |
1 files changed, 16 insertions, 0 deletions
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()] |