Azure Billing API gives me only 7 days of data - azure-billing-api

Is there any restriction on the date range to use the Azure Billing API? I'm requesting a month's worth of data but I only get the first 7 days of that range...
I use a request like the one below:
/UsageAggregates?api-version=2015-06-01-preview&reportedstartTime=2015-12-01&reportedEndTime=2016-01-01
And my console only gives me:
[2015-12-01T00:00:00+00:00] Metric 1 blah blah
[2015-12-01T00:00:00+00:00] Metric 2 blah blah
[2015-12-01T00:00:00+00:00] Metric 3 blah blah
[2015-12-02T00:00:00+00:00] Metric 1 blah blah
[2015-12-02T00:00:00+00:00] Metric 2 blah blah
[2015-12-02T00:00:00+00:00] Metric 3 blah blah
[2015-12-03T00:00:00+00:00] Metric 1 blah blah
[2015-12-03T00:00:00+00:00] Metric 2 blah blah
[2015-12-03T00:00:00+00:00] Metric 3 blah blah
[2015-12-04T00:00:00+00:00] Metric 1 blah blah
[2015-12-04T00:00:00+00:00] Metric 2 blah blah
[2015-12-04T00:00:00+00:00] Metric 3 blah blah
[2015-12-05T00:00:00+00:00] Metric 1 blah blah
[2015-12-05T00:00:00+00:00] Metric 2 blah blah
[2015-12-05T00:00:00+00:00] Metric 3 blah blah
[2015-12-06T00:00:00+00:00] Metric 1 blah blah
[2015-12-06T00:00:00+00:00] Metric 2 blah blah
[2015-12-06T00:00:00+00:00] Metric 3 blah blah
[2015-12-07T00:00:00+00:00] Metric 1 blah blah
[2015-12-07T00:00:00+00:00] Metric 2 blah blah
[2015-12-07T00:00:00+00:00] Metric 3 blah blah
And that's all I get!

Many of the Azure REST APIs use continuation tokens to provide pagination of results.
The Billing API is rather new and the documentation is thin on the ground, but here's an example of continuation token based pagination with the Azure Tables REST API.
If your results are being paged then you should see a header in the HTTP response providing the token to get the next page of results.

As per #AndyJ suggestion, I have fixed this using the continuationToken parameter in my api request (see below). Passing the continuationToken value from each response will give you the next set of data until the last "page" where continuationToken will be empty meaning the data for the selected range is all completed.
providers/Microsoft.Commerce/UsageAggregates?api-version=2015-06-01-preview&reportedstartTime=2016-01-01&reportedEndTime=2016-02-01&aggregationGranularity=Daily&showDetails=true&continuationToken=" + continuationToken

Related

SQL Email (.com) Reference

My school work has asked me to retrieve information from all customers with emails ending in ".com" I cannot find any information anywhere. Can you help me out? Below is what I have tried as well as many other variations.
SELECT first_name AND last_name FROM customerform WHERE email LIKE('.com')
That's not how LIKE works, nor how SELECT works. Instead:
SELECT first_name, last_name FROM customerform WHERE email LIKE '%.com'
Here % means "begins with" or "blah blah blah" in more casual parlance.
Remember things like SELECT are fully documented and there's no shame in checking how they work before running your statement. We all need to check that we're doing it correctly.

MySQL AES_Decrypt not working

I've been trying so many different variations to get AES_Decrypt to work. I started of with field types VARBINARY then tried BLOB but still no luck, keeps returning NULL. Eventually I tried this:
SELECT AES_DECRYPT(AES_ENCRYPT('blah blah blah','1234'), '1234') as test
This technically should have returned blah blah blah, but instead it returns
626c616820626c616820626c6168
So not sure what is going on or what I am doing wrong.
I have inserted encrypted data as follows:
INSERT INTO private (short_name, mobile, name)
VALUES (
'AS1',
AES_ENCRYPT('0111222333','1234'),
AES_ENCRYPT('My Name','1234')
)
Then I try to decrypt it like this:
SELECT AES_DECRYPT('mobile', '1234') AS mobile FROM private
It just does not seem to work. Followed lots of the instructions online but still no luck.
Any ideas?
So it seems that I need to use CAST unless using the mysql command line client.
So doing this seems to work:
SELECT CAST(AES_DECRYPT(AES_ENCRYPT('blah blah blah','1234'), '1234') AS CHAR (150))
SELECT AES_DECRYPT(AES_ENCRYPT('blah blah blah','1234'), '1234') as test
is returning binary string as output. If you convert it to string then it will blah blah blah. You can use online hex to binary converter to verify it. You have to set it to text in your GUI tool.

