It seems like OrmLite plain select extension method (Select<T>) tries to format the query string (like SelectFmt<T>), and so it throws an error if the query string contains curly brackets, which it assumes are missing arguments.
Example query:
db.Select<Company>("Website='http://www.test.com/?session={123}'");
Error thrown:
Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
Ideally, Select<T> should just execute the query verbatim, without any string formatting.
Is it a bug in OrmLite, or something else?!
Update: Seems like the issue is here in OrmLiteDialectProviderBase class. It should have a check for params length etc.
You can use SqlList<T> API's for executing Custom SQL that skips pre-processing by OrmLite, but you'll need to provide the full SQL Statement, e.g:
var results = db.SqlList<Company>(
"SELECT * FROM Company WHERE Website='http://www.test.com/?session={123}'");
Related
Getting "error occurred during batching: ORA-00933 SQL command not properly ended.
I'm trying to update/insert byte array in Oracle BLOB column using jooq syntax as follows:-
Map<Field<Object>, Object> fieldValueMap = new HashMap<>();
fieldValueMap.put(field("BLOB_COLUMN"), "test".getBytes());
Query = DSLContext.update(table(tablename)).set(fieldValueMap).where(condition)
Formed query for blob column as follows:-
Update tablename set BLOB_COLUMN = X'74657374' where condition.
Please help with the above issue.
X'74657374' is the default rendering of bytes[] inline literals for unknown dialects, as well as a few known dialects, including e.g. H2, HSQLDB, MariaDB, MySQL, SQLite. If you had used the SQLDialect.ORACLE dialect, then you'd have gotten something like hextoraw('74657374') as generated SQL, which wouldn't produce the error you've seen.
But you probably don't want to get inline literals anyway. This probably happened because you either:
Used static statements
Explicitly used inline literals
Trying to add values from the JSON Parser into a dynamic Oracle query but always shows up as blank/empty.
Same results trying to use the formal parameters and declaring them within the Oracle query as well.
Is this possible?
Service Bus trigger. Message comes in and goes into the "For each message" loop. It then gets parsed in the "Parse JSON Message" and when I try to use the dynamic content from that in an Oracle query (e.g. #body('Parse_JSON_Message')?['contentData']?['dynamicValue']), they always show up as nothing/blank.
I can use this same reference later (again #body('Parse_JSON_Message')?['contentData']?['dynamicValue']) with no issues but it always ends up blank in the query.
Even using formal parameterized key values shows the #body('Parse_JSON_Message')?['contentData']?['dynamicValue']) to be NULL.
So my queries are coded as:
SELECT thisValue
WHERE columnName = #body('Parse_JSON_Message')?['contentData']?['dynamicValue'] (have also tried #{body('Parse_JSON_Message')?['contentData']?['dynamicValue']})
But are coming out as:
SELECT thisValue
WHERE columnName =
...with no result obviously.
This query does work if I hard code the value.
If I use dynamic values in my output (where I'm mapping data), it works fine. So how should I correctly dynamic values in this Oracle query?
I have a Geoserver WFS request with a cross layer filter based cql in it, that looks like this:
...&CQL_FILTER=INTERSECTS(the_geom, querySingle('myLayerName','the_geom','the_id = F338'))
This does not work. Geoserver is giving me this error message:
java.lang.NullPointerException: PropertyDescriptor is null - did you
request a property that does not exist?
if I change the filter to this:
&CQL_FILTER=INTERSECTS(the_geom, querySingle('myLayerName','the_geom','INCLUDE'))
it is working.
What could be going wrong in the first example? The id with the value F338 in fact does exist.
Could it be that Geoserver is expecting a integer as id? In CQL filters can be strings, but they have to be quoted. In my example, i obviously cannot really quote the value because the whole parameter to the querySingle function is a quote itself.
For string comparison, you need to put two single quotations, so i.e.
'the_id = ''F338'''. (one double quotation doesn't work)
This stupid undocumented little thing cost me 5 hours of try and error...
I have to execute following query:
create dm_myobject object
set my_id_attribute = (select r_object_id from dm_otherobject where <some clause here>)
where ...
But subquery in brackets returns more than one id. I can't make whereclause more detailed to retrieve only one value.
How to take first?
ENABLE(FETCH_ALL_RESULTS 1) or ENABLE(RETURN_TOP 1) doesn't help.
In my experience it is impossible to use DQL hints in a sub query like you suggested, because the hint is applied to the query as a whole. It is indeed possible to use, say, ENABLE(RETURN_TOP 1) on a query that contains a sub query, however that hint will then be used on the outer query and never on the inner one. In your case, however, you'll end up with an error message telling that the sub query returns more than one result.
Try using an aggregate function on the selected attribute instead:
CREATE dm_myobject OBJECT
SET my_id_attribute = (
SELECT MIN(r_object_id)
FROM dm_otherobject
WHERE <some clause>
)
The MIN and MAX functions work with ints and strings, and I suspect they work with IDs too. Since it is ok for you to set only the first ID that's returned from your sub query, I suspect you're returning them in a sorted order and want to use the first -- hence the usage of the MIN function.
An alternative approach would of course be to write a script or a small Java program that executes several DQL statements, but that might or might not work for you in your case.
I'm trying to make something like this:
int count = new Select().From(tblSchema).Where("Type & 1").IsEqualTo("1").GetRecordCount();
And the error message is:
Incorrect syntax near '&'.
Must declare the scalar variable "#Deleted".
Is it possible to do that with SubSonic?
Must declare the scalar variable
"#Deleted"
The second error would be caused by using logical deletes on the table you are querying (the table has an isDeleted or Deleted column).
But I'm looking through the code, I'm not sure how that parameter is getting in there. The SqlQuery.GetRecordCount method doesn't call CheckLogicalDelete(), from what I can tell. Is that error message unrelated?
This seems to be a bug in the way SubSonic is naming it's parameters when it generates the SQL to be executed.
What's happening is that SubSonic is looking at "Type & 1" and then creating a parameter to compare against called #Type&10 which is not a valid SQL parameter name. So you'll end up with the following SQL from your original query. You should submit a bug to http://code.google.com/p/subsonicproject/
Meanwhile you can workaround the bug for now by using an inline query:
http://subsonicproject.com/docs/Inline_Query_Tool
It is a little fuzzy as to what you are trying to accomplish but here is a best guess.
int count = new Select().From(tbl.Schema).Where(tbl.TypeColumn).IsEqualTo(true).GetRecordCount();