Accessing WebSQL Database object in PhoneGap - javascript

I am trying to access WebSQL database results using PhoneGap Developer App, but I cannot seem to access the object correctly. Here is an example piece of code:
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM ' + table, [],
function (transaction, resultSet) {
console.log(resultSet.rows);
}, function (transaction, error) {
console.log(error);
});
});
This block works perfectly fine in Chrome while testing the PhoneGap app via the PhoneGap CLI. It returns the object in the console and the CLI says [object SQLResultSetRowList]. I can then access a specific row by calling:
console.log(resultSet.rows.item(0));
This works fine in both the desktop CLI and developer app. What I want to do though, is to iterate through the results using jQuery $.each:
$.each(resultSet.rows, function (k,v) {
console.log(JSON.stringify(v));
});
This is where I encounter a problem. In Desktop Chrome and using the CLI, each row is correctly printed to the console as a JSON string of key => value pairs. But when I try to run the exact same code using the PhoneGap Developer App on my testing device, the console instead only prints the following:
"100" which is the "length" key of the result set, and an empty output (the corresponding key being "item").
What is the correct way to iterate through the resultSet object? For reference, I am using an iPhone X on iOS 11 as my testing device.

I ended up working around this issue by building an object from scratch using the resultSet data:
function getIterableObjectFromResult(resultSet) {
for (var i = 0, data = {}; i < resultSet.rows.length; i++) {
data[i] = resultSet.rows.item(i);
}
return data;
}
The resulting output can then be iterated correctly in the PhoneGap Developer app.

Related

indexedDB with CDWKWebViewEngine in PhoneGap Build cli-6.0.0

I'm having trouble opening an indexedDB store when using CDWKWebViewEngine within an app build with PhoneGap Build 6 running on iOS 9.2. window.indexedDB is not null and appears to be of type IDBFactory but when I use the code below I get "InvalidAccessError" reported.
var request = window.indexedDB.open("MyTestDatabase", 1);
request.onerror = function (event) {
alert("Database error: " + request.error.name);
};
Has anyone been able to get indexedDB working in the environment I've described?

Trouble during passing extension data along with session request in QuickBlox

I am working on a project which provides video calling from web to phone (iOS or Android). I am using QuickBlox + WebRTC to implement video calling. From web I want to pass some additional info along with call request like caller name, etc. I looked into the JavaScript documentation of QuickBlox + WebRTC which suggest to use the following code (JavaScript):
var array = {
me: "Hari Gangadharan",
}
QB.webrtc.call(callee.id, 'video', array);
I have implemented the same code but unable to get the info attached with session request on the receiver side (getting nil reference in iOS method).
- (void)didReceiveNewSession:(QBRTCSession *)session userInfo:(NSDictionary *)userInfo {
//Here userInfo is always nil
}
Please use the following structure
var array = {
"userInfo": {
"me":"Hari Gangadharan",
}
}
because our iOS SDK uses "userInfo" as a key for parsing custom user info
Check Signaling v1.0

Chrome packaged app in-app payment api

I have created a chrome app and trying to get the list of product but I am getting internal server error. The following is a code.
function getProductList() {
console.log("google.payments.inapp.getSkuDetails");
statusDiv.text("Retreiving list of available products...");
google.payments.inapp.getSkuDetails({
'parameters': {env: "prod"},
'success': onSkuDetails,
'failure': onSkuDetailsFailed
});
}
function onSkuDetails(response) {
console.log("onSkuDetails", response);
var products = response.response.details.inAppProducts;
var count = products.length;
for (var i = 0; i < count; i++) {
var product = products[i];
addProductToUI(product);
}
statusDiv.text("");
getLicenses();
}
function onSkuDetailsFailed(response) {
console.log("onSkuDetailsFailed", response);
statusDiv.text("Error retreiving product list. (" + response.response.errorType + ")");
}
I received this same error because I mistakenly changed the app id inside buy.js to my own app id. I thought that this was the way that the in-app purchase mechanism connected to my app in the chrome web store to access the in-app purchases, but this is not the case at all. What I guess the app-id inside buy.js is the connection to the in-app purchase mechanism built inside Chrome.
So I suggest you try again with the original unmodified buy.js that comes with the test app sample zip package and see if that changes.
The consequence of all of this, is that as far as I can determine it is not possible to debug the in-app purchase flow mechanism, because you can only make it work with a already published app on which in-app purchases have been specified and as such you cannot access the Chrome console. I have not tried unpublishing the app, perhaps that might work. What you cannot do, is clone the app and load it again as an unpackaged extension (as that will of course have a different app-id).
Hope this helps.

