Exemplo n.º 1
0
        // The parser calls this routine in order to create a new VIEW
        internal static void sqlite3CreateView(Parse pParse, Token pBegin, Token pName1, Token pName2, Select pSelect, int isTemp, int noErr)
        {
            var sFix = new DbFixer();
            var db   = pParse.db;

            if (pParse.nVar > 0)
            {
                sqlite3ErrorMsg(pParse, "parameters are not allowed in views");
                sqlite3SelectDelete(db, ref pSelect);
                return;
            }
            Token pName = null;

            sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
            var p = pParse.pNewTable;

            if (p == null || pParse.nErr != 0)
            {
                sqlite3SelectDelete(db, ref pSelect);
                return;
            }
            sqlite3TwoPartName(pParse, pName1, pName2, ref pName);
            var iDb = sqlite3SchemaToIndex(db, p.pSchema);

            if (sqlite3FixInit(sFix, pParse, iDb, "view", pName) != 0 && sqlite3FixSelect(sFix, pSelect) != 0)
            {
                sqlite3SelectDelete(db, ref pSelect);
                return;
            }
            // Make a copy of the entire SELECT statement that defines the view. This will force all the Expr.token.z values to be dynamically
            // allocated rather than point to the input string - which means that they will persist after the current sqlite3_exec() call returns.
            p.pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
            sqlite3SelectDelete(db, ref pSelect);
            if (0 == db.init.busy)
            {
                sqlite3ViewGetColumnNames(pParse, p);
            }
            // Locate the end of the CREATE VIEW statement.  Make sEnd point to the end.
            var sEnd = pParse.sLastToken;

            if (Check.ALWAYS(sEnd.z[0] != 0) && sEnd.z[0] != ';')
            {
                sEnd.z = sEnd.z.Substring(sEnd.n);
            }
            sEnd.n = 0;
            var n = (int)(pBegin.z.Length - sEnd.z.Length);
            var z = pBegin.z;

            while (Check.ALWAYS(n > 0) && sqlite3Isspace(z[n - 1]))
            {
                n--;
            }
            sEnd.z = z.Substring(n - 1);
            sEnd.n = 1;
            // Use sqlite3EndTable() to add the view to the SQLITE_MASTER table
            sqlite3EndTable(pParse, null, sEnd, null);
            return;
        }
Exemplo n.º 2
0
 internal static void sqlite3CreateView(Parse pParse, Token pBegin, Token pName1, Token pName2, Select pSelect, int isTemp, int noErr)
 {
 }