Unable to bind parameter in Insight.Database - oledb

I am trying to bind a parameter to a SQL query in my repository but having an error
public IList<Movie> FindMovieById(int movieId)
{
return Database.Connection().QuerySql<Movie>("select * from myDB.movies where ID=?", new { movieId });
}
I get an OleDb exception.
SQL0313: Number of host variables not valid.
Cause . . . . . : The number of host variables or entries in an SQLDA or descriptor area specified in either an EXECUTE or OPEN statement is not the same as the number of parameter markers specified in the prepared SQL statement S000001. If the statement name is *N, the number of host variables or entries in a SQLDA or descriptor area was specified in an OPEN statement and is not the same as the number of host variables specified in the DECLARE CURSOR statement for cursor C000001. Recovery . . . : Change the number of host variables specified in the USING clause or the number of entries in the SQLDA or descriptor area to equal the number of parameter markers in the prepared SQL statement or the number of host variables in the DECLARE CURSOR statement. Precompile the program again.
I have used ? for parameter binding as OleDb has positional parameters which are denoted by '?' rather the '#parameterName'.
Any help is appreciated.

Using Insight.Database can you try this?
return Database.Connection().QuerySql<Movie>(
"select * from myDB.movies where ID=#movieId",
new { movieId = movieId });

In order for Insight to map queries to objects, it binds parameters by name, not by position.
Your parameter object can be an anonymous type. If you specify:
new { movieId }
I believe the compiler will generate a property with the name "MovieID"
In that case, your parameter should be called #movieId.
If your database doesn't support named parameters, please open an issue up on github and I can take a look at it.
https://github.com/jonwagner/Insight.Database/issues

Related

How to pass arbitrary data between the C module callbacks in FreeRADIUS

What is the proper/recommended method to pass data between the callbacks in a C module in FreeRADIUS?
For example, I want to create a unique request_id for the request and use it for all log entries during that request. If I create this value inside mod_authorize, how do I pass it over to mod_authenticate on the same request thread, and how do I retrieve it?
static rlm_rcode_t CC_HINT(nonnull) mod_authorize(void *instance, REQUEST *request)
{
// Generate uuid
uuid_t uuid;
uuid_generate_random(uuid);
// Convert to a string representation
char *request_id = talloc_array(mem_ctx, char, UUID_STR_LEN);
uuid_unparse(uuid, request_id);
// Do stuff and log authorize messages
radlog(L_INFO, "request_id inside mod_authorize: %s", request_id);
// How do I pass request_id to mod_authenticate callback
// ?????????????
return RLM_MODULE_OK;
}
static rlm_rcode_t CC_HINT(nonnull) mod_authenticate(void *instance, REQUEST *request)
{
char *request_id = NULL;
// How do I retrieve the request_id value
// ???????????????????
// Do stuff and log authenticate messages
radlog(L_INFO, "request_id inside mod_authenticate: %s", request_id);
return RLM_MODULE_OK;
}
Attaching the value to the request object seems like a logical thing, but I don't see a way of doing it, other than adding a value pair to the request->reply (and I don't want to return this value to NAS).
Thank you.
Apparently, there is a range of "Temporary attributes, for local storage" (defined in the dictionary.freeradius.internal file) that can be used with one of the requests object's collections (request->config, request->reply->vps and request->packet->vps). You can find the start of this range by searching dictionary.freeradius.internal file in the FreeRADIUS repository for
ATTRIBUTE Tmp-String-0
In this case I found request->packet->vps to be appropriate, and used Tmp-String-3 to add my request_id to it while inside MOD_AUTHORIZE callback:
pair_make_request("Tmp-String-3", request_ctx->request_id, T_OP_EQ);
where pair_make_request is a macro defined as
fr_pair_make(request->packet, &request->packet->vps, _a, _b, _c)
I then retrieved it, while inside MOD_AUTHENTICATE callback:
VALUE_PAIR *vp = fr_pair_find_by_num(request->packet->vps, PW_TMP_STRING_3, 0, TAG_ANY);
The numerical values of these attributes change between the versions, you must use macro definitions instead
The macros for these attributes, such as PW_TMP_STRING_3 in the esample above, are located in the file "attributes.h" which is auto-generated during the build. Here is a quote from Arran Cudbard-Bell, that I found here:
If you really want to know where each one is used, download,
configure, build the source. Then see src/include/attributes.h for the
macro versions, and grep -r through the code. That'll at least tell
you the modules, and if you're familiar with C you should be able to
figure out how/when they're added or checked for. – Arran Cudbard-Bell
Apr 12 '15 at 20:51
In my case, the resulting file is located at /usr/include/freeradius/attributes.h
I must say that it took me unreasonable amount of effort to track this information down. There is no other trace, none whatsoever, of these attribute macros. Not in the code, not in the FreeRADIUS documentation, not in Google search results.

