comparison shelltools/query-pr/query.py @ 56:42d7888272a0 default tip

Implement fetch_classifications().
author David A. Holland
date Sun, 10 Apr 2022 19:37:18 -0400
parents 40f64a96481f
children
comparison
equal deleted inserted replaced
55:40f64a96481f 56:42d7888272a0
37 # just assemble a massive view with one column for each field. 37 # just assemble a massive view with one column for each field.
38 # 38 #
39 # The QueryBuilder class knows how to arrange for all known fields to 39 # The QueryBuilder class knows how to arrange for all known fields to
40 # be present. 40 # be present.
41 # 41 #
42
43 # loaded below
44 hierclasses = []
45 flatclasses = []
46 textclasses = []
47 tagclasses = []
42 48
43 class QueryBuilder: 49 class QueryBuilder:
44 # these fields are in the PRs table 50 # these fields are in the PRs table
45 prtable_fields = [ 51 prtable_fields = [
46 "id", "synopsis", "confidential", "state", "locked", 52 "id", "synopsis", "confidential", "state", "locked",
266 cursor.execute(qtext, args) 272 cursor.execute(qtext, args)
267 result = cursor.fetchall() 273 result = cursor.fetchall()
268 cursor.close() 274 cursor.close()
269 return result 275 return result
270 # end querydb 276 # end querydb
277
278 ############################################################
279 # classification schemes
280
281 #
282 # Load the available classification schemes from the database.
283 # We only need their names up front.
284 #
285 def fetch_classifications():
286 global hierclasses, flatclasses, textclasses, tagclasses
287 hierclasses = querydb('''
288 ------------------------------
289 SELECT name FROM hierclass_names ORDER BY ordering;
290 ------------------------------
291 ''', [])
292 flatclasses = querydb('''
293 ------------------------------
294 SELECT name FROM flatclass_names ORDER BY ordering;
295 ------------------------------
296 ''', [])
297 textclasses = querydb('''
298 ------------------------------
299 SELECT name FROM textclass_names ORDER BY ordering;
300 ------------------------------
301 ''', [])
302 tagclasses = querydb('''
303 ------------------------------
304 SELECT name FROM tagclass_names ORDER BY ordering;
305 ------------------------------
306 ''', [])
307 # The results come back as monoples, unwrap that
308 hierclasses = [name for (name,) in hierclasses]
309 flatclasses = [name for (name,) in flatclasses]
310 textclasses = [name for (name,) in textclasses]
311 tagclasses = [name for (name,) in tagclasses]
271 312
272 ############################################################ 313 ############################################################
273 # query class for searches 314 # query class for searches
274 # XXX: obsolete, remove 315 # XXX: obsolete, remove
275 316
1335 if selections != []: 1376 if selections != []:
1336 msg = "No queries given for requested selections\n" 1377 msg = "No queries given for requested selections\n"
1337 sys.stderr.write(msg) 1378 sys.stderr.write(msg)
1338 exit(1) 1379 exit(1)
1339 1380
1340 return Invocation(ops) 1381 return (Invocation(ops), paranoid)
1341 # end getargs 1382 # end getargs
1342 1383
1343 ############################################################ 1384 ############################################################
1344 # main 1385 # main
1345 1386
1346 todo = getargs(sys.argv) 1387 (todo, paranoid) = getargs(sys.argv)
1347 #todo.dump(Dumper(sys.stdout)) 1388 #todo.dump(Dumper(sys.stdout))
1348 1389
1349 opendb() 1390 opendb(paranoid)
1350 fetch_classifications() 1391 fetch_classifications()
1351 todo = compile(todo) 1392 todo = compile(todo)
1352 run(todo) 1393 run(todo)
1353 closedb() 1394 closedb()
1354 exit(0) 1395 exit(0)