MVC jqGrid Small Integer Error - asp.net-mvc

This article is really great and awesome. This is from the topic "ASP.NET MVC 2.0 Implementation of searching in jqgrid" - ASP.NET MVC 2.0 Implementation of searching in jqgrid.
But right now I was facing searching problem when I added a field with small integer data type. The field added with data type of small integer will serve as Status.
Lets say the value one(1) is for Active and value two(2) is for Inactive.
When I type 1 or 2 from the text box it was throwing an error of
System.Data.Entity: The argument types 'Edm.Int16' and 'Edm.String' are incompatible for this operation. Near equals expression, line 6, column 12.
Thank you in advance.

I am glad that my old answer was helpful for you. I suppose you have problem near the line
// TODO: Extend to other data types
In the code which I included in the answer I shown that propertyInfo.PropertyType.FullName hold the information about the datatype of the entity's property. In the code I used only two types: string and 32-bit integer. In case of 32-bit integers I made the corresponding data parsing with respect of Int32.Parse:
String.Compare (propertyInfo.PropertyType.FullName,
"System.Int32", StringComparison.Ordinal) == 0 ?
new ObjectParameter ("p" + iParam, Int32.Parse(rule.data)
You should replace " ? : " operator with case where you test propertyInfo.PropertyType.FullName for more data types. For example in case of smallint SQL type you should use System.Int16, in case of tinyint it should be System.Byte, The sbyte SQL datatype corresponds to System.SByte and so on. If you would use as the second parameter of ObjectParameter correct datatype all should work correctly

Related

Pass an empty value to an OData V2 Edm.Time property

I have a variable type time but sometimes this variable doesn't have anything.
When it is initial, it shouldn't be "000000", I want an empty value without anything (no zeros). Let me explain my problem with the code:
IF lwa_hora IS INITIAL.
CLEAR lwa_hora.
ls_entity-hora = lwa_hora. " Result: 000000 but I don't want any zero
ELSE.
ls_entity-hora = lwa_hora. " Result: 000000
ENDIF.
I tried with CLEAR but nothing happens.
I need this is because in the JavaScript frontend client logic, I need the OData property to contain a falsy value (E.g. null or an empty string "").
But it always has the value "000000" which is not an empty string. Is it possible to make something in the backend to "clear" the variable?
The time data-type in abap (t) is a value-type. It's internally implemented as an integer counting the seconds since midnight. 0 seconds since midnight is a valid value, so it can't have a null-value.
However, ABAP allows you to create a reference to any value-type:
hora TYPE REF TO t.
That means hora will be a reference to a variable of TYPE t. Initially, this reference will be unbound, which is conceptually very similar to a null-reference in other programming languages. You can check that with:
IF ls_entity-hora IS BOUND.
...
IF ls_entity-hora IS NOT BOUND.
You can assign a time value with GET REFERENCE OF lwa_hora INTO ls_entity-hora. But now you have a reference to an existing variable. Change the value of lwa_hora, and the value of ls_entity-hora also changes. That might not always be what you want. So it might be better to create a new piece of data in memory for our reference to point to:
CREATE DATA ls_entity-hora.
Now ls_entity-hora is no longer unbound (or "null" if you want to call it that), it points to a new time-value of 000000. If you want to read or change the value of this nameless piece of data this reference points to, then you can do this with the dereferencing-operator ->*:
ls_entity-hora->* = lwa_hora.
If you intentionally want to set a reference to unbound (or "set the reference to null"), you can do that by clearing the reference:
CLEAR ls_entity-hora.
By the way: Representing a point in time by two separate variables of the types d and t fell out of fashion in the past decade. The current best practice for this situation is to use a single variable of type TIMESTAMP (if you need second precision) or TIMESTAMPL (if you need microsecond precision). A timestamp of 00000000000000 is obviously an illegal value, so it can be used to represent the absence of a point in time. This type also usually makes it much easier to communicate with a SAPUI5 frontend (like in your case), because many of the technologies for making oData services offer automatic conversion between Javascript Date and ABAP TIMESTAMP.
An alternative to heap allocating the time would be to store a boolean next to it, indicating whether it is set or not:
TYPES:
BEGIN OF optional_time,
time TYPE t,
is_null TYPE abap_bool,
END OF optional_time.
DATA(no_time) = VALUE optional_time( is_null = abap_true ).
" Setting to null:
DATA(some_time) = no_time.
" Setting to some time:
some_time = VALUE #( time = '12:30' ).
IF some_time = no_time.
" ...
ENDIF.
This sort of things is probably better to handle on front-end than on back-end.
SAP Gateway serializes ABAP Date/time initial values to NULL in the OData response if the corresponding property is nullable. You need to make sure this property is set to TRUE like in this sample
you can also set this property in runtime
TRY .
lo_action = model->get_entity_type( iv_entity_name = 'Z_REPORTType').
lo_property = lo_action->get_property( iv_property_name = 'Requested_Date').
lo_property->set_nullable( iv_nullable = abap_true ).
CATCH /iwbep/cx_mgw_busi_exception /iwbep/cx_mgw_med_exception /iwbep/cx_mgw_tech_exception INTO DATA(lo_exception).
ENDTRY.

What is the correct designation for values of discriminated union types?

Consider this type definition:
type ChoiceOne =
| A
| B
and this binding
let c1 = A
I assume the correct way to translate this into natural language would be "the value A of type ChoiceOne is constructed and bound to the name c1".
Now take a look at this next type definition and binding:
type ChoiceTwo =
| A of int
| B of float
let c1 = A 1
I now see several ways of describing what is going on here:
"the value A of type ChoiceTwo is constructed ..." ( and what about the 1 ? )
"the value 1 of type ChoiceTwo is constructed ..." ( and what about the A ? )
"the value A of type ChoiceTwo with the ( inner value ? associated value ? ... ) 1 is constructed ..."
I guess option 3 describes the situation best, but how can I correctly designate the value 1 with respect to the (other?) value A of type ChoiceTwo ?
Here's the terminology that I use, which I believe is widely accepted, using my own example:
type MyDU =
| A of int
| B
A is a case
A is also a function that takes an int and returns a value of type MyDU
Therefore, A 1 is a value of type MyDU
B is a case
B is also a value of type MyDU
The only words needed here are "case", "value", "function" and "type". Don't use the word "construct". In general, when talking about F# code, if you can accurately replace any words that you use with the ones that I recommend, then do so!
This is all splitting hairs. Nobody really cares about how exactly to say these things outside of a quiz in college, and even then, I would recommend maybe transferring to a different college :-)
But if you really want to split hairs, here we go.
In your very first example, the value A is not "constructed". Since it doesn't have parameters, there can be only one instance of it, and that instance always exists, so there is no need to "construct" it.
To be sure, A may still be referred to as a "constructor", but it's also a "value" at the same time.
In the second example, it is sometimes said that "a value A 1 was constructed", but more often "a value A constructed with parameter 1"

