Dapper - splitOn doesn't exist - stored-procedures

I'm trying to execute this snippet
var dParams = new DynamicParameters();
dParams.Add("#ShipDate", warranty.ShipDate);
dParams.Add("#WarrantyStartDate", warranty.WarrantyStartDate);
dParams.Add("#WarrantyEndDate", warranty.WarrantyEndDate);
dParams.Add("#SerialNumber", warranty.SerialNumber);
var result = conn.Query<Warranty>("TMP_WARRANTY_INFORMATION_insert", dParams ,commandType: CommandType.StoredProcedure).First();
But then it says "When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id", so I try to add a splitOn parameter, but I can't seem to do it according to how the docs/internet says it should, and intellisense can't find the param.
Am I doing something wrong or is it Dapper?

I got it working. I switched from .Query to .Execute, and changed some of the params
var dParams = new DynamicParameters();
dParams.Add("#ShipDate", warranty.ShipDate, DbType.String, ParameterDirection.Input);
dParams.Add("#WarrantyStartDate", warranty.WarrantyStartDate, DbType.String, ParameterDirection.Input);
dParams.Add("#WarrantyEndDate", warranty.WarrantyEndDate, DbType.String, ParameterDirection.Input);
dParams.Add("#SerialNumber", warranty.SerialNumber, DbType.String, ParameterDirection.Input);
var result = conn.Execute("TMP_WARRANTY_INFORMATION_insert", dParams ,commandType: CommandType.StoredProcedure);

Related

Combine/merge multiple maps into 1 map

How can I combine/merge 2 or more maps in dart into 1 map?
for example I have something like:
var firstMap = {"1":"2"};
var secondMap = {"1":"2"};
var thirdMap = {"1":"2"};
I want:
var finalMap = {"1":"2", "1":"2", "1":"2"};
you can use addAll method of Map object
var firstMap = {"1":"2"};
var secondMap = {"2":"3"};
var thirdMap = {};
thirdMap.addAll(firstMap);
thirdMap.addAll(secondMap);
print(thirdMap);
Or
var thirdMap = {}..addAll(firstMap)..addAll(secondMap);
Update
Since dart sdk 2.3
You can use spread operator ...
final firstMap = {"1":"2"};
final secondMap = {"2":"3"};
final thirdMap = {
...firstMap,
...secondMap,
};
alternate syntax using Map.addAll, Iterable.reduce and cascading operator, for combining a lot of maps:
var combinedMap = mapList.reduce( (map1, map2) => map1..addAll(map2) );
live dartpad example
https://dartpad.dartlang.org/9cd116d07d2f45a9b890b4b1186dcc5e
Another option is using CombinedMapView from package:collection:
new CombinedMapView([firstMap, secondMap])
It doesn't create a merged map, but creates a Map that is a view of both.
I came up with a "single line" solution for an Iterable of Maps:
var finalMap = Map.fromEntries(mapList.expand((map) => map.entries));
var firstMap = {"1":"5"};
var secondMap = {"1":"6"};
var thirdMap = {"2":"7"};
var finalMap = {...firstMap, ...secondMap, ...thirdMap};
// finalMap: {"1":"6", "2":"7"};
Notice that key "1" with value "5" will be overwritten with "6".

Issue using the “count” Parameter in the new Twitter Search API 1.1

I am having issues including the count parameter in the new Twitter Search API (Version 1.1) query. If I execute the query without the “count” parameter, I obtain the 15 default results. Meanwhile, if I include the count parameter, I obtain a 401 Unauthorized Error.
You will find hereafter, partial extracts from my code in C#.
1) Initially, the end of the baseString variable is set to “q=Test&count=100”.
2) After passing the baseString variable to the EscapeDataString function, the end becomes q%3DTest%26count%3D100, formatted in percent encoding, as expected.
3) Finally, the resource_url submitted is the following:
https://api.twitter.com/1.1/search/tweets.json?q=Test&count=100
var resource_url = "https://api.twitter.com/1.1/search/tweets.json";
var baseFormat = "oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&q={6}&count={7}";
var baseString = string.Format(baseFormat,
oauth_consumer_key,
oauth_nonce,
oauth_signature_method,
oauth_timestamp,
oauth_token,
oauth_version,
Uri.EscapeDataString(q),
Uri.EscapeDataString(count)
);
baseString = string.Concat("GET&", Uri.EscapeDataString(resource_url), "&", Uri.EscapeDataString(baseString));
var postBody = "q=" + Uri.EscapeDataString(q) + "&count=" + Uri.EscapeDataString(count);
resource_url += "?" + postBody;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(resource_url);
Would anyone have an idea why I am receiving this 401 Error?
I had similar issues, it seems when you Generate OAuth signature Twitter is fussy about the format of this string. I found even re-ordering the variables cause authentication errors.
Try replacing the specific lines in your code with the re-ordered ones below, hope that helps.
var resource_url = "https://api.twitter.com/1.1/search/tweets.json";
var tweet_query = "Test";
var tweet_count ="5";
var baseFormat = "count={7}&oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&q={6}";
var baseString = string.Format(baseFormat,
oauth_consumer_key,
oauth_nonce,
oauth_signature_method,
oauth_timestamp,
oauth_token,
oauth_version,
Uri.EscapeDataString(tweet_query),
Uri.EscapeDataString(tweet_count)
);
var postBody = string.Format("q={0}&count={1}", Uri.EscapeDataString(tweet_query), Uri.EscapeDataString(tweet_count));
#JF0001
yes i have the same issue, but johnHk already have the correct answer. it's just placement issue.
when i use this, it doesn't work :
base_Format = "oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}" + "&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&q={6}&result_type={7}&count={8}"
but if i use this, it's work :
base_Format = "count={8}&oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}" + "&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&q={6}&result_type={7}"
look at the "count=" parameter, haha just re-order it into the first place.

