/ Check-in [defa0515]
Login

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

Overview
Comment:Add the "PRAGMA table_xinfo" command that works like table_info but also shows hidden columns in virtual tables and adds the "hidden" boolean column.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: defa0515b8fd50ed9be699542f8c6695dd4a60c02f310665db6657ec5b6b67d0
User & Date: drh 2018-10-01 21:41:15
Context
2018-10-02
19:36
Fix comments and refactor some names associated with shared-memory locking in the Unix VFS. No logical changes. check-in: 3e9f1635 user: drh tags: trunk
2018-10-01
21:41
Add the "PRAGMA table_xinfo" command that works like table_info but also shows hidden columns in virtual tables and adds the "hidden" boolean column. check-in: defa0515 user: drh tags: trunk
21:36
Test case for PRAGMA table_xinfo. Closed-Leaf check-in: 7694b9bc user: drh tags: pragma-table-vinfo
17:33
Speed up xAccess() calls made on an RBU VFS when there are lots of open connections. check-in: 310b4b65 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pragma.c.

  1086   1086       Table *pTab;
  1087   1087       pTab = sqlite3LocateTable(pParse, LOCATE_NOERR, zRight, zDb);
  1088   1088       if( pTab ){
  1089   1089         int i, k;
  1090   1090         int nHidden = 0;
  1091   1091         Column *pCol;
  1092   1092         Index *pPk = sqlite3PrimaryKeyIndex(pTab);
  1093         -      pParse->nMem = 6;
         1093  +      pParse->nMem = 7;
  1094   1094         sqlite3CodeVerifySchema(pParse, iDb);
  1095   1095         sqlite3ViewGetColumnNames(pParse, pTab);
  1096   1096         for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
  1097         -        if( IsHiddenColumn(pCol) ){
         1097  +        int isHidden = IsHiddenColumn(pCol);
         1098  +        if( isHidden && pPragma->iArg==0 ){
  1098   1099             nHidden++;
  1099   1100             continue;
  1100   1101           }
  1101   1102           if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
  1102   1103             k = 0;
  1103   1104           }else if( pPk==0 ){
  1104   1105             k = 1;
  1105   1106           }else{
  1106   1107             for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
  1107   1108           }
  1108   1109           assert( pCol->pDflt==0 || pCol->pDflt->op==TK_SPAN );
  1109         -        sqlite3VdbeMultiLoad(v, 1, "issisi",
         1110  +        sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi",
  1110   1111                  i-nHidden,
  1111   1112                  pCol->zName,
  1112   1113                  sqlite3ColumnType(pCol,""),
  1113   1114                  pCol->notNull ? 1 : 0,
  1114   1115                  pCol->pDflt ? pCol->pDflt->u.zToken : 0,
  1115         -               k);
         1116  +               k,
         1117  +               isHidden);
  1116   1118         }
  1117   1119       }
  1118   1120     }
  1119   1121     break;
  1120   1122   
  1121   1123   #ifdef SQLITE_DEBUG
  1122   1124     case PragTyp_STATS: {

Changes to src/pragma.h.

    64     64   #define PragFlg_SchemaReq  0x80 /* Schema required - "main" is default */
    65     65   
    66     66   /* Names of columns for pragmas that return multi-column result
    67     67   ** or that return single-column results where the name of the
    68     68   ** result column is different from the name of the pragma
    69     69   */
    70     70   static const char *const pragCName[] = {
    71         -  /*   0 */ "cache_size",  /* Used by: default_cache_size */
    72         -  /*   1 */ "cid",         /* Used by: table_info */
    73         -  /*   2 */ "name",       
    74         -  /*   3 */ "type",       
    75         -  /*   4 */ "notnull",    
    76         -  /*   5 */ "dflt_value", 
    77         -  /*   6 */ "pk",         
    78         -  /*   7 */ "tbl",         /* Used by: stats */
    79         -  /*   8 */ "idx",        
    80         -  /*   9 */ "wdth",       
    81         -  /*  10 */ "hght",       
    82         -  /*  11 */ "flgs",       
    83         -  /*  12 */ "seqno",       /* Used by: index_info */
    84         -  /*  13 */ "cid",        
    85         -  /*  14 */ "name",       
           71  +  /*   0 */ "id",          /* Used by: foreign_key_list */
           72  +  /*   1 */ "seq",        
           73  +  /*   2 */ "table",      
           74  +  /*   3 */ "from",       
           75  +  /*   4 */ "to",         
           76  +  /*   5 */ "on_update",  
           77  +  /*   6 */ "on_delete",  
           78  +  /*   7 */ "match",      
           79  +  /*   8 */ "cid",         /* Used by: table_xinfo */
           80  +  /*   9 */ "name",       
           81  +  /*  10 */ "type",       
           82  +  /*  11 */ "notnull",    
           83  +  /*  12 */ "dflt_value", 
           84  +  /*  13 */ "pk",         
           85  +  /*  14 */ "hidden",     
           86  +                           /* table_info reuses 8 */
    86     87     /*  15 */ "seqno",       /* Used by: index_xinfo */
    87     88     /*  16 */ "cid",        
    88     89     /*  17 */ "name",       
    89     90     /*  18 */ "desc",       
    90     91     /*  19 */ "coll",       
    91     92     /*  20 */ "key",        
    92         -  /*  21 */ "seq",         /* Used by: index_list */
    93         -  /*  22 */ "name",       
    94         -  /*  23 */ "unique",     
    95         -  /*  24 */ "origin",     
    96         -  /*  25 */ "partial",    
    97         -  /*  26 */ "seq",         /* Used by: database_list */
           93  +  /*  21 */ "tbl",         /* Used by: stats */
           94  +  /*  22 */ "idx",        
           95  +  /*  23 */ "wdth",       
           96  +  /*  24 */ "hght",       
           97  +  /*  25 */ "flgs",       
           98  +  /*  26 */ "seq",         /* Used by: index_list */
    98     99     /*  27 */ "name",       
    99         -  /*  28 */ "file",       
   100         -  /*  29 */ "name",        /* Used by: function_list */
   101         -  /*  30 */ "builtin",    
   102         -  /*  31 */ "name",        /* Used by: module_list pragma_list */
   103         -  /*  32 */ "seq",         /* Used by: collation_list */
   104         -  /*  33 */ "name",       
   105         -  /*  34 */ "id",          /* Used by: foreign_key_list */
   106         -  /*  35 */ "seq",        
   107         -  /*  36 */ "table",      
   108         -  /*  37 */ "from",       
   109         -  /*  38 */ "to",         
   110         -  /*  39 */ "on_update",  
   111         -  /*  40 */ "on_delete",  
   112         -  /*  41 */ "match",      
   113         -  /*  42 */ "table",       /* Used by: foreign_key_check */
   114         -  /*  43 */ "rowid",      
   115         -  /*  44 */ "parent",     
   116         -  /*  45 */ "fkid",       
   117         -  /*  46 */ "busy",        /* Used by: wal_checkpoint */
   118         -  /*  47 */ "log",        
   119         -  /*  48 */ "checkpointed",
   120         -  /*  49 */ "timeout",     /* Used by: busy_timeout */
   121         -  /*  50 */ "database",    /* Used by: lock_status */
   122         -  /*  51 */ "status",     
          100  +  /*  28 */ "unique",     
          101  +  /*  29 */ "origin",     
          102  +  /*  30 */ "partial",    
          103  +  /*  31 */ "table",       /* Used by: foreign_key_check */
          104  +  /*  32 */ "rowid",      
          105  +  /*  33 */ "parent",     
          106  +  /*  34 */ "fkid",       
          107  +                           /* index_info reuses 15 */
          108  +  /*  35 */ "seq",         /* Used by: database_list */
          109  +  /*  36 */ "name",       
          110  +  /*  37 */ "file",       
          111  +  /*  38 */ "busy",        /* Used by: wal_checkpoint */
          112  +  /*  39 */ "log",        
          113  +  /*  40 */ "checkpointed",
          114  +  /*  41 */ "name",        /* Used by: function_list */
          115  +  /*  42 */ "builtin",    
          116  +                           /* collation_list reuses 26 */
          117  +  /*  43 */ "database",    /* Used by: lock_status */
          118  +  /*  44 */ "status",     
          119  +  /*  45 */ "cache_size",  /* Used by: default_cache_size */
          120  +                           /* module_list pragma_list reuses 9 */
          121  +  /*  46 */ "timeout",     /* Used by: busy_timeout */
   123    122   };
   124    123   
   125    124   /* Definitions of all built-in pragmas */
   126    125   typedef struct PragmaName {
   127    126     const char *const zName; /* Name of pragma */
   128    127     u8 ePragTyp;             /* PragTyp_XXX value */
   129    128     u8 mPragFlg;             /* Zero or more PragFlg_XXX values */
................................................................................
   161    160     /* ColNames:  */ 0, 0,
   162    161     /* iArg:      */ SQLITE_AutoIndex },
   163    162   #endif
   164    163   #endif
   165    164    {/* zName:     */ "busy_timeout",
   166    165     /* ePragTyp:  */ PragTyp_BUSY_TIMEOUT,
   167    166     /* ePragFlg:  */ PragFlg_Result0,
   168         -  /* ColNames:  */ 49, 1,
          167  +  /* ColNames:  */ 46, 1,
   169    168     /* iArg:      */ 0 },
   170    169   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   171    170    {/* zName:     */ "cache_size",
   172    171     /* ePragTyp:  */ PragTyp_CACHE_SIZE,
   173    172     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
   174    173     /* ColNames:  */ 0, 0,
   175    174     /* iArg:      */ 0 },
................................................................................
   198    197     /* ColNames:  */ 0, 0,
   199    198     /* iArg:      */ SQLITE_CkptFullFSync },
   200    199   #endif
   201    200   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   202    201    {/* zName:     */ "collation_list",
   203    202     /* ePragTyp:  */ PragTyp_COLLATION_LIST,
   204    203     /* ePragFlg:  */ PragFlg_Result0,
   205         -  /* ColNames:  */ 32, 2,
          204  +  /* ColNames:  */ 26, 2,
   206    205     /* iArg:      */ 0 },
   207    206   #endif
   208    207   #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
   209    208    {/* zName:     */ "compile_options",
   210    209     /* ePragTyp:  */ PragTyp_COMPILE_OPTIONS,
   211    210     /* ePragFlg:  */ PragFlg_Result0,
   212    211     /* ColNames:  */ 0, 0,
................................................................................
   233    232     /* ColNames:  */ 0, 0,
   234    233     /* iArg:      */ BTREE_DATA_VERSION },
   235    234   #endif
   236    235   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   237    236    {/* zName:     */ "database_list",
   238    237     /* ePragTyp:  */ PragTyp_DATABASE_LIST,
   239    238     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0,
   240         -  /* ColNames:  */ 26, 3,
          239  +  /* ColNames:  */ 35, 3,
   241    240     /* iArg:      */ 0 },
   242    241   #endif
   243    242   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
   244    243    {/* zName:     */ "default_cache_size",
   245    244     /* ePragTyp:  */ PragTyp_DEFAULT_CACHE_SIZE,
   246    245     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
   247         -  /* ColNames:  */ 0, 1,
          246  +  /* ColNames:  */ 45, 1,
   248    247     /* iArg:      */ 0 },
   249    248   #endif
   250    249   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   251    250   #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
   252    251    {/* zName:     */ "defer_foreign_keys",
   253    252     /* ePragTyp:  */ PragTyp_FLAG,
   254    253     /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
................................................................................
   270    269     /* ColNames:  */ 0, 0,
   271    270     /* iArg:      */ 0 },
   272    271   #endif
   273    272   #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
   274    273    {/* zName:     */ "foreign_key_check",
   275    274     /* ePragTyp:  */ PragTyp_FOREIGN_KEY_CHECK,
   276    275     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0,
   277         -  /* ColNames:  */ 42, 4,
          276  +  /* ColNames:  */ 31, 4,
   278    277     /* iArg:      */ 0 },
   279    278   #endif
   280    279   #if !defined(SQLITE_OMIT_FOREIGN_KEY)
   281    280    {/* zName:     */ "foreign_key_list",
   282    281     /* ePragTyp:  */ PragTyp_FOREIGN_KEY_LIST,
   283    282     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
   284         -  /* ColNames:  */ 34, 8,
          283  +  /* ColNames:  */ 0, 8,
   285    284     /* iArg:      */ 0 },
   286    285   #endif
   287    286   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   288    287   #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
   289    288    {/* zName:     */ "foreign_keys",
   290    289     /* ePragTyp:  */ PragTyp_FLAG,
   291    290     /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
................................................................................
   313    312     /* iArg:      */ SQLITE_FullFSync },
   314    313   #endif
   315    314   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   316    315   #if defined(SQLITE_INTROSPECTION_PRAGMAS)
   317    316    {/* zName:     */ "function_list",
   318    317     /* ePragTyp:  */ PragTyp_FUNCTION_LIST,
   319    318     /* ePragFlg:  */ PragFlg_Result0,
   320         -  /* ColNames:  */ 29, 2,
          319  +  /* ColNames:  */ 41, 2,
   321    320     /* iArg:      */ 0 },
   322    321   #endif
   323    322   #endif
   324    323   #if defined(SQLITE_HAS_CODEC)
   325    324    {/* zName:     */ "hexkey",
   326    325     /* ePragTyp:  */ PragTyp_HEXKEY,
   327    326     /* ePragFlg:  */ 0,
................................................................................
   349    348     /* ColNames:  */ 0, 0,
   350    349     /* iArg:      */ 0 },
   351    350   #endif
   352    351   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   353    352    {/* zName:     */ "index_info",
   354    353     /* ePragTyp:  */ PragTyp_INDEX_INFO,
   355    354     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
   356         -  /* ColNames:  */ 12, 3,
          355  +  /* ColNames:  */ 15, 3,
   357    356     /* iArg:      */ 0 },
   358    357    {/* zName:     */ "index_list",
   359    358     /* ePragTyp:  */ PragTyp_INDEX_LIST,
   360    359     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
   361         -  /* ColNames:  */ 21, 5,
          360  +  /* ColNames:  */ 26, 5,
   362    361     /* iArg:      */ 0 },
   363    362    {/* zName:     */ "index_xinfo",
   364    363     /* ePragTyp:  */ PragTyp_INDEX_INFO,
   365    364     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
   366    365     /* ColNames:  */ 15, 6,
   367    366     /* iArg:      */ 1 },
   368    367   #endif
