@@ -37,16 +37,7 @@ async def count_table_rows(session, keyspace: str, table_name: str) -> int:
3737 # Note: COUNT(*) can be slow on large tables
3838 # Consider using token ranges for very large tables
3939
40- # First validate that the table exists to prevent SQL injection
41- validation_stmt = await session .prepare (
42- "SELECT table_name FROM system_schema.tables WHERE keyspace_name = ? AND table_name = ?"
43- )
44- validation_result = await session .execute (validation_stmt , [keyspace , table_name ])
45- if not validation_result .one ():
46- raise ValueError (f"Table { keyspace } .{ table_name } does not exist" )
47-
4840 # For COUNT queries, we can't use prepared statements with dynamic table names
49- # Since we've validated the table exists, we can safely construct the query
5041 # In production, consider implementing a token range count for large tables
5142 result = await session .execute (f"SELECT COUNT(*) FROM { keyspace } .{ table_name } " )
5243 return result .one ()[0 ]
@@ -79,16 +70,7 @@ def progress_callback(page_num: int, rows_so_far: int):
7970 start_time = datetime .now ()
8071
8172 # CRITICAL: Use context manager for streaming to prevent memory leaks
82- # Validate table exists before streaming
83- validation_stmt = await session .prepare (
84- "SELECT table_name FROM system_schema.tables WHERE keyspace_name = ? AND table_name = ?"
85- )
86- validation_result = await session .execute (validation_stmt , [keyspace , table_name ])
87- if not validation_result .one ():
88- raise ValueError (f"Table { keyspace } .{ table_name } does not exist" )
89-
9073 # For SELECT * with dynamic table names, we can't use prepared statements
91- # Since we've validated the table exists, we can safely construct the query
9274 async with await session .execute_stream (
9375 f"SELECT * FROM { keyspace } .{ table_name } " , stream_config = config
9476 ) as result :
@@ -155,16 +137,7 @@ async def _export():
155137 start_time = datetime .now ()
156138
157139 # Use context manager for proper streaming cleanup
158- # Validate table exists before streaming
159- validation_stmt = await session .prepare (
160- "SELECT table_name FROM system_schema.tables WHERE keyspace_name = ? AND table_name = ?"
161- )
162- validation_result = await session .execute (validation_stmt , [keyspace , table_name ])
163- if not validation_result .one ():
164- raise ValueError (f"Table { keyspace } .{ table_name } does not exist" )
165-
166140 # For SELECT * with dynamic table names, we can't use prepared statements
167- # Since we've validated the table exists, we can safely construct the query
168141 async with await session .execute_stream (
169142 f"SELECT * FROM { keyspace } .{ table_name } " , stream_config = config
170143 ) as result :
0 commit comments