We are trying to create a dynamic query subject filter. To do this, we are trying to nest an Oracle user-defined function inside of a macro.
Example query subject filter:
#strip(ORACLE_USER_DEFINED_FUNCTION())#
We have imported the oracle function ORACLE_USER_DEFINED_FUNCTION into Framework Manager. The function returns a VARCHAR2 of the desired expression. For testing purposes, this function is simply returning VARCHAR2 value of '1=1' (the single quotes are not part of the VARCHAR2 return value).
The idea being that we want the query subject filter expression to be dynamically generated at run-time so the resulting query contains '...WHERE 1=1'. The strip macro is the mechanism to pre-process and invoke the user-defined function before the query is sent to the database.
However, when attempting to verify/check the query subject filter we receive the following error.
XQE-GEN-0018 Query Service internal error has occurred, please see the log for details.
I'm trying to get a hold of the query service log, but don't yet have it.
Perhaps there is some casting needed to convert the oracle VARCHAR2 output from the function to an IBM/Cognos string that is acceptable input for the IBM/Cognos macro.
Your assistance is appreciated. Thanks in advance.
Using Oracle 12c and Cognos 11.1.
With the exception of the queryValue macro function, macros are evaluated prior to accessing the database. This means the macro does not know what the Oracle UDF is or what its supposed to do. If you are able to call the UDF via a FM query subject you maybe able to get away with something similar to the queryValue answer found here:
Cognos 11.1.7 Framework manager change the table for the query subject, type data
Related
I tried DapperExtensions, Dapper.Extensions.Linq and linq2dapper to no avail. I will try Dapper.SimpleCRUD-with-Oracle. I will probably settle with a Stored Procedure instead. I want to use TableDirect with no embedded SQL statement. How can I use Dapper and Linq with a TableDirect? Or, how can I use TableDirect without embedded SQL, and filter a table?
Following are my problems:
I could not create Predicate without run time error.
I need missing configuration
I got ORA error about table saying "column not correct, runtime error".
How to use Dapper LINQ with TableDirect (without embedded SQL) with ORACLE?
You can achieve this with simple Dapper. For example, look at the following code from Dapper:
public static IEnumerable<T> Query<T>(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = default(int?), CommandType? commandType = default(CommandType?));
Look at the last commandType parameter. It supports the TableDirect value that you are looking for.
As far as other extensions of Dapper you mentioned in question, I do not think they will support it. I know for sure Dapper Extensions do not support it; not sure about others.
This is because, those extensions are basic query generators written over Dapper. So, you are using them for generating the query and in that case, that parameter value will/should be Text. If you want to use other values, bypass the extension and use simple Dapper.
If you want to simply provide a table name or stored procedure name, why use query generator? Just use Dapper.
I used //https://github.com/jmo21/Dapper.SimpleCRUD-with-Oracle-/blob/master/Dapper.SimpleCRUD/SimpleCRUD.cs . No nuget package for this ORACLE dialect. It just obfuscates the WHERE clause, and it is an answer, when I the organization probably will not like SELECT.. FROM ... WHERE...
We don't have SQL injection possible in any case.
I'm changing an Oracle based SSRS report and I'm having all sorts of issues with parameters.
The connection to Oracle is OLE DB.
My code is not doing anything complicated. I've only added in a new parameter. When I only have one instance of said parameter, it runs without any issues. As soon as I add it again, it bombs.
What I'm trying to do is show records if a parameter has a match. If no match, show all records.
I can run both queries in DBVisualizer without any issues.
This is what I've done
WHERE FieldName = nvl(:parameter, FieldName)
This one doesn't return the same results as this below
WHERE FieldName = :parameter
OR :parameter IS NULL
Problem is the second WHERE clause will not run in SSRS with an OLE DB connection. We cannot use another connection manager, unfortunately.
EDIT: Thanks to Hannover Fist, I was able to get this to work by doing this
I changed my WHERE clause to
WHERE FieldName = :parameter
OR :parameter2 IS NULL
Then mapped parameter2 to pull from the same SSRS parameter as the original parameter
I haven't found a good solution to this problem but I have worked around it by declaring the parameter in the Oracle SQL and mapping it to the SSRS parameter.
Then use the parameter created in the Oracle SQL in the rest of the query. This way you'll only use each SSRS parameter once.
We are trying to use a simple user-defined function (UDF) in the where clause of a query in Azure Cosmos DB, but it's not working correctly. The end goal is to query all results where the timestamp _ts is greater than or equal to yesterday, but our first step is to get a UDF working.
The abbreviated data looks like this:
[
{
"_ts": 1500000007
}
{
"_ts": 1500000005
}
]
Using the Azure Portal's Cosmos DB Data Explorer, a simple query like the following will correctly return one result:
SELECT * FROM c WHERE c._ts >= 1500000006
A simple query using our UDF incorrectly returns zero results. This query is below:
SELECT * FROM c WHERE c._ts >= udf.getHardcodedTime()
The definition of the function is below:
function getHardcodedTime(){
return 1500000006;
}
And here is a screenshot of the UDF for verification:
As you can see, the only difference between the two queries is that one query uses a hard-coded value while the other query uses a UDF to get a hard-coded value. The problem is that the query using the UDF returns zero results instead of returning one result.
Are we using the UDF correctly?
Update 1
When the UDF is updated to return the number 1, then we get a different count of results each time.
New function:
function getHardcodedTime(){
return 1;
}
New query: SELECT count(1) FROM c WHERE c._ts >= udf.getHardcodedTime()
Results vary with 7240, 7236, 7233, 7264, etc. (This set is the actual order of responses from Cosmos DB.)
By your description, the most likely cause is that the UDF version is slow and returns a partial result with continuation token instead of final result.
The concept of continuation is explained here as:
If a query's results cannot fit within a single page of results, then the REST API returns a continuation token through the x-ms-continuation-token response header. Clients can paginate results by including the header in subsequent results.
The observed count variation could be caused by the query stopping for next page at slightly different times. Check the x-ms-continuation header to know if that's the case.
Why is UDF slow?
UDF returning a constant is not the same as constant for the query. Correct me if you know better, but from CosmosDB side, it does not know that the specific UDF is actually deterministic, but assumes it could evaluate to any value and hence has to be executed for each document to check for a match. It means it cannot use an index and has to do a slow full scan.
What can you do?
Option 1: Follow continuations
If you don't care about the performance, you could keep using the UDF and just follow the continuation until all rows are processed.
Some DocumentDB clients can do this for you (ex: .net API), so this may be the fastest fix if you are in a hurry. But beware, this does not scale (keeps getting slower and cost more and more RU) and you should not consider this a long-term solution.
Option 2: Drop UDF, use parameters
You could pass the hardcodedTime instead as parameter. This way the query execution engine would know the value, could use a matching index and give you correct results without the hassle of continuations.
I don't know which API you use, but related reading just in case: Parameterized SQL queries.
Option 3: Wrap in stored proc
If you really-really must control the hardcodedTime in UDF then you could implement a server-side procedure which would:
query the hardcodedTime from UDF
query the documents, passing the hardcodedTime as parameter
return results as SP output.
It would use the UDF AND index, but brings a hefty overhead in the amount of code required. Do your math if keeping UDF is worth the extra effort in dev and maintenance.
Related documentation about SPs: Azure Cosmos DB server-side programming: Stored procedures, database triggers, and UDFs
Hello I am using Entity Framework and I am using the ExecuteStoreCommand to do a query against the database. well I am basically calling a user defined function.
This is the call:
string result = m.ExecuteStoreQuery (SQL).FirstOrDefault();
I query the User Defined Function and I get the following result.
2.09,2.06,2.06,2.0098,2.04,2.04,2.04,2.04,2.04,2,2.1,2.04,2.04,2.04
The return type for the user defined function is
RETURNS Varchar(200). The result above is from the same cell.
When I execute the code from MVC controller I get the following error.The data reader has more than one field. Multiple fields are not valid for EDM primitive types.
What datatype I should be using instead of string.
Any ideas and suggestions.
Apparently, the return type is not only a string.
On the SQL Server side, try to surround the code of your query with:
SET NOCOUNT ON
<your current sql code>
SET NOCOUNT OFF
Maybe EF is getting the rows affected in the result and gets messed up.
I currently have an existing database and I am using the LINQtoSQL generator tool to create the classes for me. The tool is working fine for this database and there are no errors with that tool.
When I run a LINQ to SQL query against the data, there is a row that has some invalid data somehow within the table and it is throwing a System.FormatException when it runs across this row. Does anyone know what that stems from? Does anyone know how I can narrow down the effecting column without adding them one by one to the select clause?
Do you have a varchar(1) that stores an empty string?
You need to change the type from char to string in the designer (or somehow prohibit empties). The .net char type cannot hold an empty string.