@@ -133,6 +133,54 @@ def callee(session):
133
133
return pool .retry_operation_sync (callee )
134
134
135
135
136
+ def select_parametrized (pool , path , series_id , season_id , episode_id ):
137
+ def callee (session ):
138
+ query = """
139
+ PRAGMA TablePathPrefix("{}");
140
+
141
+ DECLARE $seriesId AS Uint64;
142
+ DECLARE $seasonId AS Uint64;
143
+ DECLARE $episodeId AS Uint64;
144
+
145
+ $format = DateTime::Format("%Y-%m-%d");
146
+ SELECT
147
+ title,
148
+ $format(DateTime::FromSeconds(CAST(DateTime::ToSeconds(DateTime::IntervalFromDays(CAST(air_date AS Int16))) AS Uint32))) AS air_date
149
+ FROM episodes
150
+ WHERE series_id = $seriesId AND season_id = $seasonId AND episode_id = $episodeId;
151
+ """ .format (
152
+ path
153
+ )
154
+
155
+ data_query = ydb .types .DataQuery (
156
+ query ,
157
+ parameters_types = {
158
+ "$seriesId" : ydb .types .PrimitiveType .Uint64 ,
159
+ "$seasonId" : ydb .types .PrimitiveType .Uint64 ,
160
+ "$episodeId" : ydb .types .PrimitiveType .Uint64 ,
161
+ },
162
+ )
163
+
164
+ result_sets = session .transaction (ydb .SerializableReadWrite ()).execute (
165
+ data_query ,
166
+ {
167
+ "$seriesId" : series_id ,
168
+ "$seasonId" : season_id ,
169
+ "$episodeId" : episode_id ,
170
+ },
171
+ commit_tx = True ,
172
+ settings = ydb .table .ExecDataQuerySettings ().with_keep_in_cache (True ),
173
+ )
174
+ print ("\n > select_parametrized_transaction:" )
175
+ for row in result_sets [0 ].rows :
176
+ print ("episode title:" , row .title , ", air date:" , row .air_date )
177
+
178
+ return result_sets [0 ]
179
+
180
+ return pool .retry_operation_sync (callee )
181
+
182
+
183
+ # Prepared query with session-based cache
136
184
def select_prepared (pool , path , series_id , season_id , episode_id ):
137
185
def callee (session ):
138
186
query = """
@@ -338,5 +386,8 @@ def run(endpoint, database, path):
338
386
select_prepared (pool , full_path , 2 , 3 , 7 )
339
387
select_prepared (pool , full_path , 2 , 3 , 8 )
340
388
389
+ select_parametrized (pool , full_path , 2 , 3 , 9 )
390
+ select_parametrized (pool , full_path , 2 , 3 , 10 )
391
+
341
392
explicit_tcl (pool , full_path , 2 , 6 , 1 )
342
- select_prepared (pool , full_path , 2 , 6 , 1 )
393
+ select_parametrized (pool , full_path , 2 , 6 , 1 )
0 commit comments