................................................................................
   411    410     /* ColNames:  */ 0, 0,
   412    411     /* iArg:      */ 0 },
   413    412   #endif
   414    413   #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
   415    414    {/* zName:     */ "lock_status",
   416    415     /* ePragTyp:  */ PragTyp_LOCK_STATUS,
   417    416     /* ePragFlg:  */ PragFlg_Result0,
   418         -  /* ColNames:  */ 50, 2,
          417  +  /* ColNames:  */ 43, 2,
   419    418     /* iArg:      */ 0 },
   420    419   #endif
   421    420   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   422    421    {/* zName:     */ "locking_mode",
   423    422     /* ePragTyp:  */ PragTyp_LOCKING_MODE,
   424    423     /* ePragFlg:  */ PragFlg_Result0|PragFlg_SchemaReq,
   425    424     /* ColNames:  */ 0, 0,
................................................................................
   437    436   #endif
   438    437   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   439    438   #if !defined(SQLITE_OMIT_VIRTUALTABLE)
   440    439   #if defined(SQLITE_INTROSPECTION_PRAGMAS)
   441    440    {/* zName:     */ "module_list",
   442    441     /* ePragTyp:  */ PragTyp_MODULE_LIST,
   443    442     /* ePragFlg:  */ PragFlg_Result0,
   444         -  /* ColNames:  */ 31, 1,
          443  +  /* ColNames:  */ 9, 1,
   445    444     /* iArg:      */ 0 },
   446    445   #endif
   447    446   #endif
   448    447   #endif
   449    448    {/* zName:     */ "optimize",
   450    449     /* ePragTyp:  */ PragTyp_OPTIMIZE,
   451    450     /* ePragFlg:  */ PragFlg_Result1|PragFlg_NeedSchema,
................................................................................
   470    469     /* ColNames:  */ 0, 0,
   471    470     /* iArg:      */ 0 },
   472    471   #endif
   473    472   #if defined(SQLITE_INTROSPECTION_PRAGMAS)
   474    473    {/* zName:     */ "pragma_list",
   475    474     /* ePragTyp:  */ PragTyp_PRAGMA_LIST,
   476    475     /* ePragFlg:  */ PragFlg_Result0,
   477         -  /* ColNames:  */ 31, 1,
          476  +  /* ColNames:  */ 9, 1,
   478    477     /* iArg:      */ 0 },
   479    478   #endif
   480    479   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   481    480    {/* zName:     */ "query_only",
   482    481     /* ePragTyp:  */ PragTyp_FLAG,
   483    482     /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
   484    483     /* ColNames:  */ 0, 0,
................................................................................
   557    556     /* iArg:      */ SQLITE_SqlTrace },
   558    557   #endif
   559    558   #endif
   560    559   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG)
   561    560    {/* zName:     */ "stats",
   562    561     /* ePragTyp:  */ PragTyp_STATS,
   563    562     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
   564         -  /* ColNames:  */ 7, 5,
          563  +  /* ColNames:  */ 21, 5,
   565    564     /* iArg:      */ 0 },
   566    565   #endif
   567    566   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   568    567    {/* zName:     */ "synchronous",
   569    568     /* ePragTyp:  */ PragTyp_SYNCHRONOUS,
   570    569     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
   571    570     /* ColNames:  */ 0, 0,
   572    571     /* iArg:      */ 0 },
   573    572   #endif
   574    573   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   575    574    {/* zName:     */ "table_info",
   576    575     /* ePragTyp:  */ PragTyp_TABLE_INFO,
   577    576     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
   578         -  /* ColNames:  */ 1, 6,
          577  +  /* ColNames:  */ 8, 6,
   579    578     /* iArg:      */ 0 },
          579  + {/* zName:     */ "table_xinfo",
          580  +  /* ePragTyp:  */ PragTyp_TABLE_INFO,
          581  +  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
          582  +  /* ColNames:  */ 8, 7,
          583  +  /* iArg:      */ 1 },
   580    584   #endif
   581    585   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   582    586    {/* zName:     */ "temp_store",
   583    587     /* ePragTyp:  */ PragTyp_TEMP_STORE,
   584    588     /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
   585    589     /* ColNames:  */ 0, 0,
   586    590     /* iArg:      */ 0 },
