diff --git a/library.py b/library.py index 024a5a3..fca65f3 100644 --- a/library.py +++ b/library.py @@ -381,7 +381,7 @@ def insert_parts(self, data, cols): con.executemany(query, data) con.commit() - def get_part_details(self, lcsc: list) -> dict: + def get_part_details(self, lcsc: list) -> list: """Get the part details for a list of LCSC numbers using optimized FTS5 querying.""" with contextlib.closing(sqlite3.connect(self.partsdb_file)) as con: con.row_factory = dict_factory @@ -390,11 +390,10 @@ def get_part_details(self, lcsc: list) -> dict: query = '''SELECT "LCSC Part" AS lcsc, "Stock" AS stock, "Library Type" AS type FROM parts WHERE parts MATCH :number LIMIT 1''' # Use parameter binding to prevent SQL injection and handle the query more efficiently for number in lcsc: - cur.execute(query, {"number": number}) - results.extend([x for x in cur.fetchall() if x[0] == number]) # Filter exact match as FTS5 does return every match - if results: - return results[0] - return {} + self.logger.debug(number) + cur.execute(query, {"number": f'"{number}"'}) + results.extend([x for x in cur.fetchall() if x["lcsc"] == number]) # Filter exact match as FTS5 does return every match + return results def update(self): """Update the sqlite parts database from the JLCPCB CSV.""" diff --git a/mainwindow.py b/mainwindow.py index 7595e5a..e44c690 100644 --- a/mainwindow.py +++ b/mainwindow.py @@ -612,9 +612,15 @@ def populate_footprint_list(self, *_): corrections = self.library.get_all_correction_data() # find rotation correction values for part in parts: - if details: - part["type"] = details["type"] - part["stock"] = details["stock"] + detail = list( + filter( + lambda x, lcsc=part["lcsc"]: x["lcsc"] == lcsc, + details, + ) + ) + if detail: + part["type"] = detail[0]["type"] + part["stock"] = detail[0]["stock"] # First check if the part name mathes for regex, correction in corrections: if re.search(regex, str(part["reference"])):