Skip to content

Commit

Permalink
Make sure the LCSC part number search only matches against the LCSC c…
Browse files Browse the repository at this point in the history
…olumn, incidentally making the query _another_ 25x faster
  • Loading branch information
Oscilllator authored and Bouni committed Jul 23, 2024
1 parent 35b46cd commit a997824
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions library.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,14 @@ def get_part_details(self, lcsc):
con.row_factory = sqlite3.Row # To access columns by names
cur = con.cursor()
results = []
query = '''SELECT "LCSC Part", "Stock", "Library Type" FROM parts WHERE "LCSC Part" MATCH ?'''
query = '''SELECT "LCSC Part", "Stock", "Library Type" FROM parts WHERE parts MATCH ?'''

# Use parameter binding to prevent SQL injection and handle the query more efficiently
for number in lcsc:
# Each number needs to be wrapped in double quotes for exact match in FTS5
match_query = f'"{number}"'
match_query = f'"LCSC Part:{number}"'
cur.execute(query, (match_query,))
results.extend(cur.fetchall())

return results

def update(self):
Expand Down

0 comments on commit a997824

Please sign in to comment.