Disable Node in CANoe using CAPL

I am trying to disable a CAN node from sending messages. I have a function defined in CANoe:
long ILNodeControlStop(char aNodeName[])
When I try to use this in my CAPL script it shows type of parameters do not match. The error might be a very simple one, but I am not able to find it.
Suppose my node name is BECM. So I will use it as,
on start
{
//some variables;
}
on key 'a'
{
ILNodeControlStop(BECM);
}
This throws an error 'Type of parameters do not match'. Do I have to declare something in variables section ? (Using Node layer IL functions)
Pay attention to the parameter type. It is not dbNode, it is char array.
So you have to pass it as a char array (string in common language).
ILNodeControlStop("BECM");
Also, consider using the ILStartSim(), ILStopSim() variants, check out their help and their availability.

F# constructor with <"string", str>

In this article it shows how to use the SqlCommandProvider type. The sample code has this:
use cmd = new SqlCommandProvider<"
SELECT TOP(#topN) FirstName, LastName, SalesYTD
FROM Sales.vSalesPerson
WHERE CountryRegionName = #regionName AND SalesYTD > #salesMoreThan
ORDER BY SalesYTD
" , connectionString>(connectionString)
what does the <... ,...> before the type constructor name mean and why the the
first parameter have to be a string literal? It looks like a generic but it's taking variables not types. The constructor seems to be taking in a connection string already in the <> section.
The angle brackets are the configuration for a type.
In your example, you are defining a type and creating an instance at the same type. It's clearer when the steps are separated.
Define a type.
type SalesPersonQuery = SqlCommandProvider<query, connectionString>
But to actually have an instance of the type you have to create it:
let command = new SalesPersonQuery()
Now you can use the command.Execute() rather then SalesPersonQuery.Execute().
The reason there is a constructor is because later on (at run-time) you can change the connection string to a different then the one provided in the definition, so for instance:
let command = new SalesPersonQuery(differentConnectionString)
You can find that in the documentation in configuration section:
Connection string can be overridden at run-time via constructor optional parameter
First parameter can be a path to a SQL script or a SQL query. I suppose that's the reason it's a string: how else would you like to define a SQL query?
Again, from the documentation:
Command text (sql script) can be either literal or path to *.sql file

Lua script for scan with 'match' and 'count' constraints

I am using Jedis. I need a Lua script to scan for a pattern with a specified limit. I don't know how to pass the parameters inside Lua script.
Sample Code:
String script="return {redis.call('SCAN',KEYS[1],'COUNT',KEYS[2],'MATCH',KEYS[3]}";
List<String> response = (List<String>)jedis.eval(script,cursor,COUNT,pattern);
How do I pass these parameters to the script?
Your code has several points to fix.
In scan command, 'match' parameter should be placed prior to 'count'.
You should only use KEYS when it is a place for Redis key. Other things should be represented to ARGV.
You forgot to specify key count while calling Jedis.eval().
So, fixed version of your code is,
String script="return {redis.call('SCAN',ARGV[1],'MATCH',ARGV[2],'COUNT',ARGV[3])}";
List<String> response = (List<String>)jedis.eval(script, 0, cursor, pattern, COUNT);
But I agree Itamar to use Jedis.scan() instead.
Hope this helps.

adding a where clause to sql statement

I am trying to filter data from a table using sql as follows:
$select= new \Zend\Db\Sql\Select ;
$select->from('questions');
$select->where(array('questions.id'=>$value));
$select->columns(array('user_id','description'));
$select->join('users', "users.id = questions.user_id", array('username','password'), 'left');
echo $select->getSqlString();
$resultSet = $this->tableGateway->selectWith($select);
return $resultSet;
Without the $select->where(array('questions.id'=>$value)); the query executes okay and i can get all database values. Otherwise if i add the statement i get this error:
Attempting to quote a value without specific driver level support
can introduce security vulnerabilities in a production environment.
How can i rectify this for the where clause to work?
You'll probably find that it's echoing the SQL string which is generating that error. Assuming you only did that for debugging, removing that line should fix it. Alternatively you can pass the platform object to the function with something like:
echo $select->getSqlString($this->tableGateway->getAdapter()->getPlatform());

Resources