22from typing import Sequence
33
44import timeplus_connect
5+ from timeplus_connect .driver .binding import quote_identifier , format_query_value
56from dotenv import load_dotenv
67from fastmcp import FastMCP
78
@@ -38,18 +39,18 @@ def list_databases():
3839def list_tables (database : str , like : str = None ):
3940 logger .info (f"Listing tables in database '{ database } '" )
4041 client = create_timeplus_client ()
41- query = f"SHOW STREAMS FROM { database } "
42+ query = f"SHOW STREAMS FROM { quote_identifier ( database ) } "
4243 if like :
43- query += f" LIKE ' { like } ' "
44+ query += f" LIKE { format_query_value ( like ) } "
4445 result = client .command (query )
4546
4647 # Get all table comments in one query
47- table_comments_query = f"SELECT name, comment FROM system.tables WHERE database = ' { database } ' "
48+ table_comments_query = f"SELECT name, comment FROM system.tables WHERE database = { format_query_value ( database ) } "
4849 table_comments_result = client .query (table_comments_query )
4950 table_comments = {row [0 ]: row [1 ] for row in table_comments_result .result_rows }
5051
5152 # Get all column comments in one query
52- column_comments_query = f"SELECT table, name, comment FROM system.columns WHERE database = ' { database } ' "
53+ column_comments_query = f"SELECT table, name, comment FROM system.columns WHERE database = { format_query_value ( database ) } "
5354 column_comments_result = client .query (column_comments_query )
5455 column_comments = {}
5556 for row in column_comments_result .result_rows :
@@ -60,7 +61,7 @@ def list_tables(database: str, like: str = None):
6061
6162 def get_table_info (table ):
6263 logger .info (f"Getting schema info for table { database } .{ table } " )
63- schema_query = f"DESCRIBE STREAM { database } .` { table } ` "
64+ schema_query = f"DESCRIBE STREAM { quote_identifier ( database ) } . { quote_identifier ( table ) } "
6465 schema_result = client .query (schema_query )
6566
6667 columns = []
0 commit comments