Skip to content

Commit

Permalink
馃敡Fixed #7 - Escaping characters correctly (#8)
Browse files Browse the repository at this point in the history
* 馃敡Fixed #7 - Escaping characters correctly
* 鉁忥笍  Updated docstring
* build: Version bump v2.0.4
  • Loading branch information
EndlessTrax committed May 6, 2023
1 parent 1c6fdf3 commit cb23cff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 36 deletions.
2 changes: 1 addition & 1 deletion pgn_to_sqlite/__init__.py
@@ -1,3 +1,3 @@
"""Fetch your games from chess.com and lichess.org and add them to a sqlite database"""

__version__ = "2.0.3"
__version__ = "2.0.4"
61 changes: 26 additions & 35 deletions pgn_to_sqlite/cli.py
Expand Up @@ -38,19 +38,23 @@ def create_db_connection(path: str):
return connection


def execute_db_query(connection, query: str) -> None:
def execute_db_query(connection, query: str, values: tuple = None) -> None:
"""Executes a SQL query on the Sqlite3 database
Args:
connection: A database connection object
query: The SQL query as a string
values: A tuple of values to be inserted into the query
Returns:
Nothing.
"""
cursor = connection.cursor()
try:
cursor.execute(query)
if values:
cursor.execute(query, values)
else:
cursor.execute(query)
connection.commit()
except sqlite3.Error as e:
print(f"The error '{e}' occurred")
Expand All @@ -66,42 +70,29 @@ def save_game_to_db(connection, pgn: dict) -> None:
Returns:
Nothing.
"""

execute_db_query(
connection,
f"""INSERT INTO
games (
event,
site,
date,
round,
white,
black,
result,
eco,
white_elo,
black_elo,
variant,
time_control,
termination,
moves)
VALUES
"""INSERT INTO
games(event, site, date, round, white, black, result, eco, white_elo,
black_elo, variant, time_control, termination, moves)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);""",
(
'{pgn["event"]}',
'{pgn["site"]}',
'{pgn["date"]}',
'{pgn["round"]}',
'{pgn["white"]}',
'{pgn["black"]}',
'{pgn["result"]}',
'{pgn["eco"]}',
'{pgn["white_elo"]}',
'{pgn["black_elo"]}',
'{pgn["variant"]}',
'{pgn["time_control"]}',
'{pgn["termination"]}',
'{pgn["moves"]}'
);
""",
pgn["event"],
pgn["site"],
pgn["date"],
pgn["round"],
pgn["white"],
pgn["black"],
pgn["result"],
pgn["eco"],
pgn["white_elo"],
pgn["black_elo"],
pgn["variant"],
pgn["time_control"],
pgn["termination"],
pgn["moves"],
),
)


Expand Down

0 comments on commit cb23cff

Please sign in to comment.