/ Check-in [d5e2c1fc76]
Login

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

Overview
Comment:A proposed fix for the problem of CREATE TABLE AS generating a table that has INTEGER values in a TEXT column. Ticket [f2ad7de056ab1dc92].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | create-table-as-type-fix
Files: files | file ages | folders
SHA1: d5e2c1fc7625130a3cbacc95c28bb553a0119cb8
User & Date: drh 2015-05-20 15:51:09
Context
2015-05-20
17:18
Simplification of the initialization code for CREATE TABLE AS. check-in: 937f659e89 user: drh tags: create-table-as-type-fix
15:51
A proposed fix for the problem of CREATE TABLE AS generating a table that has INTEGER values in a TEXT column. Ticket [f2ad7de056ab1dc92]. check-in: d5e2c1fc76 user: drh tags: create-table-as-type-fix
00:15
Fix handling of queries with VALUES on the left and UNION ALL SELECT on the right and a LIMIT clause. check-in: c403502cdc user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/build.c.

1911
1912
1913
1914
1915
1916
1917


1918

1919
1920
1921
1922


1923
1924
1925

1926



1927
1928
1929
1930
1931
1932
1933
1934









1935
1936
1937
1938
1939
1940
1941
    ** as a schema-lock must have already been obtained to create it. Since
    ** a schema-lock excludes all other database users, the write-lock would
    ** be redundant.
    */
    if( pSelect ){
      SelectDest dest;
      Table *pSelTab;




      assert(pParse->nTab==1);
      sqlite3VdbeAddOp3(v, OP_OpenWrite, 1, pParse->regRoot, iDb);
      sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG);
      pParse->nTab = 2;


      sqlite3SelectDestInit(&dest, SRT_Table, 1);
      sqlite3Select(pParse, pSelect, &dest);
      sqlite3VdbeAddOp1(v, OP_Close, 1);

      if( pParse->nErr==0 ){



        pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect);
        if( pSelTab==0 ) return;
        assert( p->aCol==0 );
        p->nCol = pSelTab->nCol;
        p->aCol = pSelTab->aCol;
        pSelTab->nCol = 0;
        pSelTab->aCol = 0;
        sqlite3DeleteTable(db, pSelTab);









      }
    }

    /* Compute the complete text of the CREATE statement */
    if( pSelect ){
      zStmt = createTableStmt(db, p);
    }else{







>
>

>




>
>
|

|
>

>
>
>








>
>
>
>
>
>
>
>
>







1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
    ** as a schema-lock must have already been obtained to create it. Since
    ** a schema-lock excludes all other database users, the write-lock would
    ** be redundant.
    */
    if( pSelect ){
      SelectDest dest;
      Table *pSelTab;
      int regYield;       /* Register holding co-routine entry-point */
      int addrTop;        /* Top of the co-routine */

      regYield = ++pParse->nMem;
      assert(pParse->nTab==1);
      sqlite3VdbeAddOp3(v, OP_OpenWrite, 1, pParse->regRoot, iDb);
      sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG);
      pParse->nTab = 2;
      addrTop = sqlite3VdbeCurrentAddr(v) + 1;
      sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
      sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
      sqlite3Select(pParse, pSelect, &dest);
      sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield);
      sqlite3VdbeJumpHere(v, addrTop - 1);
      if( pParse->nErr==0 ){
        int regRec = ++pParse->nMem;
        int regRowid = ++pParse->nMem;
        int addrInsLoop;
        pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect);
        if( pSelTab==0 ) return;
        assert( p->aCol==0 );
        p->nCol = pSelTab->nCol;
        p->aCol = pSelTab->aCol;
        pSelTab->nCol = 0;
        pSelTab->aCol = 0;
        sqlite3DeleteTable(db, pSelTab);
        addrInsLoop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
        VdbeCoverage(v);
        sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec);
        sqlite3TableAffinity(v, p, 0);
        sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid);
        sqlite3VdbeAddOp3(v, OP_Insert, 1, regRec, regRowid);
        sqlite3VdbeAddOp2(v, OP_Goto, 0, addrInsLoop);
        sqlite3VdbeJumpHere(v, addrInsLoop);
        sqlite3VdbeAddOp1(v, OP_Close, 1);
      }
    }

    /* Compute the complete text of the CREATE statement */
    if( pSelect ){
      zStmt = createTableStmt(db, p);
    }else{