/ Check-in [7b053d69]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Bring the documentation and implementation of sqlite3_uri_boolean() into closer agreement. Ticket [5f41597f7c9c]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7b053d699ffa1da9c50f1a19edb052c0f014058a
User & Date: drh 2012-01-30 18:40:55
Context
2012-01-31
05:11
Change a comment in test script backup.test. check-in: 313546b4 user: dan tags: trunk
2012-01-30
18:40
Bring the documentation and implementation of sqlite3_uri_boolean() into closer agreement. Ticket [5f41597f7c9c] check-in: 7b053d69 user: drh tags: trunk
18:00
Fix compiler warnings in the TCL test harness. check-in: c4cd38a0 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pragma.c.

    12     12   ** This file contains code used to implement the PRAGMA command.
    13     13   */
    14     14   #include "sqliteInt.h"
    15     15   
    16     16   /*
    17     17   ** Interpret the given string as a safety level.  Return 0 for OFF,
    18     18   ** 1 for ON or NORMAL and 2 for FULL.  Return 1 for an empty or 
    19         -** unrecognized string argument.
           19  +** unrecognized string argument.  The FULL option is disallowed
           20  +** if the omitFull parameter it 1.
    20     21   **
    21     22   ** Note that the values returned are one less that the values that
    22     23   ** should be passed into sqlite3BtreeSetSafetyLevel().  The is done
    23     24   ** to support legacy SQL code.  The safety level used to be boolean
    24     25   ** and older scripts may have used numbers 0 for OFF and 1 for ON.
    25     26   */
    26         -static u8 getSafetyLevel(const char *z){
           27  +static u8 getSafetyLevel(const char *z, int omitFull, int dflt){
    27     28                                /* 123456789 123456789 */
    28     29     static const char zText[] = "onoffalseyestruefull";
    29     30     static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16};
    30     31     static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4};
    31     32     static const u8 iValue[] =  {1, 0, 0, 0, 1, 1, 2};
    32     33     int i, n;
    33     34     if( sqlite3Isdigit(*z) ){
    34     35       return (u8)sqlite3Atoi(z);
    35     36     }
    36     37     n = sqlite3Strlen30(z);
    37         -  for(i=0; i<ArraySize(iLength); i++){
           38  +  for(i=0; i<ArraySize(iLength)-omitFull; i++){
    38     39       if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){
    39     40         return iValue[i];
    40     41       }
    41     42     }
    42         -  return 1;
           43  +  return dflt;
    43     44   }
    44     45   
    45     46   /*
    46     47   ** Interpret the given string as a boolean value.
    47     48   */
    48     49   u8 sqlite3GetBoolean(const char *z){
    49         -  return getSafetyLevel(z)&1;
           50  +  return getSafetyLevel(z,1,0)!=0;
    50     51   }
    51     52   
    52     53   /* The sqlite3GetBoolean() function is used by other modules but the
    53     54   ** remainder of this file is specific to PRAGMA processing.  So omit
    54     55   ** the rest of the file if PRAGMAs are omitted from the build.
    55     56   */
    56     57   #if !defined(SQLITE_OMIT_PRAGMA)
................................................................................
   837    838       if( !zRight ){
   838    839         returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
   839    840       }else{
   840    841         if( !db->autoCommit ){
   841    842           sqlite3ErrorMsg(pParse, 
   842    843               "Safety level may not be changed inside a transaction");
   843    844         }else{
   844         -        pDb->safety_level = getSafetyLevel(zRight)+1;
          845  +        pDb->safety_level = getSafetyLevel(zRight,0,1)+1;
   845    846         }
   846    847       }
   847    848     }else
   848    849   #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
   849    850   
   850    851   #ifndef SQLITE_OMIT_FLAG_PRAGMAS
   851    852     if( flagPragma(pParse, zLeft, zRight) ){

Changes to src/sqlite.h.in.

  2634   2634   ** sqlite3_uri_parameter(F,P) returns the value of the P
  2635   2635   ** parameter if it exists or a NULL pointer if P does not appear as a 
  2636   2636   ** query parameter on F.  If P is a query parameter of F
  2637   2637   ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
  2638   2638   ** a pointer to an empty string.
  2639   2639   **
  2640   2640   ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
  2641         -** parameter and returns true (1) or false (0) according to the value
  2642         -** of P.  The value of P is true if it is "yes" or "true" or "on" or 
  2643         -** a non-zero number and is false otherwise.  If P is not a query parameter
  2644         -** on F then sqlite3_uri_boolean(F,P,B) returns (B!=0).
         2641  +** parameter and returns true (non-zero) or false (0) according to the value
         2642  +** of P.  The value of P is true if it is "yes" or "true" or "on"
         2643  +** or if value of P begins with a non-zero number. If P is not a query
         2644  +** parameter on F then sqlite3_uri_boolean(F,P,B) returns (B!=0).
  2645   2645   **
  2646   2646   ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
  2647   2647   ** 64-bit signed integer and returns that integer, or D if P does not
  2648   2648   ** exist.  If the value of P is something other than an integer, then
  2649   2649   ** zero is returned.
  2650   2650   ** 
  2651   2651   ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and