Hi all I am having some trouble with my PUT function and getting Invalid key predicate. I have never seen this error before and don't really know what it means. Can anyone see what I am doing wrong here?
Here is my code:
boxId = 1;
updateBox = {};
updateBox.x = 5;
updateBox.y = 10;
sap.ui.getCore().getModel("updateBoxModel").update("/Boxes(BoxId=" + boxId + ")", updateBox,
null, this.successMsg, this.errorMsg);
updateBoxLog = {};
updateBoxLog.x = 5;
updateBoxLog.y = 10;
sap.ui.getCore().getModel("updateBoxModel").update("/BoxLogs(BoxId=" + boxId + ")", updateBoxLog,
null, null, null);
The first update works as it should but the second doesn't work at all. Both tables are expecting a numeric value and not sure if this helps, but BoxLogs tables primary key isn't BoxId
If BoxId is an alternate key for BoxLogs, you're going to have to enable alternate keys on the OData service and write some supporting code. There is a sample project on github that should provide enough guidance.
Related
Via an enterpreise service consumer I connect to a webservice, which returns me some data, and also url's.
However, I tried all methods of the mentioned class above and NO METHOD seems to convert the unicode-characters inside my url into the proper readable characters.... ( in this case '=' and ';' ) ...
The only method, which runs properly is "is_valid_url", which returns false, when I pass url's like this:
http://not_publish-workflow-dev.hq.not_publish.com/lc/content/forms/af/not_publish/request-datson-internal/v01/request-datson-internal.html?taskId\u003d105862\u0026wcmmode\u003ddisabled
What am I missing?
It seems that this format is for json values. Usually = and & don't need to be written with the \u prefix. To decode all \u characters, you may use this code:
DATA(json_value) = `http://not_publish-workflow-dev.hq.not_publish.com/lc`
&& `/content/forms/af/not_publish/request-datson-internal/v01`
&& `/request-datson-internal.html?taskId\u003d105862\u0026wcmmode\u003ddisabled`.
FIND ALL OCCURRENCES OF REGEX '\\u....' IN json_value RESULTS DATA(matches).
SORT matches BY offset DESCENDING.
LOOP AT matches ASSIGNING FIELD-SYMBOL(<match>).
DATA hex2 TYPE x LENGTH 2.
hex2 = to_upper( substring( val = json_value+<match>-offset(<match>-length) off = 2 ) ).
DATA(uchar) = cl_abap_conv_in_ce=>uccp( hex2 ).
REPLACE SECTION OFFSET <match>-offset LENGTH <match>-length OF json_value WITH uchar.
ENDLOOP.
ASSERT json_value = `http://not_publish-workflow-dev.hq.not_publish.com/lc`
&& `/content/forms/af/not_publish/request-datson-internal/v01`
&& `/request-datson-internal.html?taskId=105862&wcmmode=disabled`.
I hate to answer my own questions, but anyway, I found an own solution, via manually replacing those unicodes. It is similar to Sandra's idea, but able to convert ANY unicode.
I share it here, just in case, any person might also need it.
DATA: lt_res_tab TYPE match_result_tab.
DATA(valid_url) = url.
FIND ALL OCCURRENCES OF REGEX '\\u.{4}' IN valid_url RESULTS lt_res_tab.
WHILE lines( lt_res_tab ) > 0.
DATA(match) = substring( val = valid_url off = lt_res_tab[ 1 ]-offset len = lt_res_tab[ 1 ]-length ).
DATA(hex_unicode) = to_upper( match+2 ).
DATA(char) = cl_abap_conv_in_ce=>uccp( uccp = hex_unicode ).
valid_url = replace( val = valid_url off = lt_res_tab[ 1 ]-offset len = lt_res_tab[ 1 ]-length with = char ).
FIND ALL OCCURRENCES OF REGEX '\\u.{4}' IN valid_url RESULTS lt_res_tab.
ENDWHILE.
WRITE / url.
WRITE / valid_url.
This is a piece of code I am trying to use to POST a set of 13 parameter values from the MQL4 script to an external php script, named upload.php
string headers = "Content-Type: application/x-www-form-urlencoded";
string data = "{\"ohlcVectors\":{\"ticker\":\"dax\",\"barIntervalSeconds\":300,\"open\":[6844.2998046875," +
"6847.7998046875]},\"className\":\"MAIndicator\",\"parameters\":{\"periods\":2}}";
string acceptTypes[1] = {"*/*"};
int HttpOpen = InternetOpenA( "HTTP_Client_Sample", 1, NULL, NULL, 0 );
int HttpConnect = InternetConnectA( HttpOpen, "127.0.0.1", 7777, NULL, NULL, 3, 0, 1 );
int HttpRequest = HttpOpenRequestA( HttpConnect, "POST", "/tradesheet/upload.php", NULL, NULL, acceptTypes, 0, 1 );
HttpSendRequestA( HttpRequest, headers, StringLen( headers ), data, StringLen( data ) );
The compiler keeps throwing an error that the data is an incompatible type. That data string was picked up from a site, when I was searching for ways for MQL4 to send POST params to a php. But I need that string data to have my own parameter values, but clueless on how to put it in the right format.
I tried searching quite a bit and just cant find anything helpful.
The following is the parameter list that I need to send to upload.php. Can someone please help me arrange in the format that HttpSendRequestA() is expecting it ?
string params[13][13];
params[0][0] = "x1";
params[0][1] = "GOD#GMAIL.com";
params[1][0] = "x2";
params[1][1] = 10000;
params[2][0] = "x3";
params[2][1] = 10000;
params[3][0] = "x4";
params[3][1] = "fxpro";
params[4][0] = "x5";
params[4][1] = "usd";
params[5][0] = "x6";
params[5][1] = 10000;
params[6][0] = "x7";
params[6][1] = 5000;
params[7][0] = "x8";
params[7][1] = 10;
params[8][0] = "x9";
params[8][1] = 10;
params[9][0] = "x10";
params[9][1] = "sdfskfms";
params[10][0] = "x11";
params[10][1] = 232;
params[11][0] = "x12";
params[11][1] = 230;
params[12][0] = "x13";
params[12][1] = "fxpro";
Thanks a ton
High chances you are using build 600.
Build 600 supports Unicode and not Ansi anymore.
therefore these are the functions you have to use:
InternetOpenW
InternetConnectW
HttpOpenRequestW
HttpSendRequestW
see below:
Mt4 b600 / ghttp.mqh and InternetOpenUrlA() problem
Ok so this is my scenario:
rascal>map[int, list[int]] g = ();
rascal>g += (1:[2]);
This will result in:
rascal>g[1];
list[int]: [2]
So far so good, but now I wanted to do this, but it didn't work:
rascal>g[1] += 3;
|stdin:///|(2,1,<1,2>,<1,3>): insert into collection not supported on value and int
So I can't directly use the value from g[1] and will have to use a temporary variable like this:
rascal>lst = g[1];
rascal>lst += 3;
rascal>g[1] = lst;
map[int, list[int]]: (1:[2,3])
But doing this everytime I want to extent my list is a drag!
Am I doing something wrong or would this be an awesome feature?
Richard
Good question! + on lists is concatenation not insert, so you could type the following to get the desired effect:
g[1] += [2];
I'm trying to get the count of plus one's I have for google plus, I am checking to see if I have the count right with this
https://plusone.google.com/u/0/_/%2B1/fastbutton?count=true&url=MY_URL
I see that google plus rejects my URL (doesn't return 0 or anything)
I wanted to know if anyone can tell me if I have anything wrong in my url, I have these symbols in my url outside of letters and numbers
:
/
.
?
=
&
_
and my url is formatted like this
(protocol)://(server [such as www]).(domain)/(text).php?(text)=(text)&(text)=(digits)&(text)=(text)
Use the URL
https://plusone.google.com/_/+1/fastbutton?url=http%3A%2F%2Fwww.yoursite.com%2Fpath%2Fyour%2fcontent
instead and follow the solution found in this question (parse for window.__SSR = {c:)
I think you're looking for this. It's ugly and Google clearly doesn't support it, but it still works.
function shinra_gplus_get_count( $url ) {
$contents = file_get_contents(
'https://plusone.google.com/_/+1/fastbutton?url='
. urlencode( $url )
);
preg_match( '/window\.__SSR = {c: ([\d]+)/', $contents, $matches );
if( isset( $matches[0] ) )
return (int) str_replace( 'window.__SSR = {c: ', '', $matches[0] );
return 0;
}
I'm creating an application which will create a large number of folders on a web server, with files inside of them.
I need the folder name to be unique. I can easily do this with a GUID, but I want something more user friendly. It doesn't need to be speakable by users, but should be short and standard characters (alphas is best).
In short: i'm looking to do something like Bit.ly does with their unique names:
www.mydomain.com/ABCDEF
Is there a good reference on how to do this? My platform will be .NET/C#, but ok with any help, references, links, etc on the general concept, or any overall advice to solve this task.
Start at 1. Increment to 2, 3, 4, 5, 6, 7,
8, 9, a, b...
A, B, C...
X, Y, Z, 10, 11, 12, ... 1a, 1b,
You get the idea.
You have a synchronized global int/long "next id" and represent it in base 62 (numbers, lowercase, caps) or base 36 or something.
I'm assuming that you know how to use your web server's redirect capabilities. If you need help, just comment :).
The way I would do it would be generating a random integer (between the integer values of 'a' and 'z'); converting it into a char; appending it to a string; and repeating until we reach the needed length. If it generates a value already in the database, repeat the process. If it was unique, store it in the database with the name of the actual location and the name of the alias.
This is a bit hack-like because it assumes that 'a' through 'z' are actually in sequence in their integer values.
Best I could think of :(.
In Perl, without modules so you can translate more easly.
sub convert_to_base {
my ($n, $b) = #_;
my #digits;
while ($n) {
my $digits = $n % $b;
unshift #digits, $digit;
$n = ($n - $digit) / $b;
}
unshift #digits, 0 if !#digits;
return #digits;
}
# Whatever characters you want to use.
my #digit_set = ( '0'..'9', 'a'..'z', 'A'..'Z' );
# The id of the record in the database,
# or one more than the last id you generated.
my $id = 1;
my $converted =
join '',
map { $digit_set[$_] }
convert_to_base($id, 0+#digits_set);
I needed something similar to what you're trying to accomplish. I retooled my code to generate folders so try this. It's setup for a console app, but you can use it in a website also.
private static void genRandomFolders()
{
string basepath = "C:\\Users\\{username here}\\Desktop\\";
int count = 5;
int length = 8;
List<string> codes = new List<string>();
int total = 0;
int i = count;
Random rnd = new Random();
while (i-- > 0)
{
string code = RandomString(rnd, length);
if (!codes.Exists(delegate(string c) { return c.ToLower() == code.ToLower(); }))
{
//Create directory here
System.IO.Directory.CreateDirectory(basepath + code);
}
total++;
if (total % 100 == 0)
Console.WriteLine("Generated " + total.ToString() + " random folders...");
}
Console.WriteLine();
Console.WriteLine("Generated " + total.ToString() + " total random folders.");
}
public static string RandomString(Random r, int len)
{
//string str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; //uppercase only
//string str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"; //All
string str = "abcdefghjkmnpqrstuvwxyz123456789"; //Lowercase only
StringBuilder sb = new StringBuilder();
while ((len--) > 0)
sb.Append(str[(int)(r.NextDouble() * str.Length)]);
return sb.ToString();
}