MySQL regex to return matching string only

I'm building a query to run in an Invision Power Board hosted site using the SQL Toolbox, unfortunately it seems a but limited and I've not been able to add custom SQL function so far. I've built a mutli-table query but for the sake of simplicity will simplify it here.
The following is a sample of the database and a query to find profiles which include an address in their About Me (field_11) profile using Regex. The results shows the entirety of the About Me and not just the matching string.
Is there a way to structure the query to return just the matching string found by regex without using a bespoke MySQL function?
SQL Database
CREATE TABLE core_pfields_content
(`field_11` LONGTEXT);
INSERT INTO core_pfields_content
(`field_11`)
VALUES
('<p> C++ eveloper</p> <p> AJ4ndBBLJZmRDVtC7JfGAVivhUXFDvWqKL </p>'),
('<p> Norwegian designer and illustrator working out of Oslo. </p>'),
('<p> Hello everyone, I am a Freelancer Photographer </p> <p> My portfolio: </p> <p> address: AW7fvzoEWAfiyyEwgXmgog525NCCeAxVmG </p>');
Query
SELECT field_11
FROM core_pfields_content
WHERE field_11 REGEXP '^.*([A][a-km-zA-HJ-NP-Z1-9]{26,33}).*';
Result
field_11
<p> C++ eveloper</p> <p> AJ4ndBBLJZmRDVtC7JfGAVivhUXFDvWqKL </p>
<p> Hello everyone, I am a Freelancer Photographer </p> <p> My portfolio: </p> <p> address: AW7fvzoEWAfiyyEwgXmgog525NCCeAxVmG </p>
http://sqlfiddle.com/#!9/02d1d/1

Remove html link from mysql database field with SQL

I have an old MySQL database and I need to remove different HTML links from description field.
So, for example after SQL execution on description with a following text:
Hello test World !
I need to get:
Hello World !
Please note that in my database HTML links are not the same and contain different addresses and texts.
Is it possible to do with MySQL SQL query and if so, could you please provide an example.
You can use a query like this. You only must change FIELDNAME to your fieldname and TABLENAME to your tablename. In your Sample there are one space behind HELLO ** and one before ** WORLD, so you have 2 spaces in the RESULT
SELECT
CONCAT(
SUBSTR(FIELDNAME,1,
INSTR(FIELDNAME,'<a href=')-1)
,
SUBSTR(FIELDNAME,
INSTR(FIELDNAME,'</a>')+4)
)
FROM YOURTABLE;
sample
SELECT
CONCAT(
SUBSTR('Hello test World !',1,
INSTR('Hello test World !','<a href=')-1)
,
SUBSTR('Hello test World !',
INSTR('Hello test World !','</a>')+4)
);
result
Hello World !

FirstOrDefault() || Select() which is faster?

In general, is one faster than the other, assuming 1 record is being returned?
Are there benefits to using one over the other?
Just as an example:
DataContext.TableBlah.FirstOrDefault(_blah => _blah.id == 1);
or
var test = (from blah in TableBlah
where blah.id == 1
select blah)
FirstOrDefault returns as soon as it finds a result, so it can be slightly faster, but not by an order of magnitude... Anyway, your second query can return more than one result, so it's not really a fair comparison. You could compare it to SingleOrDefault instead, which is like a Select, but returns just 1 result.
SingleOrDefault, like a Select, must go through the complete list, but it guarantees that you get one and only one result.
Note: If you're using Linq to SQL, than you second query can be faster, depends on your indexes...
var test = (from blah in TableBlah
where blah.id == 1
select blah)
This can return more than 1 rows, for matching records (As against FirstOrDefault).
Performance wise, I don't think it should be any different.
It also depends on number of rows in the table? Is Id column indexed?
I'm 90% certain that
var test = dc.TableBlah.FirstOrDefault(_blah => _blah.id == 1);
sets up the exact same expression tree as
var test = (from blah in dc.TableBlah
where blah.id == 1
select blah).FirstOrDefault();
So your second example simply lacks the benefit of getting a single record by calling FirstOrDefault(). In terms of performance, they'll be identical.
Personally, I would use SingleOrDefault() instead, since you're looking for a single item. SingleOrDefault() will throw if you receive more than one record.
This can potentially be faster.
var test = (from blah in TableBlah
where blah.id == 1
select blah)
It depends on which LINQ provider you're using. If you're using LINQ to Sql or Subsonic, etc, this can get translated into a direct SQL call, which will only fetch one row from the DB.
In LINQ to Objects, the two statements will be nearly identical, due to LINQs streaming of results.