Patch to add Affinity and Collation to table_info pragma's

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Patch to add Affinity and Collation to table_info pragma's

Keith Medcalf

Your line numbers may be different as I have also added a database_info pragma that returns schema, type, name for all attached databases.

Index: src/pragma.c
==================================================================
--- src/pragma.c
+++ src/pragma.c
@@ -1081,28 +1081,34 @@
   ** the returned data set are:
   **
   ** cid:        Column id (numbered from left to right, starting at 0)
   ** name:       Column name
   ** type:       Column declaration type.
+  ** aff:        Column affinity
+  ** coll:       Column collation
   ** notnull:    True if 'NOT NULL' is part of column declaration
   ** dflt_value: The default value for the column, if any.
   ** pk:         Non-zero for PK fields.
   */
   case PragTyp_TABLE_INFO: if( zRight ){
     Table *pTab;
+    char *affinity[] = {"NONE", "BLOB", "TEXT", "NUMERIC", "INTEGER", "REAL"};
     pTab = sqlite3LocateTable(pParse, LOCATE_NOERR, zRight, zDb);
     if( pTab ){
       int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
       int i, k;
       int nHidden = 0;
       Column *pCol;
       Index *pPk = sqlite3PrimaryKeyIndex(pTab);
-      pParse->nMem = 7;
+      pParse->nMem = 9;
       sqlite3CodeVerifySchema(pParse, iTabDb);
       sqlite3ViewGetColumnNames(pParse, pTab);
       for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
         int isHidden = IsHiddenColumn(pCol);
+        int affcode = (int)(pCol->affinity - SQLITE_AFF_NONE);
+        if ((affcode < 0) || (affcode > 5))
+            affcode = 0;
         if( isHidden && pPragma->iArg==0 ){
           nHidden++;
           continue;
         }
         if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
@@ -1111,14 +1117,16 @@
           k = 1;
         }else{
           for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
         }
         assert( pCol->pDflt==0 || pCol->pDflt->op==TK_SPAN );
-        sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi",
+        sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issssisii" : "issssisi",
                i-nHidden,
                pCol->zName,
                sqlite3ColumnType(pCol,""),
+               affinity[affcode],
+               pCol->zColl ? pCol->zColl : "",
                pCol->notNull ? 1 : 0,
                pCol->pDflt ? pCol->pDflt->u.zToken : 0,
                k,
                isHidden);
       }


Index: tool/mkpragmatab.tcl
==================================================================
--- tool/mkpragmatab.tcl
+++ tool/mkpragmatab.tcl
@@ -219,11 +219,11 @@
   IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)

   NAME: table_info
   FLAG: NeedSchema Result1 SchemaOpt
   ARG:  0
-  COLS: cid name type notnull dflt_value pk
+  COLS: cid name type aff coll notnull dflt_value pk
   IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)

   NAME: trigger_list
   FLAG: NeedSchema Result1 SchemaOpt
   COLS: seq name tm_tr op
@@ -231,11 +231,11 @@

   NAME: table_xinfo
   TYPE: TABLE_INFO
   FLAG: NeedSchema Result1 SchemaOpt
   ARG:  1
-  COLS: cid name type notnull dflt_value pk hidden
+  COLS: cid name type aff coll notnull dflt_value pk hidden
   IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)

   NAME: stats
   FLAG: NeedSchema Result0 SchemaReq
   COLS: tbl idx wdth hght flgs




--
The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume.



_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users