Fossil SCM

When rendering SQLite log messages to the error log, include the SQL for all busy SQL statements in the log message.

drh 2018-07-13 16:06 trunk
Commit c6ecf21f37a809151d93f5d1384706f899bcca53ba0cf6e6632410f77ded0a95
1 file changed +26 -4
+26 -4
--- src/main.c
+++ src/main.c
@@ -509,13 +509,15 @@
509509
return zCode;
510510
}
511511
512512
/* Error logs from SQLite */
513513
static void fossil_sqlite_log(void *notUsed, int iCode, const char *zErrmsg){
514
+ sqlite3_stmt *p;
515
+ Blob msg;
514516
#ifdef __APPLE__
515517
/* Disable the file alias warning on apple products because Time Machine
516
- ** creates lots of aliases and the warning alarms people. */
518
+ ** creates lots of aliases and the warnings alarm people. */
517519
if( iCode==SQLITE_WARNING ) return;
518520
#endif
519521
#ifndef FOSSIL_DEBUG
520522
/* Disable the automatic index warning except in FOSSIL_DEBUG builds. */
521523
if( iCode==SQLITE_WARNING_AUTOINDEX ) return;
@@ -525,11 +527,23 @@
525527
#ifdef SQLITE_READONLY_DIRECTORY
526528
if( iCode==SQLITE_READONLY_DIRECTORY ){
527529
zErrmsg = "database is in a read-only directory";
528530
}
529531
#endif
530
- fossil_warning("%s: %s", fossil_sqlite_return_code_name(iCode), zErrmsg);
532
+ blob_init(&msg, 0, 0);
533
+ blob_appendf(&msg, "%s: %s", fossil_sqlite_return_code_name(iCode), zErrmsg);
534
+ if( g.db ){
535
+ for(p=sqlite3_next_stmt(g.db, 0); p; p=sqlite3_next_stmt(g.db,p)){
536
+ const char *zSql;
537
+ if( !sqlite3_stmt_busy(p) ) continue;
538
+ zSql = sqlite3_sql(p);
539
+ if( zSql==0 ) continue;
540
+ blob_appendf(&msg, "\nSQL: %s", zSql);
541
+ }
542
+ }
543
+ fossil_warning("%s", blob_str(&msg));
544
+ blob_reset(&msg);
531545
}
532546
533547
/*
534548
** This function attempts to find command line options known to contain
535549
** bitwise flags and initializes the associated global variables. After
@@ -2745,17 +2759,17 @@
27452759
login_needed(0);
27462760
return;
27472761
}
27482762
style_header("Warning Test Page");
27492763
style_submenu_element("Error Log","%R/errorlog");
2750
- if( iCase<1 || iCase>3 ){
2764
+ if( iCase<1 || iCase>4 ){
27512765
@ <p>Generate a message to the <a href="%R/errorlog">error log</a>
27522766
@ by clicking on one of the following cases:
27532767
}else{
27542768
@ <p>This is the test page for case=%d(iCase). All possible cases:
27552769
}
2756
- for(i=1; i<=3; i++){
2770
+ for(i=1; i<=4; i++){
27572771
@ <a href='./test-warning?case=%d(i)'>[%d(i)]</a>
27582772
}
27592773
@ </p>
27602774
@ <p><ol>
27612775
@ <li value='1'> Call fossil_warning()
@@ -2767,10 +2781,18 @@
27672781
db_begin_transaction();
27682782
}
27692783
@ <li value='3'> Call db_end_transaction()
27702784
if( iCase==3 ){
27712785
db_end_transaction(0);
2786
+ }
2787
+ @ <li value='4'> warning during SQL
2788
+ if( iCase==4 ){
2789
+ Stmt q;
2790
+ db_prepare(&q, "SELECT uuid FROM blob LIMIT 5");
2791
+ db_step(&q);
2792
+ sqlite3_log(SQLITE_ERROR, "Test warning message during SQL");
2793
+ db_finalize(&q);
27722794
}
27732795
@ </ol>
27742796
@ <p>End of test</p>
27752797
style_footer();
27762798
}
27772799
--- src/main.c
+++ src/main.c
@@ -509,13 +509,15 @@
509 return zCode;
510 }
511
512 /* Error logs from SQLite */
513 static void fossil_sqlite_log(void *notUsed, int iCode, const char *zErrmsg){
 
 
514 #ifdef __APPLE__
515 /* Disable the file alias warning on apple products because Time Machine
516 ** creates lots of aliases and the warning alarms people. */
517 if( iCode==SQLITE_WARNING ) return;
518 #endif
519 #ifndef FOSSIL_DEBUG
520 /* Disable the automatic index warning except in FOSSIL_DEBUG builds. */
521 if( iCode==SQLITE_WARNING_AUTOINDEX ) return;
@@ -525,11 +527,23 @@
525 #ifdef SQLITE_READONLY_DIRECTORY
526 if( iCode==SQLITE_READONLY_DIRECTORY ){
527 zErrmsg = "database is in a read-only directory";
528 }
529 #endif
530 fossil_warning("%s: %s", fossil_sqlite_return_code_name(iCode), zErrmsg);
 
 
 
 
 
 
 
 
 
 
 
 
531 }
532
533 /*
534 ** This function attempts to find command line options known to contain
535 ** bitwise flags and initializes the associated global variables. After
@@ -2745,17 +2759,17 @@
2745 login_needed(0);
2746 return;
2747 }
2748 style_header("Warning Test Page");
2749 style_submenu_element("Error Log","%R/errorlog");
2750 if( iCase<1 || iCase>3 ){
2751 @ <p>Generate a message to the <a href="%R/errorlog">error log</a>
2752 @ by clicking on one of the following cases:
2753 }else{
2754 @ <p>This is the test page for case=%d(iCase). All possible cases:
2755 }
2756 for(i=1; i<=3; i++){
2757 @ <a href='./test-warning?case=%d(i)'>[%d(i)]</a>
2758 }
2759 @ </p>
2760 @ <p><ol>
2761 @ <li value='1'> Call fossil_warning()
@@ -2767,10 +2781,18 @@
2767 db_begin_transaction();
2768 }
2769 @ <li value='3'> Call db_end_transaction()
2770 if( iCase==3 ){
2771 db_end_transaction(0);
 
 
 
 
 
 
 
 
2772 }
2773 @ </ol>
2774 @ <p>End of test</p>
2775 style_footer();
2776 }
2777
--- src/main.c
+++ src/main.c
@@ -509,13 +509,15 @@
509 return zCode;
510 }
511
512 /* Error logs from SQLite */
513 static void fossil_sqlite_log(void *notUsed, int iCode, const char *zErrmsg){
514 sqlite3_stmt *p;
515 Blob msg;
516 #ifdef __APPLE__
517 /* Disable the file alias warning on apple products because Time Machine
518 ** creates lots of aliases and the warnings alarm people. */
519 if( iCode==SQLITE_WARNING ) return;
520 #endif
521 #ifndef FOSSIL_DEBUG
522 /* Disable the automatic index warning except in FOSSIL_DEBUG builds. */
523 if( iCode==SQLITE_WARNING_AUTOINDEX ) return;
@@ -525,11 +527,23 @@
527 #ifdef SQLITE_READONLY_DIRECTORY
528 if( iCode==SQLITE_READONLY_DIRECTORY ){
529 zErrmsg = "database is in a read-only directory";
530 }
531 #endif
532 blob_init(&msg, 0, 0);
533 blob_appendf(&msg, "%s: %s", fossil_sqlite_return_code_name(iCode), zErrmsg);
534 if( g.db ){
535 for(p=sqlite3_next_stmt(g.db, 0); p; p=sqlite3_next_stmt(g.db,p)){
536 const char *zSql;
537 if( !sqlite3_stmt_busy(p) ) continue;
538 zSql = sqlite3_sql(p);
539 if( zSql==0 ) continue;
540 blob_appendf(&msg, "\nSQL: %s", zSql);
541 }
542 }
543 fossil_warning("%s", blob_str(&msg));
544 blob_reset(&msg);
545 }
546
547 /*
548 ** This function attempts to find command line options known to contain
549 ** bitwise flags and initializes the associated global variables. After
@@ -2745,17 +2759,17 @@
2759 login_needed(0);
2760 return;
2761 }
2762 style_header("Warning Test Page");
2763 style_submenu_element("Error Log","%R/errorlog");
2764 if( iCase<1 || iCase>4 ){
2765 @ <p>Generate a message to the <a href="%R/errorlog">error log</a>
2766 @ by clicking on one of the following cases:
2767 }else{
2768 @ <p>This is the test page for case=%d(iCase). All possible cases:
2769 }
2770 for(i=1; i<=4; i++){
2771 @ <a href='./test-warning?case=%d(i)'>[%d(i)]</a>
2772 }
2773 @ </p>
2774 @ <p><ol>
2775 @ <li value='1'> Call fossil_warning()
@@ -2767,10 +2781,18 @@
2781 db_begin_transaction();
2782 }
2783 @ <li value='3'> Call db_end_transaction()
2784 if( iCase==3 ){
2785 db_end_transaction(0);
2786 }
2787 @ <li value='4'> warning during SQL
2788 if( iCase==4 ){
2789 Stmt q;
2790 db_prepare(&q, "SELECT uuid FROM blob LIMIT 5");
2791 db_step(&q);
2792 sqlite3_log(SQLITE_ERROR, "Test warning message during SQL");
2793 db_finalize(&q);
2794 }
2795 @ </ol>
2796 @ <p>End of test</p>
2797 style_footer();
2798 }
2799

Keyboard Shortcuts

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