................................................................................
   636    640     /* ePragTyp:  */ PragTyp_WAL_AUTOCHECKPOINT,
   637    641     /* ePragFlg:  */ 0,
   638    642     /* ColNames:  */ 0, 0,
   639    643     /* iArg:      */ 0 },
   640    644    {/* zName:     */ "wal_checkpoint",
   641    645     /* ePragTyp:  */ PragTyp_WAL_CHECKPOINT,
   642    646     /* ePragFlg:  */ PragFlg_NeedSchema,
   643         -  /* ColNames:  */ 46, 3,
          647  +  /* ColNames:  */ 38, 3,
   644    648     /* iArg:      */ 0 },
   645    649   #endif
   646    650   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   647    651    {/* zName:     */ "writable_schema",
   648    652     /* ePragTyp:  */ PragTyp_FLAG,
   649    653     /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
   650    654     /* ColNames:  */ 0, 0,
   651    655     /* iArg:      */ SQLITE_WriteSchema },
   652    656   #endif
   653    657   };
   654         -/* Number of pragmas: 61 on by default, 78 total. */
          658  +/* Number of pragmas: 62 on by default, 79 total. */

Changes to test/tabfunc01.test.

    24     24   load_static_extension db series
    25     25   load_static_extension db carray
    26     26   load_static_extension db remember
    27     27   
    28     28   do_execsql_test tabfunc01-1.1 {
    29     29     SELECT *, '|' FROM generate_series WHERE start=1 AND stop=9 AND step=2;
    30     30   } {1 | 3 | 5 | 7 | 9 |}
           31  +do_execsql_test tabfunc01-1.1b {
           32  +  PRAGMA table_xinfo(generate_series);
           33  +} {0 value {} 0 {} 0 0 1 start {} 0 {} 0 1 2 stop {} 0 {} 0 1 3 step {} 0 {} 0 1}
    31     34   do_execsql_test tabfunc01-1.2 {
    32     35     SELECT *, '|' FROM generate_series LIMIT 5;
    33     36   } {0 | 1 | 2 | 3 | 4 |}
    34     37   do_catchsql_test tabfunc01-1.3 {
    35     38     CREATE VIRTUAL TABLE t1 USING generate_series;
    36     39   } {1 {no such module: generate_series}}
    37     40   do_execsql_test tabfunc01-1.4 {

Changes to tool/mkpragmatab.tcl.

   216    216   
   217    217     NAME: synchronous
   218    218     FLAG: NeedSchema Result0 SchemaReq NoColumns1
   219    219     IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   220    220   
   221    221     NAME: table_info
   222    222     FLAG: NeedSchema Result1 SchemaOpt
          223  +  ARG:  0
   223    224     COLS: cid name type notnull dflt_value pk
   224    225     IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   225    226   
          227  +  NAME: table_xinfo
          228  +  TYPE: TABLE_INFO
          229  +  FLAG: NeedSchema Result1 SchemaOpt
          230  +  ARG:  1
          231  +  COLS: cid name type notnull dflt_value pk hidden
          232  +  IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
          233  +
   226    234     NAME: stats
   227    235     FLAG: NeedSchema Result0 SchemaReq
   228    236     COLS: tbl idx wdth hght flgs
   229    237     IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG)
   230    238   
   231    239     NAME: index_info
   232    240     TYPE: INDEX_INFO
