/ Check-in [3076a890]
Login

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

Overview
Comment:Enhance the table_info pragma so that the pk column shows the order of the columns in a multi-column primary key.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3076a89015071e9b40e728bd55160e3a6ed98820
User & Date: drh 2013-01-01 13:55:31
Context
2013-01-01
14:01
Reduce the size of the Index object (by 8 bytes on x64). check-in: 5a2ac944 user: drh tags: trunk
13:55
Enhance the table_info pragma so that the pk column shows the order of the columns in a multi-column primary key. check-in: 3076a890 user: drh tags: trunk
2012-12-31
20:16
More test cases for the REGEXP operator. Fix minor bugs uncovered by these test cases. check-in: a611c750 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pragma.c.

   944    944     ** dflt_value: The default value for the column, if any.
   945    945     */
   946    946     if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){
   947    947       Table *pTab;
   948    948       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   949    949       pTab = sqlite3FindTable(db, zRight, zDb);
   950    950       if( pTab ){
   951         -      int i;
          951  +      int i, k;
   952    952         int nHidden = 0;
   953    953         Column *pCol;
          954  +      Index *pPk;
          955  +      for(pPk=pTab->pIndex; pPk && pPk->autoIndex!=2; pPk=pPk->pNext){}
   954    956         sqlite3VdbeSetNumCols(v, 6);
   955    957         pParse->nMem = 6;
   956    958         sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
   957    959         sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
   958    960         sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC);
   959    961         sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", SQLITE_STATIC);
   960    962         sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", SQLITE_STATIC);
................................................................................
   971    973              pCol->zType ? pCol->zType : "", 0);
   972    974           sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4);
   973    975           if( pCol->zDflt ){
   974    976             sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0);
   975    977           }else{
   976    978             sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
   977    979           }
   978         -        sqlite3VdbeAddOp2(v, OP_Integer,
   979         -                            (pCol->colFlags&COLFLAG_PRIMKEY)!=0, 6);
          980  +        if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
          981  +          k = 0;
          982  +        }else if( pPk==0 ){
          983  +          k = 1;
          984  +        }else{
          985  +          for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){}
          986  +        }
          987  +        sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
   980    988           sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
   981    989         }
   982    990       }
   983    991     }else
   984    992   
   985    993     if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){
   986    994       Index *pIdx;

Changes to test/pragma.test.

   530    530   do_test pragma-6.2.2 {
   531    531     execsql {
   532    532       CREATE TABLE t5(
   533    533         a TEXT DEFAULT CURRENT_TIMESTAMP, 
   534    534         b DEFAULT (5+3),
   535    535         c TEXT,
   536    536         d INTEGER DEFAULT NULL,
   537         -      e TEXT DEFAULT ''
          537  +      e TEXT DEFAULT '',
          538  +      UNIQUE(b,c,d),
          539  +      PRIMARY KEY(e,b,c)
   538    540       );
   539    541       PRAGMA table_info(t5);
   540    542     }
   541         -} {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 0 2 c TEXT 0 <<NULL>> 0 3 d INTEGER 0 NULL 0 4 e TEXT 0 '' 0}
          543  +} {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 2 2 c TEXT 0 <<NULL>> 3 3 d INTEGER 0 NULL 0 4 e TEXT 0 '' 1}
   542    544   db nullvalue {}
          545  +do_test pragma-6.2.3 {
          546  +  execsql {
          547  +    CREATE TABLE t2_3(a,b INTEGER PRIMARY KEY,c);
          548  +    pragma table_info(t2_3)
          549  +  }
          550  +} {0 a {} 0 {} 0 1 b INTEGER 0 {} 1 2 c {} 0 {} 0}
   543    551   ifcapable {foreignkey} {
   544    552     do_test pragma-6.3.1 {
   545    553       execsql {
   546    554         CREATE TABLE t3(a int references t2(b), b UNIQUE);
   547    555         pragma foreign_key_list(t3);
   548    556       }
   549    557     } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE}
................................................................................
  1615   1623     execsql { PRAGMA main.integrity_check; }
  1616   1624   } [list $mainerr]
  1617   1625   do_test 22.4.3 {
  1618   1626     execsql { PRAGMA aux.integrity_check; }
  1619   1627   } {ok}
  1620   1628   
  1621   1629   finish_test
  1622         -
  1623         -