How use arithmetic operators in Orchard Core SQL Query select clause - orchardcore

I have tried to run this SQL-92 query:
select (Rating * 100.0) as ratingCalc from BlogPostStatsPartIndex;
on "Run SQL Query" page in admin but it has failed with error:
"Syntax error, expected: ALL, DISTINCT, id_simple, * at line:0, col:7".
This query executes correctly on SQLite but "OrchardCore.Queries.Sql.SqlParser" class produces syntax error for this. This query looks like SQL-92 compatible. I have looked at Orchard Core's "SqlParserTests" implementation, but I haven't found any example how to use arithmetic operators in select clause.

Related

How to find the line number of error in Teradata SQL Assistant

I'm new to Teradata SQL Assistant and have a simple issue that couldn't find the solution in Terada documentations.
How I can find the exact location of this error?
You need to parse the input and find strings that don't conform to your expectations.
For example...
SELECT
*
FROM
your_table
WHERE
TryCast(your_column AS INT) IS NULL
https://docs.teradata.com/r/Teradata-Database-SQL-Functions-Operators-Expressions-and-Predicates/March-2017/Data-Type-Conversions/TRYCAST/Syntax-Elements/data_type

SQLite ON CONFLICT fails to work for v3.8.11.1 (which comes with ubuntu by default)

select sqlite_version();
INSERT INTO users (uuid, test_field) VALUES ('uuid1', '1.0);
INSERT INTO users (uuid) VALUES ('uuid1') ON CONFLICT(uuid) DO UPDATE SET test_field = '1.1';
The above results in:
3.8.11.1
OK
ERROR: near "ON": syntax error
Why is it failing to recognize the ON word of ON CONFLICT
The us of ON CONFLICT is what is termed as an UPSERT and was only introduced in SQLite 3.24.0.
as per :-
UPSERT is a special syntax addition to INSERT that causes the INSERT
to behave as an UPDATE or a no-op if the INSERT would violate a
uniqueness constraint. UPSERT is not standard SQL. UPSERT in SQLite
follows the syntax established by PostgreSQL. UPSERT syntax was added
to SQLite with version 3.24.0 (2018-06-04).
SQL As Understood By SQLite - upsert
As such it cannot be used in SQLite 3.8.11.1 and thus the SYNTAX error near ON as it's not a recognised keyword in that context.

How to prepare a statement from the CLI interpreter?

How does one prepare a statement from the SQLite CLI? I have found the page Compiling An SQL Statement but it is geared more towards the ODBC interface, not the CLI interpreter. I'm hopinpg for something akin to the following:
sqlite> pq = prepare(SELECT * FROM Users WHERE username=?)
sqlite> run(pq, 'jeffatwood')
0 | jeffatwood | hunter2 | admin
sqlite>
Does the SQLite CLI have any such functionality? Note that I am not referring to the Bash CLI but rather SQLite's CLI interpreter or the excellent LiteCLI alternative.
Perhaps SQL Parameters using named parameters would do the trick
sqlite> .param set :user 'jeffatwood'
sqlite> select * from Users where username = :user
should return the desired row.
CLI was not designed for such. For this you must use an SQLite API on an available programming language.
You may also write a batch/shell file to handle CLI call.
E.g., in Windows a file named User.bat like following:
#SQLITE3.EXE some.db "SELECT * FROM Users WHERE username='%~1'"
May be called like this:
User "jeffatwood"
will perform desired result.
EDIT:
About prepared/compiled statements: with those you can bind parameters, fetch queries row by row and repeat same command in a faster manner.
sqlite3 CLI tool wouldn't take any advantage on those:
all parameters must be typed in SQL statement, making binding useless;
all query rows are returned at once, no need to fetch row by row;
repeated commands must be retyped - small speed improvement would result in using precompiled statements.

Entity Framework 5, Code First, Full Text Search but IQueryable via CreateQuery?

I am using .NET 4.5 and EF 5 with Code First approach and now I need to implement Full Text Search.
I have already read a lot about it and so far my conclusions are:
Stored procedures nor Table Value Functions can not be mapped with Code First.
Still I can call them using dynamic sql
dbContext.Database.SqlQuery<Movie>(Sql, parameters)
But this returns IEnumerable and I want IQueryable so that I can do more filtering before fetching the data from db server. I know I can send those parameters to Db function but I don't want that.
What I have found that could fulfill my needs is CreateQuery function from IObjectContextAdapter that looks like this(Select All just for test):
IQueryable<Movie> result = ((IObjectContextAdapter)dbContext).ObjectContext.CreateQuery<Movie>("SELECT * FROM Movie");
However executing this throws Exception"
'System.Data.EntitySqlException was unhandled
HResult=-2146232006
Message=The query syntax is not valid. Near term '*', line 1, column 9.'
So the questions are:
Why do I get this exception and can it be fixed ?
If not is there any way with Code First to do FTS that returns IQueryable ?
Try it like this
ObjectQuery<Movie> query =
objectContext.CreateQuery<Movie>(#"SELECT VALUE movie FROM Movies");
As for why see these links
Differences from Transact-SQL Unlike Transact-SQL, Entity SQL does not
support use of the * argument in the SELECT clause. Instead
Entity SQL Reference - SELECT
"SELECT VALUE" - value keyword in LINQ/Entity Framework query

Viewing results of a pipelined function in SQL*Plus or Oracle SQL Developer

How can I view the results returned by a pipelined function in Oracle SQL Developer ?
I'm invoking the function using a simple select..from dual like
select piaa_extract.FN_PIAA_EXTRACT('01-JAN-00','01-JAN-12') FROM DUAL
and the result I get is
IQCFINAL.REC_PIAA(IQCFINAL.REC_PIAA,IQCFINAL.REC_PIAA,.....,IQCFINAL.REC_PIAA)
Allround Automations' PL/SQL developer displays the results beautifully in a tabular format, but I do not have a license for the full version of PL/SQL developer.
SQL*Plus' output isn't very good either, though better than Oracle SQL Developer's.
Any thoughts ?
Typically, you'd use
select * from table(piaa_extract.FN_PIAA_EXTRACT('01-JAN-00','01-JAN-12'))
Does that work?

Resources