import sqlite3


def get_aircraft_registrant(database, mode_s_code_hex):
	"""
	Looks up an aircraft's registrant's name based on the mode_s_code_hex
	in the FAA's database.  Example: FEDERAL EXPRESS CORP (a FedEx plane)

	Parameters:
		1 - database file path
		2 - mode_s_code_hex (must be all uppercase string)

	Returns:
		The aircraft's registrant
	"""

	# Connect to the database
	conn = sqlite3.connect(database)

	select_statement = (
		'SELECT '
			'IFNULL(faa_master.name, "REG?") '
		'FROM faa_master '
		'WHERE faa_master.mode_s_code_hex LIKE "' + mode_s_code_hex + '%";')

	results = conn.execute(select_statement)

	# Get the one and only row of the results set
	result = results.fetchone()

	conn.close()

	# In the event that no results at all are returned
	if result is not None:
		# Create string of registrant name with trailing whitespace removed
		registrant = str(result[0]).rstrip()

	else:
		registrant = "REG?"

	return registrant