Fossil SCM
When rendering SQLite log messages to the error log, include the SQL for all busy SQL statements in the log message.
Commit
c6ecf21f37a809151d93f5d1384706f899bcca53ba0cf6e6632410f77ded0a95
Parent
264223fc5981cd2…
1 file changed
+26
-4
+26
-4
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -509,13 +509,15 @@ | ||
| 509 | 509 | return zCode; |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /* Error logs from SQLite */ |
| 513 | 513 | static void fossil_sqlite_log(void *notUsed, int iCode, const char *zErrmsg){ |
| 514 | + sqlite3_stmt *p; | |
| 515 | + Blob msg; | |
| 514 | 516 | #ifdef __APPLE__ |
| 515 | 517 | /* 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. */ | |
| 517 | 519 | if( iCode==SQLITE_WARNING ) return; |
| 518 | 520 | #endif |
| 519 | 521 | #ifndef FOSSIL_DEBUG |
| 520 | 522 | /* Disable the automatic index warning except in FOSSIL_DEBUG builds. */ |
| 521 | 523 | if( iCode==SQLITE_WARNING_AUTOINDEX ) return; |
| @@ -525,11 +527,23 @@ | ||
| 525 | 527 | #ifdef SQLITE_READONLY_DIRECTORY |
| 526 | 528 | if( iCode==SQLITE_READONLY_DIRECTORY ){ |
| 527 | 529 | zErrmsg = "database is in a read-only directory"; |
| 528 | 530 | } |
| 529 | 531 | #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); | |
| 531 | 545 | } |
| 532 | 546 | |
| 533 | 547 | /* |
| 534 | 548 | ** This function attempts to find command line options known to contain |
| 535 | 549 | ** bitwise flags and initializes the associated global variables. After |
| @@ -2745,17 +2759,17 @@ | ||
| 2745 | 2759 | login_needed(0); |
| 2746 | 2760 | return; |
| 2747 | 2761 | } |
| 2748 | 2762 | style_header("Warning Test Page"); |
| 2749 | 2763 | style_submenu_element("Error Log","%R/errorlog"); |
| 2750 | - if( iCase<1 || iCase>3 ){ | |
| 2764 | + if( iCase<1 || iCase>4 ){ | |
| 2751 | 2765 | @ <p>Generate a message to the <a href="%R/errorlog">error log</a> |
| 2752 | 2766 | @ by clicking on one of the following cases: |
| 2753 | 2767 | }else{ |
| 2754 | 2768 | @ <p>This is the test page for case=%d(iCase). All possible cases: |
| 2755 | 2769 | } |
| 2756 | - for(i=1; i<=3; i++){ | |
| 2770 | + for(i=1; i<=4; i++){ | |
| 2757 | 2771 | @ <a href='./test-warning?case=%d(i)'>[%d(i)]</a> |
| 2758 | 2772 | } |
| 2759 | 2773 | @ </p> |
| 2760 | 2774 | @ <p><ol> |
| 2761 | 2775 | @ <li value='1'> Call fossil_warning() |
| @@ -2767,10 +2781,18 @@ | ||
| 2767 | 2781 | db_begin_transaction(); |
| 2768 | 2782 | } |
| 2769 | 2783 | @ <li value='3'> Call db_end_transaction() |
| 2770 | 2784 | if( iCase==3 ){ |
| 2771 | 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); | |
| 2772 | 2794 | } |
| 2773 | 2795 | @ </ol> |
| 2774 | 2796 | @ <p>End of test</p> |
| 2775 | 2797 | style_footer(); |
| 2776 | 2798 | } |
| 2777 | 2799 |
| --- 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 |