Geting DataTime from database through Javascript

I have a MVC Web Application Im trying to Ajax call an action method to retrieve some datetime from the database, the problem is the value comes as "/Date(386028000000)/"
its a DateOfBirth actually which I m using a java script function to calculate the age:
function (DOB) {
var birthday = +new Date(DOB);
return ~~((Date.now() - birthday) / (31557600000));
}
Anyway i can fix the Date Format and get only the date in a proper format or change the Java-Script method to accept the current format of the date value ?
I got it
var FixedDate = new Date();
FixedDate .setTime(DOB.replace("/Date(", "").replace(")/", ""));
return ~~((Date.now() - FixedDate) / (31557600000));
Click here to check the Demo
Sample Javascript/JQuery
var = MyDate_String_Value = "/Date(386028000000)/"
var value = new Date
(
parseInt(MyDate_String_Value.replace(/(^.*\()|([+-].*$)/g, ''))
);
var dat = value.getMonth() +
1 +
"/" +
value.getDate() +
"/" +
value.getFullYear();
Result - "3/27/1982"

PetaPoco and output parameters from stored procedures?

I'm trying to setup an output parameter using PetaPoco. I found someone using this sample online:
var ctx = new CustomDBDatabase();
var total = new SqlParameter("Total", System.Data.SqlDbType.Int);
total.Direction = System.Data.ParameterDirection.Output;
var results = ctx.Query<DBEntity>("exec GetDBEntities #StartIndex, #MaxIndex, #TotalCount = #Total out",
id, start, max, total);
int totalCount = (int)total.Value;
However, total.value returns null, even though when I run this statement directly against SQL Server, it returns me 3. Is this setup correctly with PetaPoco? Are output parameters supported?
Thanks.
This is supported. But your current syntax is wrong anyways.
var ctx = new CustomDBDatabase();
var total = new SqlParameter("TotalCount", System.Data.SqlDbType.Int);
total.Direction = System.Data.ParameterDirection.Output;
var results = ctx.Query<DBEntity>("exec GetDBEntities #StartIndex, #MaxIndex, #TotalCount OUTPUT", new { StartIndex = start, MaxIndex = max, TotalCount = total});
int totalCount = (int)total.Value;
Something like this should work though. Not quite sure of the sql syntax but this should get you on your way.

Node.js url.parse result back to string

I am trying to do some simple pagination.
To that end, I'm trying to parse the current URL, then produce links to the same query, but with incremented and decremented page parameters.
I've tried doing the following, but it produces the same link, without the new page parameter.
var parts = url.parse(req.url, true);
parts.query['page'] = 25;
console.log("Link: ", url.format(parts));
The documentation for the URL module seems to suggest that format is what I need but I'm doing something wrong.
I know I could iterate and build up the string manually, but I was hoping there's an existing method for this.
If you look at the latest documentation, you can see that url.format behaves in the following way:
search will be used in place of query
query (object; see querystring) will only be used if search is absent.
And when you modify query, search remains unchanged and it uses it. So to force it to use query, simply remove search from the object:
var url = require("url");
var parts = url.parse("http://test.com?page=25&foo=bar", true);
parts.query.page++;
delete parts.search;
console.log(url.format(parts)); //http://test.com/?page=26&foo=bar
Make sure you're always reading the latest version of the documentation, this will save you a lot of trouble.
Seems to me like it's a bug in node. You might try
// in requires
var url = require('url');
var qs = require('querystring');
// later
var parts = url.parse(req.url, true);
parts.query['page'] = 25;
parts.query = qs.stringify(parts.query);
console.log("Link: ", url.format(parts));
The other answer is good, but you could also do something like this. The querystring module is used to work with query strings.
var querystring = require('querystring');
var qs = querystring.parse(parts.query);
qs.page = 25;
parts.search = '?' + querystring.stringify(qs);
var newUrl = url.format(parts);
To dry out code and get at URL variables without needing to require('url') I used:
/*
Used the url module to parse and place the parameters into req.urlparams.
Follows the same pattern used for swagger API path variables that load
into the req.params scope.
*/
app.use(function(req, res, next) {
var url = require('url');
var queryURL = url.parse(req.url, true);
req.urlparams = queryURL.query;
next();
});
var myID = req.urlparams.myID;
This will parse and move the url variables into the req.urlparams variable. It runs early in the request workflow so is available for all expressjs paths.

Resources