what is the GQL count query - google-app-engine

In the interest of time, I do mean GQL, as in
SELECT * FROM Song WHERE composer = 'Lennon, John'
The following failed
SELECT COUNT(*) FROM myEntity
also the following
SELECT COUNT() FROM myEntity

As shown here, there is actually a way to count the return of your GQL. The doc about the GQL language shows you can't really do a count on the query itself. So what you would do is take your select *, put it in a GQL query object, then call the "count()" method on that object to have the count

Related

How to limit the result data in flexible seach query

I want to limit the result data in flexible search query.
Let's say query should return only 10 records each time (like LIMIT)
How can I do this?
You already answered your query, you can use LIMIT cause same as we use in MySQL.
Try this
SELECT * FROM {Product} LIMIT 10
or
SELECT TOP 10 * FROM {Product}
For Oracle
SELECT * FROM {Product} WHERE rownum <= 10
Though API
final FlexibleSearchQuery query = new FlexibleSearchQuery("SELECT * FROM {Product}");
query.setCount(10);
Find more detail in helphybris
Use the query.setCount(int) method of the API.

How do I execute this query in GQL [Google App engine]?

I have a table of projects with two of it's columns as 'language' and 'tag'.
After the user gives an input, I want to output all the projects whose language is input or tag is input.
Sql query for above would be this,
Sql query: Select * from TableName where language='input' OR tag='input'
I tried to execute the same in Gql but in vain. What should be the query in Gql to output the data in the above mentioned way.
GQL doesn't have OR, so basically you have to make two separate queries and union results:
Select * from TableName where language='input'
Select * from TableName where tag='input'
You should join results on your app side, Cloud Console doesn't support such things too.
See GQL reference: https://cloud.google.com/datastore/docs/apis/gql/gql_reference
I don't know if is mandatory for you to use GQL, but in case you are able to avoid it, you can use the ndb filter instead.
results = TableName.query(ndb.OR(TableName.language == 'input',
TableName.tag == 'input'))
for result in results:
....your code here...
More information in: https://cloud.google.com/appengine/docs/python/ndb/queries

Gql query for repeated StructuredProperty

How do I write the following query in GQL? [1]
Contact.query(Contact.address == Address(city='San Francisco',
street='Spear St'))
[1] Filtering for Structured Property Values
Quoting https://cloud.google.com/appengine/docs/python/ndb/queries#gql , "To query models containing structured properties, you can use foo.bar in your GQL syntax to reference subproperties" -- so if I understand your task correctly,
'''SELECT * FROM Contact
WHERE address.city='San Francisco' AND
address.street='Spear St'
'''
should work. Doesn't it?

cakephp: group by is missing from generated query

I have a simple model where I would like to find some count data per date.
I made this find in order to do that:
$statsubscriptions = $this->Nlist->Statsubscription->find('all',
array(
'fields'=>array('Statsubscription.date','Statsubscription.type','COUNT(*) as qs'),
'qroup'=>array('Statsubscription.date','Statsubscription.type'),
'conditions'=>array('Statsubscription.nlist_id'=>$id),
'recursive'=>-1,
)
);
But it does not work. The generated query is the following:
SELECT `Statsubscription`.`date`, `Statsubscription`.`type`, COUNT(*) as qs
FROM `statsubscriptions` AS `Statsubscription`
WHERE `Statsubscription`.`nlist_id` = 1
GROUP BY is completly missing... Instead of the above I would like this query to be generated:
SELECT `Statsubscription`.`date`, `Statsubscription`.`type`, COUNT(`Statsubscription`.`id`) as qs
FROM `statsubscriptions` AS `Statsubscription`
WHERE `Statsubscription`.`nlist_id` = 1
GROUP BY `Statsubscription`.`date`, `Statsubscription`.`type`
How can I achieve this? And what could be the reason of the missing GROUP BY?
You are writing qroup instead of group (that's q instead of g). Which is why it doesn't work.
P.S.: get some sleep...

I use the SELECT query to download contacts from Salesforce.com. As it is given below and i am getting "MALFORMED_QUERY" exception

I use this select query and i am not getting what's the wrong with this.
Select Id,Contact.FirstName,Contact.LastName,Contact.Title,Contact.Department,Contact.Birthdate,
Contact.Phone,Contact.HomePhone,Contact.MobilePhone,Contact.OtherPhone,Contact.Fax,Contact.Email,Contact.MailingStreet,
Contact.MailingCity,Contact.MailingState,Contact.MailingCountry,Contact.MailingPostalCode,Contact.OtherStreet,
Contact.OtherCity,Contact.OtherState,Contact.OtherCountry,Contact.OtherPostalCode,Contact.Description,Contact.Account.Name From Contact where strcmp('%#',Id) = -1",lastcontactId
You need to generate a query that uses =, e.g.
select name from contact where id='005123123123123123'
so, you can use this to generate the query.
NSString *query = [NSString stringWithFormat:#"select name,etc from contact where id='%#'", lastContactId];
Here's the SOQL docs which has more examples.
And if you're trying to do paging, you should just run the entire query and use query/queryMore to page through the results.

Resources