public static void CreateViews(IQueryContext context)
        {
            // This view shows the grants that the user has (no join, only priv_bit).
            context.ExecuteQuery("CREATE VIEW INFORMATION_SCHEMA.ThisUserSimpleGrant AS " +
                                 "  SELECT \"priv_bit\", \"object\", \"name\", \"user\", " +
                                 "         \"grant_option\", \"granter\" " +
                                 "    FROM " + SystemSchema.UserGrantsTableName +
                                 "   WHERE ( user = user() OR user = '******' )");

            // This view shows the grants that the user is allowed to see
            context.ExecuteQuery("CREATE VIEW INFORMATION_SCHEMA.ThisUserGrant AS " +
                                 "  SELECT \"description\", \"object\", \"name\", \"user\", " +
                                 "         \"grant_option\", \"granter\" " +
                                 "    FROM " + SystemSchema.UserGrantsTableName + ", " + SystemSchema.PrivilegesTableName +
                                 "   WHERE ( user = user() OR user = '******' )" +
                                 "     AND " + SystemSchema.UserGrantsTableName + ".priv_bit = " +
                                 SystemSchema.PrivilegesTableName + ".priv_bit");

            // A view that represents the list of schema this user is allowed to view
            // the contents of.
            context.ExecuteQuery("CREATE VIEW INFORMATION_SCHEMA.ThisUserSchemaInfo AS " +
                                 "  SELECT * FROM  " + SystemSchema.SchemaInfoTableName +
                                 "   WHERE \"name\" IN ( " +
                                 "     SELECT \"name\" " +
                                 "       FROM INFORMATION_SCHEMA.ThisUserGrant " +
                                 "      WHERE \"object\" = " + ((int)DbObjectType.Schema) +
                                 "        AND \"description\" = '" + Privileges.List + "' )");

            // A view that exposes the table_columns table but only for the tables
            // this user has read access to.
            context.ExecuteQuery("CREATE VIEW INFORMATION_SCHEMA.ThisUserTableColumns AS " +
                                 "  SELECT * FROM " + SystemSchema.TableColumnsTableName +
                                 "   WHERE \"schema\" IN ( " +
                                 "     SELECT \"name\" FROM INFORMATION_SCHEMA.ThisUserSchemaInfo )");

            // A view that exposes the 'table_info' table but only for the tables
            // this user has read access to.
            context.ExecuteQuery("CREATE VIEW INFORMATION_SCHEMA.ThisUserTableInfo AS " +
                                 "  SELECT * FROM " + SystemSchema.TableInfoTableName +
                                 "   WHERE \"schema\" IN ( " +
                                 "     SELECT \"name\" FROM INFORMATION_SCHEMA.ThisUserSchemaInfo )");

            context.ExecuteQuery("  CREATE VIEW " + Tables + " AS " +
                                 "  SELECT NULL AS \"TABLE_CATALOG\", \n" +
                                 "         \"schema\" AS \"TABLE_SCHEMA\", \n" +
                                 "         \"name\" AS \"TABLE_NAME\", \n" +
                                 "         \"type\" AS \"TABLE_TYPE\", \n" +
                                 "         \"other\" AS \"REMARKS\", \n" +
                                 "         NULL AS \"TYPE_CATALOG\", \n" +
                                 "         NULL AS \"TYPE_SCHEMA\", \n" +
                                 "         NULL AS \"TYPE_NAME\", \n" +
                                 "         NULL AS \"SELF_REFERENCING_COL_NAME\", \n" +
                                 "         NULL AS \"REF_GENERATION\" \n" +
                                 "    FROM INFORMATION_SCHEMA.ThisUserTableInfo \n");

            context.ExecuteQuery("  CREATE VIEW " + Schemata + " AS " +
                                 "  SELECT \"name\" AS \"TABLE_SCHEMA\", \n" +
                                 "         NULL AS \"TABLE_CATALOG\" \n" +
                                 "    FROM INFORMATION_SCHEMA.ThisUserSchemaInfo\n");
        }
Exemple #2
0
        protected IQueryResponse[] CoreExecuteQuery(IQueryContext context, string text, IEnumerable<QueryParameter> parameters)
        {
            // Where Query result eventually resides.
            int resultId = -1;

            // For each StreamableObject in the query object, translate it to a
            // IRef object that presumably has been pre-pushed onto the server from
            // the client.

            // Evaluate the sql Query.
            var query = new SqlQuery(text);
            if (parameters != null) {
                // TODO: Download the Large-Objects and replace with a reference
            }

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            var results = context.ExecuteQuery(query);
            var responses = new IQueryResponse[results.Length];
            int j = 0;

            foreach (var result in results) {
                QueryResult queryResult;
                try {
                    queryResult = new QueryResult(query, result);
                    resultId = AddResult(queryResult);
                } catch (Exception e) {
                    if (resultId != -1)
                        DisposeResult(resultId);

                    throw;
                }

                var taken = stopwatch.Elapsed;

                // Return the Query response
                responses[j] = new QueryResponse(resultId, queryResult, (int)taken.TotalMilliseconds, "");

                j++;
            }

            stopwatch.Stop();
            return responses;
        }