................................................................................
   406    414   set type {}
   407    415   set if {}
   408    416   set flags {}
   409    417   set cols {}
   410    418   set cols_list {}
   411    419   set arg 0
   412    420   proc record_one {} {
   413         -  global name type if arg allbyname typebyif flags cols allcols
          421  +  global name type if arg allbyname typebyif flags cols all_cols
   414    422     global cols_list colUsedBy
   415    423     if {$name==""} return
   416    424     if {$cols!=""} {
   417         -    if {![info exists allcols($cols)]} {
          425  +    if {![info exists all_cols($cols)]} {
          426  +      set all_cols($cols) 1
   418    427         lappend cols_list $cols
   419         -      set allcols($cols) [llength $cols_list]
   420    428       }
   421         -    set cx $allcols($cols)
          429  +    set cx $cols
   422    430       lappend colUsedBy($cols) $name
   423    431     } else {
   424    432       set cx 0
   425    433     }
   426         -  set allbyname($name) [list $type $arg $if $flags $cx]
          434  +  set allbyname($name) [list $type $arg $if $flags $cols]
   427    435     set name {}
   428    436     set type {}
   429    437     set if {}
   430    438     set flags {}
   431    439     set cols {}
   432    440     set arg 0
   433    441   }
................................................................................
   500    508   puts $fd "\n/* Property flags associated with various pragma. */"
   501    509   set fv 1
   502    510   foreach f [lsort [array names allflags]] {
   503    511     puts $fd [format {#define PragFlg_%-10s 0x%02x /* %s */} \
   504    512                $f $fv $flagMeaning($f)]
   505    513     set fv [expr {$fv*2}]
   506    514   }
          515  +
          516  +# Sort the column lists so that longer column lists occur first
          517  +#
          518  +proc colscmp {a b} {
          519  +  return [expr {[llength $b] - [llength $a]}]
          520  +}
          521  +set cols_list [lsort -command colscmp $cols_list]
   507    522   
   508    523   # Generate the array of column names used by pragmas that act like
   509    524   # queries.
   510    525   #
   511    526   puts $fd "\n/* Names of columns for pragmas that return multi-column result"
   512    527   puts $fd "** or that return single-column results where the name of the"
   513    528   puts $fd "** result column is different from the name of the pragma\n*/"
   514    529   puts $fd "static const char *const pragCName\[\] = {"
   515    530   set offset 0
          531  +set allcollist {}
   516    532   foreach cols $cols_list {
   517         -  set cols_offset($allcols($cols)) $offset
          533  +  set n [llength $cols]
          534  +  set limit [expr {[llength $allcollist] - $n}]
          535  +  for {set i 0} {$i<$limit} {incr i} {
          536  +    set sublist [lrange $allcollist $i [expr {$i+$n-1}]]
          537  +    if {$sublist==$cols} {
          538  +      puts $fd [format "%27s/* $colUsedBy($cols) reuses $i */" ""]
          539  +      set cols_offset($cols) $i
          540  +      break
          541  +    }
          542  +  }
          543  +  if {$i<$limit} continue
          544  +  set cols_offset($cols) $offset
   518    545     set ub " /* Used by: $colUsedBy($cols) */"
   519    546     foreach c $cols {
          547  +    lappend allcollist $c
   520    548       puts $fd [format "  /* %3d */ %-14s%s" $offset \"$c\", $ub]
   521    549       set ub ""
   522    550       incr offset
   523    551     }
   524    552   }
   525    553   puts $fd "\175;"
   526    554   
................................................................................
   538    566   puts $fd "\175 PragmaName;"
   539    567   puts $fd "static const PragmaName aPragmaName\[\] = \173"
   540    568   
   541    569   set current_if {}
   542    570   set spacer [format {    %26s } {}]
   543    571   foreach name $allnames {
   544    572     foreach {type arg if flag cx} $allbyname($name) break
   545         -  if {$cx==0} {
          573  +  if {$cx==0 || $cx==""} {
   546    574       set cy 0
   547    575       set nx 0
   548    576     } else {
   549    577       set cy $cols_offset($cx)
   550         -    set nx [llength [lindex $cols_list [expr {$cx-1}]]]
          578  +    set nx [llength $cx]
   551    579     }
   552    580     if {$if!=$current_if} {
   553    581       if {$current_if!=""} {
   554    582         foreach this_if $current_if {
   555    583           puts $fd "#endif"
   556    584         }
   557    585       }