Room #Query doesn't work with a pre-created SQLite VIEW - kotlin

It appears that #Query Room annotation would not recognize a pre-existing VIEW in a pre-created SQLite schema .
Is there any work-around ?
(I'm aware that the Room API can generate VIEWs on SQLite, but in my use-case I want an ad-hoc #Query to work with a hand-created pre-existing VIEW on SQLite )
Thank you in advance for any help!

You could use an #RawQuery (in short Room knows nothing about the view and hence). See https://developer.android.com/reference/androidx/room/RawQuery

Related

Is there a way to use scripting methods in a saved view in BigQuery?

I am currently using a view in BigQuery to aggregate data from many different large tables. I then use this view to create a materialized flat table, with a MERGE statement to update it. However, the most recent LEFT JOIN I've added to the view caused the query that instantiates the materialized table to return the error: "Resources exceeded during query execution." The view right now is estimated to churn through 60GB of data.
To try to solve this issue, I tried using scripting to create temporary tables for the different subqueries in the view, thinking that this might save on resources. However, it appears that I am not able to save a view that uses scripting. Is there some way that this can be done?
I assume that is not supported today. I had the errors weeks ago and I bet that is due to beta version.
For answering the comment, a very simple query
DECLARE dummy STRING;
set dummy="not work";
select dummy
This simply answers not work. Try to create a view from this, I have an error Syntax error: Unexpected keyword DECLARE at [1:1]. Not a data error, not a query error, simply not supported!
Using stored procedure not help because you use "script" command CALL for calling your stored procedure.
For information, there is a feature request on this

Reverse Engineering a View

I was asked how to reverse engineer a view so it can be determined what columns and table were used in the sql query to produce the view . So say view 1 was constructed from the following 10 tables and 43 columns . Is this even possible in sql server 2005 ?
Use sp_helptext
exec sp_helptext 'your_view'
Edit
What you want is to find out what dependencies your view has. You can use sp_depends to do that, but it will only get you the table dependencies and not the columns.
exec sp_depends 'your_view'
In order to find out the columns you will probably have to code some kind of SQL parser to extract the columns being used from the Create View statement you recovered with sp_helptext.
You can try using a ReGex to extract the info you want or if you want a big and fancier gun you can try Irony which has a built in Sql Lexic.
Yes, in SSMS choose your database -> views -> right click -> script as CREATE.
If you want to decode a view on another database, you have no access to (e.g interface) - than this is not possible.

SQL query to get the source of a Stored Procedure

I'm using a DB2 database and I'm hoping for a query which will iterate over all stored procedures in a single database and print out the source code of each. No fancy formatting or performance requirements.
The reason for this (in case there's a better way of doing it) is I'm trying to track down usages of a particular table in our stored procs, so I want to be able to do a simple text search through all of them.
Also, I've got access to SQuirreL SQL client if anyone knows of a way via that.
Ah, figured it out. For other's reference:
select ROUTINENAME, TEXT from syscat.routines
where definer not in ('SYSIBM') AND ROUTINESCHEMA='databaseName'
I know this is old, but your answer started me on the right track. We are also using DB2, but don't have syscat.routines visible to us. However we do have SYSIBM.SYSROUTINES and that allows similar by doing
SELECT SCHEMA,
NAME,
TEXT
FROM SYSIBM.SYSROUTINES
WHERE SCHEMA = '<SCHEMA>'
and NAME = '<NAME>'
FOR FETCH ONLY WITH UR;

Use varbinary(max) to store HTML? SQL Server 2008

I am trying to figureout the best solution to store html data in some of my tables and track the history of changes made to that HTML. I read that text, ntext, etc are no longer supported for AFTER Triggers so I was thinking of using the varbinary(max) instead. Has anyone used varbinary to store HTML? I was planning on tracking the changes using a trigger to write off the history when the HTML is updated.
As always I greatly appreciate the input....the feedback I get is always great.
Thanks,
S
using varchar(max) would be more logical - it is made for textual data and you can us string processing functions with it.
Why not varchar(max) or nvarchar(max) instead?

MySQL VIEW vs. embedded query, which one is faster?

I'm going to optimize a MySQL embedded query with a view, but I'm not sure whether it will give an effect:
SELECT id FROM (SELECT * FROM t);
I want to convert it to:
CREATE VIEW v AS SELECT * FROM t;
SELECT id FROM v;
I've heard about "indexed views" in SQL Server, but I'm not sure about MySQL. Any help would be appreciated. Thanks!
Indexed views in SQL Server are generally called "materialized views", which MySQL does not support. MySQL's VIEW support is rather limited in comparison to other vendors - the restrictions are listed in their documentation.
A normal view is merely a prepared SQL statement - there's no difference between using the two examples you provided. In some cases, the WHERE clause when selecting from a View can be pushed into the VIEW query by the optimizer, but it's completely out of your control.
The view might be faster (it probably is), but why don't you just test it? Or run an EXPLAIN against both queries to see how they will execute?
It's about the same. Will it be fast or not it depends on your indexes.
MySQL caches query results, so as long as your queries are same between executions, and as long as underlying dataset is same (no new records added), it will return cached results on next query execution.
The select statement will be run each time you fetch a view.
A view behaves a bit differently, see Create View