I'm running the following query:
SELECT new com.acme.Rooms.RoomStatistics(r.floor.floorId ,SUM(r.roomCapacity), COUNT(DISTINCT r.roomType.roomTypeId), COUNT(r.roomId)) FROM Room r where r.disabled = 0 group by r.floor.floorId
My RoomStatistics constructor's signature is
(int, long, long, long)
I've noted the similar questions (where COUNT(AppleTree) should be replaced with COUNT(AppleTree.id)). But it looks a bit different.
I have the following error in markers view:
No constructors can be found that match the argument types.
What's the reason of this error? Is there a way I can debug it?
I've disabled JPA validation. It compiles good and runs as expected without the validation. Sort of workaround, but I was unable to find better solution.
Related
I am very new to Xtext/Xtend, therefore apologies in advance if the answer is obvious.
I would like to allow the end-users of my DSL to define a 'filter', that when applied and 'returns' true it means that they want to 'filter out' the given entity of data from consideration.
I want to allow them 2 ways of defining the filter
A) by introspecting the attributes of a given data object and apply basic rules like
if (obj.field1<CURRENT_DATE && obj.field2=="EXPIRED)
{ return true;} else {return false;}
B) by executing a controlled snippet using 'eval' of my host language
In other words, the user would be expected to type into a string/code block a valid
code snippet of the hosting language
I had decided that the easiest way for me support case A) would be to leverage the XBase rules (including expressions/etc)
Therefore I defined filters (mostly copying the ideas from Lorenzo's book)
Filter:
(FilterDSL | FilterCode);
FilterDSL:
'filterDSL' (type=JvmTypeReference)? name=ID
'(' (params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)*)? ')'
body=XBlockExpression ;
FilterCode:
'filterCode' (type=JvmTypeReference)? name=ID
'(' (params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)*)? ')'
'{'
body=STRING
'}';
Now when trying to implement the Java mapping for my DSL, via the inferrer stub in Xtend -- I am running into multiple problems.
All of them likely indicate that I am missing some fundamental understanding
Problem 1) fl.body is not defined. fl Is of type Filter, not FilterDSL or FilterCode
And I do not understand how to check what type a given instance is of, so that I can access the content of a 'body' feature.
Problem 2) I do not understand where 'body' attribute in the inferrer method is defined and why. Is this part of ECore? (I could not find it)
Problem 3) what's the proper way to allow a user to specify a code block? String seems to be not the right thing as it does not allow multiline
Problem 4) How do I correctly convert a code block into something that is accepted by the 'body' such that it ends up in the generated code.
Problem 5) How do I setup multiple inferrers (as I have more than one thing for which I need the code generated (mostly) by xBase code generator)
Appreciate in advance any suggestions, or pointer to code examples solving similar problems.
As a side observation, Inferrer and its interplay with XBase has sofar been the most confusing and difficult thing to understand.
in general: have a look at the xtend docs at xtend-lang.org
You can do a if (x instanceof Type) or a switch statement with Type guards (see domain model example)
i dont get that question. both your FilterDSL and FilterCode EClasses should have a field+getter/setter named body, FilterCode of type String, FilterDSL of type XBlockExpression. The JvmTypesBuilder add extension methods to JvmOperation called setBody(String) and setBody(XExpression), syntax sugar lets you call body = .... instead of setBody(...)
(btw you can do crtl+click to find out where a thing is defined)
strings are actually multiline
is answered by (2)
you dont need multiple inferrers, you can infer multiple stuff e.g. by calling toClass or toField multiple times for the same input
I'm trying to create this sort of Map:
var map:Map = new Map<Dynamic, Array<ProductData>>();
But compiler throws an error : Unexpected ;
So it doesn't like the types declaration nesting. But I really do need that Array<ProductData> as a value of a map.
How can I overcome this mistake?
That's interesting, since I get a different error with that code:
Invalid number of type parameters for Map
That is fixed by removing the :Map though (just let type inference handle that).
After that, though, I get the following error:
Abstract Map has no #:to function that accepts IMap>
...or in other words - you can't have a Map with Dynamic keys in Haxe. Why are you using Dynamic there in the first place? Could that maybe be statically typed?
Quick question... I have to work with quite a bit of legacy ASP code that I am cleaning up, and it all uses queries that are vulnerable to SQL injection. I have a library that I put together to replace them with parameterized queries, and I'm wondering if there is a difference from a security standpoint between the following approaches.
Approach 1: This is the approach shown on most examples where parameter objects are individually built and added to the Command object. Here's an example from another question.
Approach 2: Use the Command.Execute method with an array of parameter values. Example:
Command.CommandText = "select foo, bar from baz where a = ? and b = ?"
Command.Execute , Array(1, "BBB")
Yes, the first parameter to Execute is ignored.
The first approach has each parameter built with its type, size, etc all specified, and it needs to match the database. But I've always had trouble with that approach, weird errors and the like if everything isn't "just" perfect. So I prefer the latter, and it in fact works with my coding style much better because I can encapsulate the DB logic into a class and pass around arrays as needed without having to litter my code with tons of DB calls.
Example of approach #2 using my wrapper DB.Query method:
set rs = DB.Query("select foo, bar from baz where a = ? and b = ?", Array(1, "BBB")
Or:
set rs = DB.Query("select foo, bar from baz", empty)
(passing keyword empty to denote the parameter is not used)
Given that, I'm wondering: Is approach #2 still safe from SQL injection attacks?
Thanks.
Edit The call to Execute was wrong and written from memory, it has been corrected.
From my sight: yes it is.
i wrote a quick example and then debugged it with Visual Studio. After the call to
Command.Execute , Array(1, "BBB")
the Parameters object of the ADODB.Command is properly filled with the given values from the Array. The datatype and length of the parameters is correctly set.
So in my opinion this approach is as safe as the approach #1 (with a manually created Parameters object).
I tried running this Query in CRM 2011:
var activity = (from a in crmService.ActivityPointerSet
where a.StateCode == ActivityPointerState.Open &&
a.ActivityTypeCode == "4201"
select a).First();
But I got this error:
Microsoft.Crm.Metadata.EntityMetadataNotFoundException: The entity with a name = '4201' was not found in the MetadataCache
After checking with the FilteredActivityPointer database view, I noticed that that column was defined as an int, not a string. I manually edited the generated class, changing the string to an int on the property, and it worked just fine.
Is there a bug in the early bound type generator (CrmSvcUtil.exe), or did I somehow create it wrong?
EDIT: After some more testing, it looks like the ActivityTypeCode is expecting the string "appointment". Don't know why it's showing differently in the database though...
I would imagine they have done this as ObjectTypeCodes are not guaranteed to be the same across different deployments (if you have more than one).
By using 'task', 'appointment' or 'email' (etc) there is no ambiguity.
I agree it seems a bit strange though!
I'm getting an error while trying to load an record through the constructor.
The constructor is:
public Document(Expression<Func<Document,bool>> expression);
and i try to load a single item in like this
var x = new Document(f=>f.publicationnumber=="xxx");
publicationnumber isn't a key but tried making an it an unique key and still no go..
Am i totally wrong regarding the use of the constructor? and can someone please tell me how to use that constructor?
The error i'm getting is:
Test method TestProject1.UnitTest1.ParseFileNameTwoProductSingleLanguage threw exception: System.NullReferenceException:
with the following stacktrace:
SubSonic.Query.SqlQuery.Where[T](Expression1` expression)
Load`[T]`(T item, Expression1expression)
db.Document..ctor(Expression``1 expression) in C:\#Projects\DocumentsSearchAndAdmin\DocumentsSearchAndAdmin\Generated\ActiveRecord.cs: line 5613
rest removed for simplicity
Regards
Dennis
Use == instead of =, i.e.:
...(f=>f.publicationnumber == "xxx");
I've just gotten the SubSonic source, and found out that it had to with the expression parser and my lack of knowledge thereof .. my right side of the expression was actually an item in an string array - and s[PUBNO] (PUBNO is a const) and it was looking for an column named s instead of publicationnumber, i don't know if this i a bug or not in the linq classes
none the less - i've managed to get it to work by creating a local variable containing the value of s[PUBNO] and using that instead...
//dennis