Escaping colon symbol ":" in ColdFusion CFScript string? - coldfusion

I am writing a query in CFScript for Informix database that looks something like this:
myQuery = new Query();
myQuery.setSQL("select something from someDatabase:someTable");
In Informix someDatabase:someTable syntax means accessing table from external database but
In ColdFusion :parameter is what you write to later pass parameters. So CF throws an error
Parameter 'someTable' not found in the list of parameters specified
How do I escape that : symbol?
I tried `\` - it did not work.
Edit: I tried with backticks like so:
myQuery.setSQL("select something from `someDatabase:someTable`");
and now error message says
Parameter 'someTable`' not found in the list of parameters specified
Notice there is backtick after someTable, so it treats backtick as part of variable name.

Related

PowerBI: Filter Using URL Query String Parameter in report

I applied advance filter in PowerBI desktop, It is working. Similarly, I want to apply "Contains" or "In" operator to filter a report using URL Query String Parameter. I want to filter with delimitated value. "eq" operator is working but "in/contains" operator is not working.
I tried like this:
lstReportFilter.Add(string.Format("&filter=Sheet1/TPId in |181|"));
I have taken reference from here: https://learn.microsoft.com/en-us/power-bi/collaborate-share/service-url-filters
Can you please correct me on what I am doing wrong here?
UPDATE:
I also tried with round bracket, but still its not working. The column have data with pipes, so I need to include pipe while filtering.
lstReportFilter.Add(string.Format("&filter=Sheet1/TPId in (|181|)"));
lstReportFilter.Add(string.Format("&filter=Sheet1/TPId in ('|181|')"));
PowerBI column data
IN Operator expects a comma seperated list of primitive values or a expression
eg:
~/Products?$filter=Name in ('Milk', 'Cheese')
~/Products?$filter=Name in RelevantProductNames
~/Products?$filter=ShipToAddress/CountryCode in MyShippers/Regions
~/Products?$filter=Name in Fully.Qualified.Namespace.MostPopularItemNames
It seems like your use case is the first example, but if you don't have multiple values you can simply use the EQ Operator
like: filter=Sheet1/TPId eq |181|
Reference:
https://learn.microsoft.com/odata/webapi/in-operator
https://learn.microsoft.com/power-bi/collaborate-share/service-url-filters

Using Django SQL Explorer how do I correctly set default dates for paramters with PostgreSQL backend?

Our Django application just migrated from MySQL to PostgreSQL, and we are in the process of updating our user queries to use the correct syntax. These queries are stored/executed via Django-SQL-Explorer.
I have a query that for simplicity's sake looks like this:
SELECT * FROM table t WHERE t.scheduled_start_date BETWEEN $$from_date$$ AND $$to_date$$
The query above works, but I would like to set defaults for today & today+30 respectively.
I've tried the following WHERE clauses to no avail:
Works with user entered date, default throws syntax error
WHERE t.scheduled_start_date BETWEEN date('$$from_date:CURRENT_DATE$$') AND date('$$to_date:CURRENT_DATE + INTERVAL \'30 DAY\'$$')
Error using defaults:
syntax error at or near "30" LINE 28: ...urrent_date') AND date('current_date + interval \'30 day\'') ^
Defaults work correctly, but user entered dates do not:
WHERE t.scheduled_start_date BETWEEN date($$from_date:CURRENT_DATE$$) AND date($$to_date:CURRENT_DATE + INTERVAL '30 DAY'$$)
Error with user dates:
function date(integer) does not exist LINE 28: WHERE t.scheduled_start_date BETWEEN date(2019-09-30) AND da... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.
The message about casting makes sense to me since the user enters in string data, however I can't seem to get the syntax right that casts to DATE but only when the default is overridden.
Any suggestions would be helpful. Thanks!
Your input is a string value, current_date is a function call. The former needs quotes whereas the latter does not. Therefore your client side substitution will not work. You can move the default logic into the SQL statement using the COALESCE() function doc.
In case the client sends NULL values for an empty user input this would result in the following where clause:
BETWEEN date(COALESCE('$$from_date$$',current_date))
AND date(COALESCE('$$from_date$$',current_date + interval '30 DAYS'))
You added that your client sends an empty string, not a NULL value. So this should be changed to:
BETWEEN COALESCE(NULLIF('$$from_date$$','')::date, current_date)
AND COALESCE(NULLIF('$$from_date$$','')::date, current_date + interval '30 DAYS')