chrome.management.getAll does not return Chrome Store's app data

I am now writing a new tab page replacement for Chrome 33.
While I am using chrome.management.getAll() to get app list, I found a strange thing.
Here is my code:
document.addEventListener('DOMContentLoaded', function () {
...
chrome.management.getAll(getAllApps);
...});
function getAllApps(data) {
...
console.log("Installed App Count:" + data.length);
for (var i = data.length - 1; i >= 0; i--) {
console.log("Found App: " + data[i].name + " type:" + data[i].type);
if (data[i].type == 'theme' ||
data[i].type == 'extension' ) {
continue;
};
...
}
}
The output never lists Chrome Store.
But if I use chrome.management.get(), I could get the record of Chrome Store by its id.
Is there anything wrong in my code? Or is the Store is intended to be hidden?
Thank you. It is my first question here, so if there is any inappropriate words in my question, please forgive me.
The Store app is a component extension. Those extensions are built in to Chrome, not installed. As you can see from the documentation, getAll() returns only the user's installed extensions.
Your best bet is to hardcode the list of extensions that appear in a brand-new profile, which will consist only of component items (unless you're on a machine you don't control). Over time that list will diverge from the canonical list in the source code.
Both chrome.management.get() and chrome.management.getAll() show information about apps/extensions/themes installed on local computer, not information from Chrome Web Store.

openDatabase creates error in Android PhoneGap application

I built a basic phone app using HTML5 and JavaScript (including JQTouch), and then used PhoneGap to turn it into an Android app (after many traumas - seems that PhoneGap and Windows computers don't get along too well).
The app works well in Chrome, but on an Android emulator the following error shows up in LogCat:
06-07 21:38:51.711: DEBUG/WebCore(204): Console: ReferenceError: Can't find variable: openDatabase line: 9 source: file:///android_asset/www/handicap.js
This refers to the following line in handicap.js:
db = openDatabase('Handicaps', '1.0', 'Handicaps', 65536);
The wider context of this piece of code is:
// initialise all important functions
$(document).ready(function(){
$('#newrace form').submit(saveRace);
$('#newrace form').submit(setTitle);
$('#enterhandicaps form').submit(savePrediction);
$('#enterhandicaps form').submit(refreshEntries);
$('#calcraces').click(raceList);
// create database to hold data on predicted and actual times
db = openDatabase('Handicaps', '1.0', 'Handicaps', 65536);
db.transaction(
function(transaction) {
transaction.executeSql(
'CREATE TABLE IF NOT EXISTS predictions (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,racename TEXT NOT NULL, runner TEXT NOT NULL, prediction INTEGER, start TEXT, finish TEXT, position TEXT);'
);
transaction.executeSql(
'CREATE TABLE IF NOT EXISTS races (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,racename TEXT NOT NULL, date TEXT, distance REAL);'
);
transaction.executeSql(
'CREATE TABLE IF NOT EXISTS autocompletion (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,runner TEXT NOT NULL, value TEXT,racename TEXT NOT NULL);'
);
}
);
}
);
On looking at other people having similar problems on stackoverflow, I've tried the suggestion of using only Android versions below 2.2 but that has not helped. Any other suggestions?
Could be something very obvious that I've missed, as I'm completely new to this.
The complete code for the app in web browser form is at https://github.com/fhr/Handicap-timer-app if that helps.
Can you share your app code in the app format with all the references to phonegap.js and so on ? Also I do not see your code using the window object. As per the phonegap apis the correct way to use the openDatabase() is var db = window.openDatabase(). Also, it would help if you could also mention the version of pg that you are using.
well i think its trying to open the file "file:///android_asset/www/handicap.js"
as opposed to where a db normally is //data/data//database/dbfile (normally no extension)
please post more code
i think its the opendatabase that your using.
Override onExceededDatabaseQuota method in your WebChromeClient Object.
#Override
public void onExceededDatabaseQuota(String url, String databaseIdentifier,
long currentQuota, long estimatedSize, long totalUsedQuota,
WebStorage.QuotaUpdater quotaUpdater) {
Log.d("test", "onExceededDatabaseQuota : " + " currentQuota=" + currentQuota
+ " estimatedSize=" + estimatedSize + " totalUsedQuota=" + totalUsedQuota);
quotaUpdater.updateQuota(estimatedSize * 2);
}

Categories

Resources