JdbcPollingChannelAdapter setUpdateSql - binding parameter wrapped with quotes - spring-integration

I need to wrap the parameter with quotes in query.
=':param'
JdbcPollingChannelAdapter adapter = new JdbcPollingChannelAdapter(...
adapter.setUpdateSql("..COL =':param'");
adapter.setUpdateSqlParameterSourceFactory(...)
If I add quote parameter is not replaced, if i remove the quotes parameter replaced - but I must have the quotes.
The type of bounded filed is long.
Tried different wrappings.

If it has to be with quotes, then the result of param evaluation has to be quoted.
Or it looks like it has to be evaluated to String, not long as you mention. The query binding doesn't work like you expect. It really has to be a top-level instruction for the query processor to let it to bind the value properly from the template.
See if ExpressionEvaluatingSqlParameterSourceFactory can help you somehow to evaluate the result of :param to expected quoted value: https://docs.spring.io/spring-integration/docs/current/reference/html/jdbc.html#jdbc

Related

How to read visual studio code intellisense syntax hint, any document for operators?

VSC like VS gives out syntax/signature hint. I understand : means data type
myText: string // : means datatype of myText is string
myStuff: any // any means can be any data type.
sometimes hard to guess what the operators mean, for example the Node's request(),
my understanding is
const request means I can define any variable like const x=request(...) or var x=request(...).
request.RequestAPI means it's an API call.
options: defines this parameter is a typical object-like options in form of {...}
(request.UriOptions & request.CoreOptions) I understand the beginning and end parts, they must be enum of Uri and Core, but what is &? Does it mean I need to supply both Uri AND Core?
| does this pipe mean OR? If it is then it's duplicating the part before the pipe.
callback?: request.RequestCallback, so here I must provide a callback which will be typed (or functioning) as RequestCallback, but what is ?:?
Is there any document for these conventions?
I wanted to comment, because I don't know the complete answer, but here is some helpful information:
You are probably seeing this definition of DefinitelyTyped: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/request/index.d.ts#L29
Have a look at this to understand the definition file syntax: http://www.typescriptlang.org/docs/handbook/declaration-files/by-example.html
And you can interpret the definition like this:
const request: there is a constant named request that implements the interface request.RequestAPI (which is also callable directly and then for that) takes arguments options of type (request.UriOptions & request.CoreOptions) | (request.UrlOptions & request.CoreOptions) and an optional parameter callback (hence the ? of type request.RequestCallback. The function returns a request.Request.
& usually mean and
A pipe | usually means or, there is no duplication URI vs URL
=> "returns"
You see request in front of everything because it's the namespace (my wording may be off here)
The definitions of UriOptions, UrlOptions, CoreOptions are buried a bit. I'm not a node user, so I don't know what you can pass to request.
For example UrlOptions can either be a string argument named "url" or a url (from require('url')). See https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/request/index.d.ts#L162

What's the difference in TWIG between using the attribute() function and using brackets

I'm trying to understand twigs attribute() function, because it seems to me that this
attribute(object, parameter)
and this
object[ parameter ]
Would do the same thing. They return the value of that parameter in the object. I realize that brackets can also be used to get a value from an array with an index, but if the parameter is a string it seems to get the value from the parameter just as well. What else does attribute() do that Im missing?
The attribute function can also be used to call methods of objects and enables you to pass arguments towards it
{{ attribute(object, method, arguments) }}

How can I pass a structure down a tree (i.e. an inherited attribute) when using Visitor pattern?

I'm using the C++ version of ANTLR4 to develop a DSL for a music product. I used to (30 years ago!) do this kind of thing by hand so it's mostly a pleasure to have something like ANTLR, particularly now that I don't have to insert code in the actual grammar definition itself.
I want to do type checking of actual vs formal args in a function call. In the grammar segment below, the 'actualParameter' can return the type of the expression. However, the 'actualParameterList' needs to return an array (say) of these types so that the code for functionCall can compare to the formal parameter list.
If I was handwriting this, the calls to visit or visitChildren would take an extra parameter after context such that I could create a new array at the appropriate place and then have child nodes fill in the details.
I suppose that instead of just calling visitChildren inside the 'visitActualParameterList' I could create the array there and manually call each child rather than just a simple visitChildren but that feels like a hack, and it becomes very sensitive to minor changes in the grammar.
Is there a better approach?
functionCall: Identifier LeftParen actualParameterList? RightParen
;
actualParameterList:
actualParameter anotherActualParameter
;
actualParameter:
expression
;
anotherActualParameter:
Comma actualParameter anotherActualParameter
|
;
You're on the right path. I would suggest something like:
functionCall: Identifier LPAREN actualParameterList RPAREN
;
actualParameterList:
actualParameter (',' actualParameter)*
;
actualParameter:
expression
;
LPAREN : '(';
RPAREN : ')';
Using this, in the Visitor for actualParameterList you can check each child to see if it's of type actualParameterContext and if so, explicitly call Visit on that child, which will get you into your expression evaluation code (presumably handled in the visitor for actualParameter). This alleviates the need, as you say, to just generically visit children. It's very precise when you can check the type like this.
Here's an example of this pattern from my own code (in C# but surely you'll see the pattern in action):
for (int c = 0; c < context.ChildCount; c++)
{
if (context.GetChild(c) is SystemParser.ServerContext) // make sure correct type
{
string serverinfo = Visit(context.GetChild(c)); // visit the specific child and save return value, string in this case
sb.Append(serverinfo); // use result to fill array or do whatever
}
}
Now that you can see the pattern, back to your code. The syntax:
actualParameter (',' actualParameter)*
means that a parameter list has one actualParameter followed by zero or more additional ones with the * operator. I just threw the comma in there for visual clarity.
As you suggest, Visitor is the perfect pattern for this because you can explicitly visit any node you need to. It won't give you an array, but you can fill an array or any other necessary structure with the results of the visiting the children as you saw in the snip from my code. My Visitor returns strings, and I just appended to a StringBuilder. You can use the same pattern to build whatever you need.

Interpolating values in HTML attributes - Pug (Jade)

I am trying to construct an anchor tag with a dynamic href attribute in Jade.
I did go through the docs and some SO questions but they didn't help me. This is what I tried.
a(href= "http://www.imdb.com/title/#{movie.imdb_id}") Know more
But it renders
http://www.imdb.com/title/#{movie.imdb_id}
rather than
http://www.imdb.com/title/tt1234567
However this works
a(href= "http://www.imdb.com/title/" + movie.imdb_id) Know more
and this too.
- var url = "http://www.imdb.com/title/" + movie.imdb_id;
a(href= url) Know more
What's wrong with the first version?
Interpolation is only available in text.
You need to use JS string concatenation for attributes:
a(href="http://www.imdb.com/title/" + movie.imdb_id) Know more
If you JavaScript runtime supports ES2015 template string, you can also use them (notice the backticks):
a(href=`http://www.imdb.com/title/${movie.imdb_id}`) Know more
Reference
the pug variable declaration doesnt work in this case using #{...}
the right syntax goes this way,
a(attributes) Know more
a(href="http://www.imdb.com/title/"+ movie.imdb_id) Know more
the attributes is an expression so it renders correcly, or you could use ES5 template literals with back quotes to render the variable along side the text which becomes
a(href=`http://www.imdb.com/title/${movie.imdb_id}`) Know more
note that when using back quotes with template literals your variable expression are enclosed in parenthesis and a leading $ sign, that is ${..expression..}
When you quote it simply tells pug "this is a string". That's basic JS. Interpolation works with #{'#{interpolation}'} too! is an example which renders "Interpolation works with #{interpolation} too!"
I don't have any knowledge about pug(jade)
But my guess is "a(your code)" is already a signal to pug(jade) that it is in the controller's scope already.. and "{variable}" is also an indicator that you are accessing controller's scope. so
a(href= "http://www.imdb.com/title/#{movie.imdb_id}") Know more
for "{}" inside a() is no longer an indicator that your are trying to access controller's scope because you're already in the controller's scope.. so "{}" inside a() is just a string, {movie.imdb_id} is part of the link string.
So in order for the framework to identity that movie.imdb_id is a variable, you should separate it from the actual string.
NOTE: This is just a guess..I'm using angular

Why doesn't calling repr on type objects work as expected?

First, let me say that I agree that eval(repr(some_string)) is potentially a bad idea. But it is a thing that exists, and I have a specific question about it.
Why doesn't this work?
my_type = int
my_type_str = repr(int)
my_type_from_str = eval(my_type_str)
To clarify, I know specifically why the eval call fails. The command repr(int) produces a string which cannot be automatically interpreted. I guess my issue is that this isn't behaving as I expect... so either my expectation is faulty or the implementation is faulty. Which is it?
Side Note
There are some tricks that can be used to get around this default behavior, some obvious, some not. For instance, this:
my_type = int
my_type_str = my_type.__name__
my_type_from_str = eval(my_type_str)
assert my_type is my_type_from_str
This sets off my "hack" alert hardcore, and I don't like it (or other similar hacks, for instance parsing the string "<class 'int'>" with some home made function).
The documentation explains:
Return a string containing a printable representation of an object. For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to eval(), otherwise the representation is a string enclosed in angle brackets that contains the name of the type of the object together with additional information often including the name and address of the object. A class can control what this function returns for its instances by defining a repr() method.
(emphasis mine)
So, it doesn't say that repr must always return valid Python code - sometimes it's not the case. Just another argument for not relying on it.

Resources