Fossil SCM

Add the /repo_stat1 webpage (accessible only to administrators). Enhance the /repo_schema page so that it can optionally show the schema for a single table. Include sqlite_stat1 information on the /repo_schema page.

drh 2017-02-23 14:55 optimize-pragma
Commit f9f5702d7aaac0c2b3605ceecbb32888ea730bbf
1 file changed +64 -2
+64 -2
--- src/stat.c
+++ src/stat.c
@@ -383,10 +383,12 @@
383383
**
384384
** Show the repository schema
385385
*/
386386
void repo_schema_page(void){
387387
Stmt q;
388
+ Blob sql;
389
+ const char *zArg = P("n");
388390
login_check_credentials();
389391
if( !g.perm.Admin ){ login_needed(0); return; }
390392
391393
style_header("Repository Schema");
392394
style_adunit_config(ADUNIT_RIGHT_OK);
@@ -393,18 +395,78 @@
393395
style_submenu_element("Stat", "stat");
394396
style_submenu_element("URLs", "urllist");
395397
if( sqlite3_compileoption_used("ENABLE_DBSTAT_VTAB") ){
396398
style_submenu_element("Table Sizes", "repo-tabsize");
397399
}
398
- db_prepare(&q,
399
- "SELECT sql FROM repository.sqlite_master WHERE sql IS NOT NULL");
400
+ blob_init(&sql,
401
+ "SELECT sql FROM repository.sqlite_master WHERE sql IS NOT NULL", -1);
402
+ if( zArg ){
403
+ style_submenu_element("All", "repo_schema");
404
+ blob_appendf(&sql, " AND (tbl_name=%Q OR name=%Q)", zArg, zArg);
405
+ }
406
+ blob_appendf(&sql, " ORDER BY tbl_name, type<>'table', name");
407
+ db_prepare(&q, "%s", blob_str(&sql)/*safe-for-%s*/);
408
+ blob_reset(&sql);
400409
@ <pre>
401410
while( db_step(&q)==SQLITE_ROW ){
402411
@ %h(db_column_text(&q, 0));
403412
}
404413
@ </pre>
405414
db_finalize(&q);
415
+ if( db_table_exists("repository","sqlite_stat1") ){
416
+ if( zArg ){
417
+ db_prepare(&q,
418
+ "SELECT tbl, idx, stat FROM repository.sqlite_stat1"
419
+ " WHERE tbl LIKE %Q OR idx LIKE %Q"
420
+ " ORDER BY tbl, idx", zArg, zArg);
421
+
422
+ @ <hr>
423
+ @ <pre>
424
+ while( db_step(&q)==SQLITE_ROW ){
425
+ const char *zTab = db_column_text(&q,0);
426
+ const char *zIdx = db_column_text(&q,1);
427
+ const char *zStat = db_column_text(&q,2);
428
+ @ INSERT INTO sqlite_stat1 VALUES('%h(zTab)','%h(zIdx)','%h(zStat)');
429
+ }
430
+ @ </pre>
431
+ db_finalize(&q);
432
+ }else{
433
+ style_submenu_element("Stat1","repo_stat1");
434
+ }
435
+ }
436
+ style_footer();
437
+}
438
+
439
+/*
440
+** WEBPAGE: repo_stat1
441
+**
442
+** Show the sqlite_stat1 table for the repository schema
443
+*/
444
+void repo_stat1_page(void){
445
+ login_check_credentials();
446
+ if( !g.perm.Admin ){ login_needed(0); return; }
447
+
448
+ style_header("Repository STAT1 Table");
449
+ style_adunit_config(ADUNIT_RIGHT_OK);
450
+ style_submenu_element("Stat", "stat");
451
+ style_submenu_element("Schema", "repo_schema");
452
+ if( db_table_exists("repository","sqlite_stat1") ){
453
+ Stmt q;
454
+ db_prepare(&q,
455
+ "SELECT tbl, idx, stat FROM repository.sqlite_stat1"
456
+ " ORDER BY tbl, idx");
457
+ @ <pre>
458
+ while( db_step(&q)==SQLITE_ROW ){
459
+ const char *zTab = db_column_text(&q,0);
460
+ const char *zIdx = db_column_text(&q,1);
461
+ const char *zStat = db_column_text(&q,2);
462
+ char *zUrl = href("%R/repo_schema?n=%t",zTab);
463
+ @ INSERT INTO sqlite_stat1 VALUES('%z(zUrl)%h(zTab)</a>','%h(zIdx)','%h(zStat)');
464
+ }
465
+ @ </pre>
466
+ db_finalize(&q);
467
+ }
406468
style_footer();
407469
}
408470
409471
/*
410472
** WEBPAGE: repo-tabsize
411473
--- src/stat.c
+++ src/stat.c
@@ -383,10 +383,12 @@
383 **
384 ** Show the repository schema
385 */
386 void repo_schema_page(void){
387 Stmt q;
 
 
388 login_check_credentials();
389 if( !g.perm.Admin ){ login_needed(0); return; }
390
391 style_header("Repository Schema");
392 style_adunit_config(ADUNIT_RIGHT_OK);
@@ -393,18 +395,78 @@
393 style_submenu_element("Stat", "stat");
394 style_submenu_element("URLs", "urllist");
395 if( sqlite3_compileoption_used("ENABLE_DBSTAT_VTAB") ){
396 style_submenu_element("Table Sizes", "repo-tabsize");
397 }
398 db_prepare(&q,
399 "SELECT sql FROM repository.sqlite_master WHERE sql IS NOT NULL");
 
 
 
 
 
 
 
400 @ <pre>
401 while( db_step(&q)==SQLITE_ROW ){
402 @ %h(db_column_text(&q, 0));
403 }
404 @ </pre>
405 db_finalize(&q);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406 style_footer();
407 }
408
409 /*
410 ** WEBPAGE: repo-tabsize
411
--- src/stat.c
+++ src/stat.c
@@ -383,10 +383,12 @@
383 **
384 ** Show the repository schema
385 */
386 void repo_schema_page(void){
387 Stmt q;
388 Blob sql;
389 const char *zArg = P("n");
390 login_check_credentials();
391 if( !g.perm.Admin ){ login_needed(0); return; }
392
393 style_header("Repository Schema");
394 style_adunit_config(ADUNIT_RIGHT_OK);
@@ -393,18 +395,78 @@
395 style_submenu_element("Stat", "stat");
396 style_submenu_element("URLs", "urllist");
397 if( sqlite3_compileoption_used("ENABLE_DBSTAT_VTAB") ){
398 style_submenu_element("Table Sizes", "repo-tabsize");
399 }
400 blob_init(&sql,
401 "SELECT sql FROM repository.sqlite_master WHERE sql IS NOT NULL", -1);
402 if( zArg ){
403 style_submenu_element("All", "repo_schema");
404 blob_appendf(&sql, " AND (tbl_name=%Q OR name=%Q)", zArg, zArg);
405 }
406 blob_appendf(&sql, " ORDER BY tbl_name, type<>'table', name");
407 db_prepare(&q, "%s", blob_str(&sql)/*safe-for-%s*/);
408 blob_reset(&sql);
409 @ <pre>
410 while( db_step(&q)==SQLITE_ROW ){
411 @ %h(db_column_text(&q, 0));
412 }
413 @ </pre>
414 db_finalize(&q);
415 if( db_table_exists("repository","sqlite_stat1") ){
416 if( zArg ){
417 db_prepare(&q,
418 "SELECT tbl, idx, stat FROM repository.sqlite_stat1"
419 " WHERE tbl LIKE %Q OR idx LIKE %Q"
420 " ORDER BY tbl, idx", zArg, zArg);
421
422 @ <hr>
423 @ <pre>
424 while( db_step(&q)==SQLITE_ROW ){
425 const char *zTab = db_column_text(&q,0);
426 const char *zIdx = db_column_text(&q,1);
427 const char *zStat = db_column_text(&q,2);
428 @ INSERT INTO sqlite_stat1 VALUES('%h(zTab)','%h(zIdx)','%h(zStat)');
429 }
430 @ </pre>
431 db_finalize(&q);
432 }else{
433 style_submenu_element("Stat1","repo_stat1");
434 }
435 }
436 style_footer();
437 }
438
439 /*
440 ** WEBPAGE: repo_stat1
441 **
442 ** Show the sqlite_stat1 table for the repository schema
443 */
444 void repo_stat1_page(void){
445 login_check_credentials();
446 if( !g.perm.Admin ){ login_needed(0); return; }
447
448 style_header("Repository STAT1 Table");
449 style_adunit_config(ADUNIT_RIGHT_OK);
450 style_submenu_element("Stat", "stat");
451 style_submenu_element("Schema", "repo_schema");
452 if( db_table_exists("repository","sqlite_stat1") ){
453 Stmt q;
454 db_prepare(&q,
455 "SELECT tbl, idx, stat FROM repository.sqlite_stat1"
456 " ORDER BY tbl, idx");
457 @ <pre>
458 while( db_step(&q)==SQLITE_ROW ){
459 const char *zTab = db_column_text(&q,0);
460 const char *zIdx = db_column_text(&q,1);
461 const char *zStat = db_column_text(&q,2);
462 char *zUrl = href("%R/repo_schema?n=%t",zTab);
463 @ INSERT INTO sqlite_stat1 VALUES('%z(zUrl)%h(zTab)</a>','%h(zIdx)','%h(zStat)');
464 }
465 @ </pre>
466 db_finalize(&q);
467 }
468 style_footer();
469 }
470
471 /*
472 ** WEBPAGE: repo-tabsize
473

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button