"Order by" query on Document DB suddenly stopped working on my development environment and is working fine without "Order by"
Here is the query which is not working (Use to work till yesterday and till yesterday it use to return me 70+ documents and now its returning null results(Empty array)):
SELECT * FROM c WHERE c.Category = 'test' ORDER BY c.StartDate DESC
Here is the query which is working(Currently its returning 70+ results and it use to return the same yesterday (which is not the case with the above query which is not working )):
SELECT * FROM c WHERE c.Category = 'test'
Did someone face the similar problem? What can be the solution for this?
I found the solution to the problem. As per the documentations:
https://learn.microsoft.com/en-us/azure/cosmos-db/indexing-policies
It clearly says
"The default indexing policy sets "kind=Hash, precision=3" by default.
If it is changed into "kind=Range, precision=-1". Order by on string
datatype works as expected."
And i found the solution here:
https://github.com/Azure/azure-documentdb-dotnet/issues/65
Here are few more links that help you know more about Document DB Indexing
https://azure.microsoft.com/en-us/blog/order-query-results-with-azure-documentdb/
https://azure.microsoft.com/en-us/blog/update-your-documentdb-indexing-policies-online/
So i have deleted my old collection and created a new one with precision "-1".
Related
I've been attempting to increase my knowledge and trying out some challenges. I've been going at this for a solid two weeks now finished most of the challenge but this one part remains. The error is shown below, what am i not understanding?
Error in sqlite query: update users set last_browser= 'mozilla' + select sql from sqlite_master'', last_time= '13-04-2019' where id = '14'
edited for clarity:
I'm trying a CTF challenge and I'm completely new to this kind of thing so I'm learning as I go. There is a login page with test credentials we can use for obtaining many of the flags. I have obtained most of the flags and this is the last one that remains.
After I login on the webapp with the provided test credentials, the following messages appear: this link
The question for the flag is "What value is hidden in the database table secret?"
So from the previous image, I have attempted to use sql injection to obtain value. This is done by using burp suite and attempting to inject through the user-agent.
I have gone through trying to use many variants of the injection attempt shown above. Im struggling to find out where I am going wrong, especially since the second single-quote is added automatically in the query. I've gone through the sqlite documentation and examples of sql injection, but I cannot sem to understand what I am doing wrong or how to get that to work.
A subquery such as select sql from sqlite_master should be enclosed in brackets.
So you'd want
update user set last_browser= 'mozilla' + (select sql from sqlite_master''), last_time= '13-04-2019' where id = '14';
Although I don't think that will achieve what you want, which isn't clear. A simple test results in :-
You may want a concatenation of the strings, so instead of + use ||. e.g.
update user set last_browser= 'mozilla' || (select sql from sqlite_master''), last_time= '13-04-2019' where id = '14';
In which case you'd get something like :-
Thanks for everyone's input, I've worked this out.
The sql query was set up like this:
update users set last_browser= '$user-agent', last_time= '$current_date' where id = '$id_of_user'
edited user-agent with burp suite to be:
Mozilla', last_browser=(select sql from sqlite_master where type='table' limit 0,1), last_time='13-04-2019
Iterated with that found all tables and columns and flags. Rather time consuming but could not find a way to optimise.
As of a few days ago, the following query worked fine on BQ with the schema generated by an export from GA:
SELECT hits.customDimensions.value
FROM TABLE_DATE_RANGE([88399188.ga_sessions_], TIMESTAMP('20150623'), TIMESTAMP('20150623'))
WHERE hits.customDimensions.index=14
LIMIT 1000
Now, I get the following error:
Error: Cannot query the cross product of repeated fields customDimensions.index and hits.customDimensions.index.
Interestingly, the following query works fine (i.e. without the WHERE clause):
SELECT hits.customDimensions.value
FROM TABLE_DATE_RANGE([88399188.ga_sessions_], TIMESTAMP('20150623'), TIMESTAMP('20150623'))
LIMIT 1000
Also, the following query works fine:
SELECT hits.customDimensions.value
FROM [88399188.ga_sessions_20150623]
WHERE hits.customDimensions.index=14
LIMIT 1000
Note that the FROM clause is the only difference between this one and the failing query; even though they are supposed to resolve to the exact same query. Please help! What am I doing wrong?
The problem is that both customDimensions is REPEATED RECORD, and hits is REPEATED RECORD, and each can repeat independently of the other. Therefore selecting hits.customDimensions.value while filtering on hits.customDimensions.index is not well defined in meaning. If, for example, you want to skip the entire record when non of the hits.customDimensions.index is 14, then you can use the following query:
SELECT hits.customDimensions.value
FROM TABLE_DATE_RANGE(
[88399188.ga_sessions_], TIMESTAMP('20150623'), TIMESTAMP('20150623')
OMIT RECORD IF EVERY(hits.customDimensions.index != 14)
LIMIT 1000
This anomaly is no longer reproducible. Though I have not gotten confirmation from Google, I have to assume this was a temporary bug that got fixed.
I have a question on creating running totals in MS Access 2010 similar to the one here:
Access 2010 - query showing running total for multiple records, dropping old record and adding new record on each line
However when I input the equivalent code from that thread I get an error saying that the database cannot be found (Access seems to think the table I have specified is the database name)
Here is the code from the original thread:-
SELECT hbep1.EmployeeID, hbep1.PayPeriodID,
(
SELECT Sum(hbep2.HoursUsed)
FROM Hours_by_Empl_PP hbep2
WHERE hbep2.EmployeeID=hbep1.EmployeeID
AND (hbep2.PayPeriodID Between hbep1.[PayPeriodID]-3
And hbep1.[PayPeriodID])
) AS Sum_of_Hours_last_4_PPs
FROM Hours_by_Empl_PP hbep1;
Here is the code I inputted into my query:-
SELECT
V4_Try.ID_NIS_INV_HDR,
V4_Try.ID_ITM,
V4_Try.RunTot3,
V4_Try.BomVsActQty,
DMin("RunTot3","V4_Try","[ID_Itm]=" & [ID_ITM]) AS IDItmMin,
DMax("RunTot3","V4_Try","[ID_Itm]=" & [ID_ITM]) AS IDItmMax,
(
SELECT Sum([V4_Try].[BomVsActQty])
FROM [V4_Try].[BomVsActQty]
WHERE [V4_Try].[ID_ITM]=[V4_Try].[ID_ITM]
AND (IDItmMax < IDItmMin)
) AS RunTot6
FROM V4_Try
ORDER BY V4_Try.ID_ITM, V4_Try.RunTot3;
One thing I notice is that the main query uses DMax() and DMin() to create some aliased columns
...
DMin("RunTot3","V4_Try","[ID_Itm]=" & [ID_ITM]) AS IDItmMin,
DMax("RunTot3","V4_Try","[ID_Itm]=" & [ID_ITM]) AS IDItmMax,
...
and then the subquery tries to use those aliases in its WHERE clause
(
SELECT ...
WHERE...
AND (IDItmMax < IDItmMin)
) AS RunTot6
I'm pretty sure that the subquery will have no knowledge of the column aliases in the "parent" query, so they may be the items that are unrecognized.
Start by running this query:
SELECT * FROM V4_Try;
Then develop for complexity. Build the nested query before anything else. When you know that runs, try adding your aliases, then the DMax() function, and so on. Isolate the point at which you have an error popping up.
This is the process to fix a query.
Oh, and please specify the precise error that is raised by Access. Also, if this is being run from VBA, please let us know because that affects your trouble-shooting.
I have a few simple named queries with only joins, ant couple subselects. All of them ar working perfectly except one. The problem is, that when i run SQL code in Management Studio, i get 177 results, and when i run named query with the same SQL code, i get 20 results. I can't figure out why is that. I Call named query the as all other:
public IList<InstitutionIndexDTO> GetInstitutionIndexByWorkTimeSearch(int time, int institutionType)
{
IQuery query = GetCurrentSession()
.GetNamedQuery("GetInstitutionsListByTime")
.SetInt32("Type", institutionType)
.SetInt32("TimeUntilClose", time)
.SetResultTransformer(Transformers.AliasToBeanConstructor(typeof(InstitutionIndexDTO).GetConstructors()[0]));
return query.List<InstitutionIndexDTO>();
}
Even when i harcoded parameters in SQL, i still got the same result. I tried checking with Profiler, but generated SQL is perfect and in management studio returns all 177 results.
InstitutionIndexDTO is working correctly, because i use it with other named queries.
I have a working named query, and the one causing problems was made from that one, adding additional INNER JOIN and changing WHERE clause. Both queries returns same columns.
Maybe somebody has an idea, what i could have done wrong?
I tested my code and realised that this line is causing the problem:
(CASE WHEN (DATEPART(dw, GETDATE())) = 1 THEN 7 ELSE (DATEPART(dw, GETDATE()) - 1) END)
If i understand well, the problem is in DATEPART function. Has anybody encountered this problem?
I have an error occuring frequently from our community server installation whenever the googlesitemap.ashx is traversed on a specific sectionID. I suspect that a username has been amended but the posts havn't recached to reflect this.
Is there a way a can check the data integruity by performing a select statement on the database, alternatively is there a way to force the database to recache?
This error could be thrown by community server if it finds users that aren't in the instance of MemberRoleProfileProvider.
See CommunityServer.Users AddMembershipDataToUser() as an example
UPDATE:
I Solved this problem for my case by noticing that the usernames are stored in two tables - cs_Users and aspnet_Users. Turns out somehow the username was DIFFERENT in each table. Manually updating so the names were the same fixed this problem.
Also, the user would left out of membership in the following line of the stored procedure cs_Membership_GetUsersByName:
INSERT INTO #tbUsers
SELECT UserId
FROM dbo.aspnet_Users ar, #tbNames t
WHERE LOWER(t.Name) = ar.LoweredUserName AND ar.ApplicationId = #ApplicationId
The #tbNames is a table of names comes from cs_Users(?) at some point and therefore the usernames didn't match and user was not inserted in to the result later on.
See also: http://dev.communityserver.com/forums/t/490899.aspx?PageIndex=2
Not so much an answer, but you can find the affected data entries by running the following query...
Select *
FROM cs_Posts
Where UserID Not In (Select UserID
From cs_Users Where UserAccountStatus = 2)