Resolving macro variable inside PROC SQL

I have a macro variable I need to use within PROC SQL. The way it resolves appears to have perfect syntax, but I am getting a syntax error and I'm not sure why;
%let test = mytext;
PROC SQL;
CREATE TABLE myTalbe&test AS
SELECT DISTINCT
a.column
FROM
tablename a
WHERE
a.column = %bquote('&test')
;QUIT;
The error I get throws a red line under the resolved text, 'mytext', and says
ERROR 22-322: Syntax error, expecting one of the following: a name, a
quoted string, a numeric constant, a datetime constant,
a missing value, (, *, +, -, ALL, ANY, BTRIM, CALCULATED, CASE, INPUT, PUT, SELECT, SOME, SUBSTRING, TRANSLATE,
USER.
I don't feel like this error applies here. If I hard code in 'mytext' it works fine. Am I missing something right under my nose? Can anyone lend me a hand?
Thanks!!!
The macro quoting is confusing the SAS parser. For this program I would remove the use of %bquote() and just use double quotes instead of single quotes so that the macro variable reference will resolve.
WHERE a.column = "&test"
If your are actually generating pass thru SQL into a system that requires the use of single quotes for string literals then you will need to use %unquote() to remove the macro quoting.
... from connection to ... ( ...
WHERE a.column = %unquote(%bquote('&test'))
... ) ...
The BQUOTE function tries to resolve the value immediately at execution time. Try removing it and using double quotes instead:
%let test = mytext;
PROC SQL;
CREATE TABLE myTalbe&test AS
SELECT DISTINCT
a.column
FROM
tablename a
WHERE
a.column = "&test"
;QUIT;

SQLite Select records which contain url

I am using Sqlite.
And I have table T with three columns: ID (int), Username (Text) and Message (Text).
I need something like this:
SELECT * FROM T WHERE Message CONTAINS <URL>
Is there a way to achieve this?
I read that Sqlite has function for handling regular expressions (regexp) but it must be implemented manually. And at this point implementing REGEXP is not an option.
The REGEXP operator is a special syntax for the regexp() user function. No regexp() user function is defined by default and so use of the REGEXP operator will normally result in an error message. If an application-defined SQL function named regexp is added at run-time, then the X REGEXP Y operator will be implemented as a call to regexp(Y,X).
try this :
SELECT * FROM T WHERE Message LIKE '%URL%';

Why do I get an error when I try to execute a query with parameters in postgreSQL?

The db is PostgreSQL. When I try to execute a query with parameters, such as this one
cursor.execute("""
SELECT u.username, up.description,
ts_rank_cd(to_tsvector(coalesce(username,'')|| coalesce(description,'')) , to_tsquery('%s')) as rank
FROM auth_user u INNER JOIN pm_core_userprofile up on u.id = up.user_id
WHERE to_tsvector(coalesce(username,'')|| coalesce(description,'')) ## to_tsquery('%s')
ORDER BY rank DESC;
""", ["hello","hello"])
Django complains of a ProgrammingError, adding syntax error at or near the parameter (in this example, "hello"). Here's the part of the Django generated SQL statement that the error comes from:
to_tsquery('E'hello'')
Even if I copy-paste it to a postgreSQL shell, I get the syntax error. If I omit the 'E' part, it works. What should I make of it?
ozgur,
Try
to_tsquery(%s)
instead of
to_tsquery('%s')
I believe you are missing a ' after the E.