function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mobile1.390759152613193E12mobile1.390759152613193E12 

MockSmartStore doesn't support "some" kind of smartQuery

Hi,

I am developing an hybrid app for iphone using the MockSmartStore (that personally I find fantastic! It saves you up a huge amount of time in debugging javascript).

I found a strange behaviour on smartQuery:

the following javascript line works when I make it run in the container:

return objectStructure.find({queryType:"smart", smartSql:"SELECT {objectStructure:_soup} FROM {objectStructure}", pageSize:25});

But when using MockSmartStore it gives me the following error:

Error caught when calling com.salesforce.smartstore:pgRunSmartQuery Error: SmartQuery not supported by MockSmartStore:SELECT {objectStructure:_soup} FROM {objectStructure} MockCordova.js:92
(anonymous function)

Error: SmartQuery not supported by MockSmartStore:SELECT {objectStructure:_soup} FROM {objectStructure}
    at module.smartQuerySoupFull (file:///Users/mauricapobianco/SalesforceMobileSDK-IOS2.1/mobile_sdk_samples/SFOfflineForIphone/test/MockSmartStore.js:292:19)
    at module.querySoupFull (file:///Users/mauricapobianco/SalesforceMobileSDK-IOS2.1/mobile_sdk_samples/SFOfflineForIphone/test/MockSmartStore.js:297:29)
    at module.querySoup (file:///Users/mauricapobianco/SalesforceMobileSDK-IOS2.1/mobile_sdk_samples/SFOfflineForIphone/test/MockSmartStore.js:340:32)
    at Object.com.salesforce.smartstore:pgRunSmartQuery (file:///Users/mauricapobianco/SalesforceMobileSDK-IOS2.1/mobile_sdk_samples/SFOfflineForIphone/test/MockSmartStore.js:402:32)
    at file:///Users/mauricapobianco/SalesforceMobileSDK-IOS2.1/mobile_sdk_samples/SFOfflineForIphone/test/MockCordova.js:90:46

The code in the two files are exactly the same, apart from the pointing to the aut_local.js and the pointing to the js libraries.

Thanks a lot for the help

Maurizio. 
akhilesh_sfdcakhilesh_sfdc
That's right! Unfortunately, Mocksmartstore doesn't currently support the smartSQL as it would require us to build a whole SQL parser in JS and we don't have any plans yet to support that.
mobile1.390759152613193E12mobile1.390759152613193E12
Thanks a lot
mobile1.390759152613193E12mobile1.390759152613193E12
Hi akhilesh, 

I checked the Account Editor example and has an example of smart query that works on MockSmartStore;


config: function() {
        // Offline: do a cache query
        if (!app.offlineTracker.get("isOnline")) {
            console.log("AccountCollection fetch offline");
            // Not using like query because it does a case-sensitive sort
            return {type:"cache", cacheQuery:{queryType:"smart", smartSql:"SELECT {accounts:_soup} FROM {accounts} WHERE {accounts:Name} LIKE '" + (this.key == null ? "" : this.key) + "%' ORDER BY LOWER({accounts:Name})", pageSize:25}};
        }
        // Online
        else {
            console.log("AccountCollection fetch mru online");
            // First time: do a MRU query
            if (this.key == null) {
                return {type:"mru", sobjectType:"Account", fieldlist: this.fieldlist, orderBy:"LastModifiedDate", orderDirection:"DESC"};
            }
            // Other times: do a SOQL query
            else {
                console.log("AccountCollection fetch online");
                return {type:"soql", query:"SELECT " + this.fieldlist.join(",") + " FROM Account WHERE Name like '" + this.key + "%' ORDER BY Name LIMIT 25"};
            }
        }
    }

HOW is it possible?

Thanks. 
akhilesh_sfdcakhilesh_sfdc
Looking into the implementation of the MockSmartStore, it seems like that it currently supports only 3 types of smart sql queries: 
1) SELECT {soupName:selectField} FROM {soupName} WHERE {soupName:whereField} IN (values)
2) SELECT {soupName:_soup} FROM {soupName} WHERE {soupName:whereField} LIKE 'value' ORDER BY LOWER({soupName:orderByField})
3) SELECT count(*) FROM {soupName}

So it seems like that MockSmartStore doesn't support a simpler version ("SELECT {objectStructure:_soup} FROM {objectStructure}") that you are using in your app. BTW, for your usecase, you should just use the "buildAllQuerySpec" method to create a querySpec for fetching all the items from soup instead of running a SmartSQL query. SmartSQL syntax is usually to support more complicated queries with complex filters etc.