cast a column in $filter using Odata v3

I'm trying to do a cast on a query but it's throwing me a error 500
http://source/service/odata.svc?$filter=(cast(Value,'Edm.Int32') eq 1)
Where column 'Value' is a Edm.String
Note that i'm using v3 of OData
I think you may get error message like from service:
No coercion operator is defined between types 'System.String' and 'System.Nullable`1[System.Int32]'.
Which was thrown by Linq's Expression.Convert, which does try to convert a string value to int value.
This is because numeric types are only supported to be cast to numeric types. (This was explicitly called out in v4 spec 5.1.1.4.29 cast).
Please also note that other strong typed languages would also not allow 'CAST' from string to int directly. Thus the following code won't compile:
string a = "3";
int b = (int) a;
A better solution could be manually casting the const here:
http://source/service/odata.svc?$filter=Value eq '1'

Is there a name for expressions that return what they are, instead of a reference?

I've noticed that strings, numbers, bool and nil data seem to be straight forward to work with. But when it comes to functions, tables, etc. you get a reference instead of the actual object.
Is there a name for this phenomenon? Is there terminology that describes the distinction between the way these 2 sets of types are handled?
a = "hi"
b = 1
c = true
d = nil
e = {"joe", "mike"}
f = function () end
g = coroutine.create(function () print("hi") end)
print(a) --> hi
print(b) --> 1
print(c) --> true
print(d) --> nil
print(e) --> table: 0x103350
print(f) --> function: 0x1035a0
print(g) --> thread: 0x103d30
What you're seeing here is an attempt by the compiler to return a string representation of the object. For simple object types the __tostring implementation is provided already, but for other more complex types there is no intuitive way of returning a string representation.
See Lua: give custom userdata a tostring method for more information which might help!
.Net (Microsoft Visual Basic, Visual C++ and C#) would describe them as value types and reference types, where reference types refer to a value by reference and value types hold the actual values.
I don't think lua puts too much thought into it given that it's supposed to be a simpler interpreted language and ultimately it doesn't matter as much because lua is a fairly weakly typed language (ie it doesn't enforce type safety beyond throwing an error when you try to use operations on types they can't be used on).
Either way, most programmers in my experience understand them as 'value types' and 'reference types', so I'd say they're the two terms it's best to stick with.
In Lua, numbers are values, everything else is accessible by reference only. But the different behavior on print is just because there's no way to actually print functions (and while tables could have a default behavior for print, they don't - possibly because they're allowed to have cyclic references).
What you are seeing is the behavior of the print function. It will its arguments by using tostring on them. print could be implemented by using io.write like this (simplified a bit):
function print(...)
local args = {n = select('#',...), ...}
for i=1,args.n do
io.write(tostring(args[i]), '\t')
end
io.write('\n')
end
You should notice the call to tostring. By default it returns the representation of numbers, booleans and strings. Since there is no sane default way to convert other types to a string, it only displays the type and a useless internal pointer to the object (so that you can differentiate instances). You can view the source here.
You will be surprised, but there is no value/reference distinction in Lua. :-)
Please read here and here.

Custom Array Functions in Open Office Calc

Could someone please tell me how to write a custom function in Open Office Basic to be used in Open Office Calc and that returns an array of values. An example of one such built-in function is MINVERSE. I need to write a custom function that populates a range of cells in much the same way.
Help would be much appreciated.
Yay, I just figured it out: all you do is return an array from your macro, BUT you also have to press Ctrl+Shift+Enter when typing in the cell formula to call your function (which is also the case when working with other arrays in calc). Here's an example:
Function MakeArray
Dim ret(2,2)
ret(0,0) = 1
ret(1,0) = 2
ret(0,1) = 3
ret(1,1) = 4
MakeArray = ret
End Function
FWIW, damjan's MakeArray function returns a Variant containing an array, I think. (The type returned by MakeArray is unspecified, so it defaults to Variant. A Variant is a container with a descriptive header, apparently cast as needed by the interpreter.)
Almost, but not quite, the same thing as returning an array. According to http://www.cpearson.com/excel/passingandreturningarrays.htm, Microsoft did not introduce the ability to return an array until 2000. His example [ LoadNumbers(Low As Long, High As Long) As Long()] does not compile in OO, flagging a syntax error on the parens following Long. It appears that OO's Basic emulates the pre-2k VBA.

Resources