Handling spaces in contentResolver string matching - android-contentresolver

I am trying to retrieve sms by phone number but I don't get any result. (I do get results if I replace where and where_args by null)
String where = "address=?";
String[] where_args = new String[]{"+33 1 23 45 67 89"};
contentResolver.query(uri, new String[]{"*"}, where, where_args, null);
I suspect that there is a problem with the ? because of the spaces, so I tried where = "address='?'"; andwhere = "address=\"?\"";` but none worked
Any idea ? Thanks !

Have you tried the following to ensure part of it works correctly?
String where = "address = '+33 1 23 45 67 89'";
contentResolver.query(uri,
new String[]{"*"},
where, null, null);
Try creating the array in the query call.
String where = "address = ?";
String where_args = "+33 1 23 45 67 89";
contentResolver.query(uri,
new String[]{"*"},
where,
new String[]{where_args},
null);
Also, check that your projection argument isn't causing issues. Set that parameter specifically to the column you are searching, at least for testing purposes, to see if that is altering the selection argument in anyway.
More examples below:
How to filter the results of content resolver in android?

Related

Google script - send email alert

I have a script that looks into values in column G and if the correspondent cell in column A is empty, sends me an email.
--- WHAT WORKS --
It works ok for static values: it sends one email per each not empty cell in column G for which there is no value in column A
--- WHAT DOESN'T WORK --
It sends several emails for what I assume it's every Column G cell (empty or not) when the column A values are fetched from another tab. That way it's like all G and A cells have data, so I get multiple unwanted emails.
This is the script code:
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName('Sheet to send emails');
const data = sh.getRange('A2:G'+sh.getLastRow()).getValues();
data.forEach(r=>{
let overdueValue = r[0];
if (overdueValue === ""){
let name = r[6];
let message = 'Text ' + name;
let subject = 'TEXT.'
MailApp.sendEmail('myemail#gmail.com', subject, message);
}
});
}
And this is the link to the test sheet:
https://docs.google.com/spreadsheets/d/1OKQlm0PjEjDB7PXvt34Og2fa4vPZWnvLazTEawEtOXg/edit?usp=sharing
In this test case, I "should" only get one email, related to ID 55555. With the script as is, I get one related to 55555 and several others "undefined".
To avoid e-mail spam, I didn't add the script to that sheet but it shows the "Vlookup" idea.
Can anyone give me a hand, please?
Thank you in advance
Issue:
The issue with your original script is that the sh.getLastRow returns 1000 (it also processes those rows that doesn't have contents, result to undefined)
Fix 1: Get specific last row of column G:
const gValues = sh.getRange('G1:G').getValues();
const gLastRow = gValues.filter(String).length;
or
Fix 2: Filter data
const data = sh.getRange('A2:G' + sh.getLastRow()).getValues().filter(r => r[6]);
Note:
As Kris mentioned in the comments, there is a specific case where getting the last row above will fail (same with getNextDataCell). This will not properly get the last row WHEN there are blank rows in between the first and last row of the column. If you have this kind of data, then use the 2nd method which is filtering the data.
If your data in column G does not have blank cells in between the first and last row, then any method should work.
I checked your test sheet, and sh.getLastRow() is 1000.
OPTION 1
If column G won't have empty cells between filled ones, then you can do this:
const ss = SpreadsheetApp.getActive();
const sheet = ss.getSheetByName("Sheet to send emails");
// get the first cell in column G
var gHeader = sheet.getRange(1, 7);
// equivelent of using CTRL + down arrow to find the last da
var lastRow = gcell.getNextDataCell(SpreadsheetApp.Direction.DOWN).getRow();
const data = sheet.getRange(2, 1, lastRow, 7).getValues();
OPTION 2
Add another condition to your code - like this:
data.forEach(r=>{
let overdueValue = r[0];
let name = r[6]
// check if the value in col A is blankd and col G is not blank
if (overdueValue === "" && name !== ""){
let message = 'Text ' + name;
let subject = 'TEXT.'
MailApp.sendEmail('myemail#gmail.com', subject, message);
}
});
And to speed it up, use a named range to limit how many rows it has to iterate through:
const ss = SpreadsheetApp.getActive();
const data = ss.getRangeByName("Your_NamedRange_Here").getValues();

How to set date using OCCI::Date::setDate method

I am trying to create a OCCI::Date object using setDate method but I get an error while doing so.
Below is the snippet of my code.
using ODate = oracle::occi::Date;
ODate ts;
ts.setDate(datetime.year(),datetime.month(),datetime.day(),datetime.hour (),datetime.minute(),datetime.second());
this is the error I get - ORA-32146: Cannot perform operation on a null date
I also printed the values that I am passing to setDate method to check if those values are correct and they are all fine and within the Date range.
datetime.year() = 2018
datetime.month() = 6
datetime.day() = 5
datetime.hour() = 6
datetime.minute() = 1
datetime.seconds() = 22
Any leads to resolve this issue?
Oracle has its own format of storing date. Check this link.
Set the resulted value in OCIDate.OCIDateYYYY

Within Where Clause, Nested Case When Statement to return Result with 'OR'

Good afternoon everyone,
I am trying to combine 2 separate function to create a semi-dynamic where clause. Currently I have 3 identical view in my SQL database which are pretty much the same except for the following line pending on what the user state are.
For WA User.
(dbo.JunctionT.ProcessState = 'CDS' )
For VIC User.
(dbo.JunctionT.ProcessState = 'VIC' OR dbo.JunctionT.ProcessState = 'WA')
For NSW User.
(dbo.JunctionT.ProcessState = 'NSW')
Therefore, if the user is from NSW, return results from their user state.. and if the user is from WA then return result where ProcessState is CDS and if the user is from VIC then return result where ProcessState is either VIC or WA.
I have written the following nested case when statement to try and combine these 3 views into 1:
`dbo.JunctionT.ProcessState =
(CASE
WHEN dbo.fnGetReviewState(CURRENT_USER) = 'NSW' THEN 'NSW'
WHEN dbo.fnGetReviewState(CURRENT_USER) = 'WA' THEN 'CDS'
WHEN dbo.fnGetReviewState(CURRENT_USER) = 'VIC' THEN 'VIC OR WA'
END)`
This seems to be working perfectly fine for both NSW and WA users but when I trial it as a VIC user, it returns nothing. I suspect it could be a syntax issue but i have tried the following without much success:
Have tried to use:('VIC OR WA'), ('VIC' OR 'WA'), ['VIC' OR 'WA'], <'VIC' OR 'WA'>
Hoping that someone more knowledgeable is able to show me what it is I am missing or even suggest a better way to complete this dynamic statement. Many many thanks in advance!!
SeanY
Brien is close. This should do the trick:
case
when dbo.JunctionT.ProcessState = 'NSW' and
dbo.fnGetReviewState(CURRENT_USER) = 'NSW' then 1
when dbo.JunctionT.ProcessState = 'CDS' and
dbo.fnGetReviewState(CURRENT_USER) = 'WA' then 1
when dbo.JunctionT.ProcessState in ( 'VIC', 'WA' ) and
dbo.fnGetReviewState(CURRENT_USER) = 'VIC' then 1
else 0
end = 1
'VIC OR WA' is literally "VIC OR WA", that is why there are no rows returning.
dbo.JunctionT.ProcessState would have to equal "VIC OR WA" (this exact/literal string) to return rows.
What you want instead dbo.JunctionT.ProcessState IN ('VIC','WA')
So there is an element of dynamic SQL involved in order to have your CASE statement return exactly what you need.

Cassandra: get_range_slices of TimeUUID super column?

I have a schema of Row Keys 1-n. In each row there are a variable number of supercolumns with a TimeUUID 'name'. Im hoping to be able to query this data by a time range.
Two issues have come up:
in KeyRange -> the values that I put in for 'start_key' and 'end_key' are getting misunderstood (for lack of a better term) by Thrift. Experimenting with different groups of values Im not seeing what I expect and often get back something completely unexpected.
Example: my row keys are running from 1-1000 with lots of random gaps. I put start_key = 50 and end_key = 20 .. and I get back rows with keys ranging from 99 to 414.
Example: I have a known row with key = 13. Putting this value into start_key and end_key gives me no results.
Second issue: even when I do get results the 'columns' portion of the 'keyslice' is always empty. I have checked via cassandra-cli and I know there is data.
Im using Perl as follows:
my $slice_range = new Cassandra::SliceRange();
$slice_range->{ start } = create_UUID( UUID::Tiny::UUID_TIME, "2010-12-24 00:00:00" );
$slice_range->{ finish } = create_UUID( UUID::Tiny::UUID_TIME, "2011-12-25 00:00:00" );
my $slice_predicate = new Cassandra::SlicePredicate();
$slice_predicate->{ slice_range } = $slice_range;
my $key_range = new Cassandra::KeyRange();
$key_range->{ start_key } = 13;
$key_range->{ end_key } = 13;
my $result = $client->get_range_slices( $column_parent, $slice_predicate, $key_range, $consistency_level );
print Dumper( $result );
Clearly Im misunderstanding some basic precept.
EDIT: It turns out that the Perl library Im using is not properly documented. The UUID creation was not working as advertised. I opened it up, fixed it, and now its all going a bit more as I was expecting. I can slice my supercolumns by date/time range. Still working on getting the key range portion to work.
http://wiki.apache.org/cassandra/FAQ#range_rp covers why you're not seeing what you expect with key ranges.
You need to specify a SlicePredicate that contains the actual range of what you're trying to select. The default of no column_names and no slice_range will result in the empty columns list that you see.

Substring a text since the target founded

I have a search on my php page and it is ok.
With my search result, I highlighted the string target on my content.
$search_tag_text = #preg_replace("/($mysearch)/i", "<u style=\"color:red\">$1</u>", $row->txtContent);
Ok, but is it possible, after having found a string target on my content, to show 20 words before and 20 words after, instead listing all my content?
Any help will be appreciated.
I would try something like:
$matches = array();
preg_match("/($mysearch)/i", $search_tag_text, $matches, PREG_OFFSET_CAPTURE);
And then in the match you would have the offset of where the found string is, then you could do:
$search_tag_text = substr($subject, ($matches[0][1] - 30), 60);
For 30 characters before the match and 30 after. If i've understood correctly the last element in $mathces[i][x] is the offset where the match was found.