ServiceStack OrmLite casing a bug - servicestack

Doing a simple
db.Dictionary("select Id, Name from \"Product\"");
results in an exception
"column "id" does not exists"
The correct field name is "Id" - seems as if the Postgres in OrmLite does something to the "Id" field. Tried with some random field names with mixed casing and they also ended up in exceptions where the fields where displayed in all lower case.
Can this be achieved somehow or is this an error in OrmLite?
Is this also an issue in db.List, db.Lookup etc?

Have you tried putting the column in quotes to preserve the case?
db.Dictionary("select \"Id\", Name from \"Product\"");
There is a unit test example here https://github.com/ServiceStack/ServiceStack.OrmLite/blob/master/src/ServiceStack.OrmLite.PostgreSQL.Tests/OrmLiteSelectTests.cs#L195

Related

jOOQ: How to resolve `Ambiguous match found for <column>` when joining across multiple tables?

The following jOOQ query spits out a SQL warning in my logs about: Fields Ambiguous match found for id
db.select(FORWARDED_MESSAGE.SES_MESSAGE_ID).
from(FORWARDED_MESSAGE).
where(
FORWARDED_MESSAGE.FORWARDED.lt( DSL.currentTimestamp().subtract(
FORWARDED_MESSAGE.mailMapping().mailKeyword().mailDomain().account().
MESSAGE_RETENTION_DAYS ))).
fetch(FORWARDED_MESSAGE.SES_MESSAGE_ID);
The SQL generated appears to be correct, but I don't want the warning polluting my logs (and I want to know if jOOQ is warning me about something important that I need to be aware of).
Some context about the schema tables:
forwarded_message doesn't have a primary key
mail_domain uses a natural PK named "domain"
mail_mapping, mail_keyword and account all have a PK named id
I tried the following, but it fails saying Key ambiguous between tables:
db.select(FORWARDED_MESSAGE.SES_MESSAGE_ID).
from(FORWARDED_MESSAGE).
join(MAIL_MAPPING).onKey().
join(MAIL_KEYWORD).onKey().
join(MAIL_DOMAIN).onKey().
join(ACCOUNT).onKey().
where(
FORWARDED_MESSAGE.FORWARDED.lt(
DSL.currentTimestamp().subtract(ACCOUNT.MESSAGE_RETENTION_DAYS) )).
fetch(FORWARDED_MESSAGE.SES_MESSAGE_ID);
jOOQ version is 3.13.4, DB is postgres, using pgjdbc 42.2.14.
The Question:
How do I resolve the Fields Ambiguous match found warning?
Note: this is not a dupe of How to resolve ambiguous match when chaining generated Jooq classes because that was about a sub-classing ambiguity - this question is about simple chaining of joins (across tables that do have duplicate PK columns).
I was able to make the warning go away by re-writing the query to the join().onKey() style, but specifying the join foreign keys explicitly.
It's a bit verbose, but it seems to work:
db.select(FORWARDED_MESSAGE.SES_MESSAGE_ID).
from(FORWARDED_MESSAGE).
join(MAIL_MAPPING).
onKey(Keys.FORWARDED_MESSAGE__FORWARDED_MESSAGE_MAIL_MAPPING_ID_FKEY).
join(MAIL_KEYWORD).onKey(Keys.MAIL_MAPPING__MAIL_MAPPING_MAIL_KEYWORD_ID_FKEY).
join(MAIL_DOMAIN).onKey(Keys.MAIL_KEYWORD__MAIL_KEYWORD_DOMAIN_FKEY).
join(ACCOUNT).onKey(Keys.MAIL_DOMAIN__MAIL_DOMAIN_MAIL_DOMAIN_ACCOUNT_ID_FKEY).
where(
FORWARDED_MESSAGE.FORWARDED.lt(
DSL.currentTimestamp().subtract(ACCOUNT.MESSAGE_RETENTION_DAYS) )).
fetch(FORWARDED_MESSAGE.SES_MESSAGE_ID);
Not sure why this is much different from the FORWARDED_MESSAGE.mailMapping()...account() style. But it works and the generated SQL is cleaner.

Server error when sorting generated entity with field name with underscore

I am getting error.internalServerError when sorting generated entity in generated table view. It leads to error only in case of fields with database names with underscore. For example project_owner.
In my console I am getting this:
GET http://localhost:9000/api/projects?cacheBuster=1489187431846&page=0&size=20&sort=image_logo_url,asc&sort=id 500 (Internal Server Error)
Is it a bug, or only my local problem?! Thanks.
The problem is in wrong parsing. See this URL for more information:
https://jira.spring.io/browse/DATACMNS-816
I thought, that when I generate field with name project_owner, it will be stored as project_owner, but entity name will be camelCase -> projectOwner.
So If you have the same issue, check your entity names and refactor them to camelCase syntax.

CouchDB: how to use wildcard

i am trying to filter records using key.For example
localhost:5984/school/_design/school/_view/schoolstats?startkey=[Name,DOB,AGE]&endkey=[Name,DOB,AGE]
1)filter using Name only
2)filter using Name and Age only
3)filter using Name and DOB only
4)filter using Age only
I have tried a lot using wildcard in couchdb but cant able to fetch the exact result.
If you use a ranged query with startkey and endkey, the order of keys is not changeable.
These combination should be working. If you need other combination you have to emit your multikey in the desired form.
startkey=[Name]&endkey=[Name,{}]
startkey=[Name,DOB]&endkey=[Name,{}]
startkey=[Name,DOB,AGE]&endkey=[Name,{}]
startkey=[Name,DOB]&endkey=[Name,DOB,{}]
For your asked filters, you have to emit two more keys/multikeys in your map function.
I think, if you do not change your emitting keys, aka, you have a emitting statement like: emit [Name,DOB,AGE], null
1)Filter using Name only
startkey=[Name]&endkey=[Name,{}]
2)Filter using Name and Age only
Can not
3)Filter using Name and DOB only
startkey=[Name,DOB]&endkey=[Name,DOB,{}]
4)Filter using Age only
Can not

Geoserver WFS Cross Layer Filtering and String IDs

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...

Subsonic - Bit operation in Where Clause

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();

Resources