[TIMOB-20222] Windows: Error while createcollection on Windows Phone
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-01-31T02:31:59.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 5.3.0 |
Components | Windows |
Labels | appcelerator, windows8.1, windows_phone |
Reporter | Alberto Bonacina |
Assignee | Christopher Williams |
Created | 2016-01-11T12:18:28.000+0000 |
Updated | 2017-10-16T22:26:11.000+0000 |
Description
I create a simple alloy app project but in my alloy.js if i put this line
Alloy.Collections.category = Alloy.createCollection('category');
when the app starts I see in the console this error
[ERROR] : Application Error: {
[ERROR] : "line": 2,
[ERROR] : "column": 10,
[ERROR] : "message": "Error while require(/app) Error while require(alloy/models/Category) unknown exception",
[ERROR] : "native_stack": [
[ERROR] : "JSExportClass<class Titanium::GlobalObject>::CallNamedFunction"
[ERROR] : ]
[ERROR] : }
everything works if a run the app on Android and iOS, but it crash if i run it in Windows Phone Simulator.
This is my model category.js
exports.definition = {
config: {
columns: {
"id": "INTEGER PRIMARY KEY AUTOINCREMENT",
"name": "TEXT",
"counter": "INTEGER",
"default_image": "TEXT"
},
defaults: {
"name": "TEXT",
"counter": "INTEGER",
"default_image": "TEXT"
},
adapter: {
"type": "sql",
"tablename": "category",
"collection_name": "category",
"db_file": "/db.sqlite",
"db_name": "category",
"idAttribute": "id",
"remoteBackup": false
}
},
extendModel: function(Model) {
_.extend(Model.prototype, {
// extended functions and properties go here
});
return Model;
},
extendCollection: function(Collection) {
_.extend(Collection.prototype, {
// extended functions and properties go here
});
return Collection;
}
};
Attachments
File | Date | Size |
---|---|---|
erroreDatabase.PNG | 2016-01-11T12:11:58.000+0000 | 81946 |
When I tested this, I see:
Which suggests to me that the database installation isn't working properly in this case here. I'll have to dig deeper and find out why...
Looks to me like this may be because we return a non-null/undefined return value for the Db.execute call here:
If we return an empty result set rather than null/undefined for the
rs
variable, the Alloy code will basically end up gathering no columns and error in a way that I'm seeing. I also used the Windows Phone Power Tools and saw that the database file existed but was 0 bytes. So I think the database file is getting created (so the Db.install looks like it's working).[~AlbWebbergate] Do you actually have a
db.sqlite
database file you use to pre-populate the category database with? It's mentioned in the db_file value, but wasn't sure if you had that file in your app, or were just relying on behavior to effectively ignore that it doesn't exist?Looks like Android has special code to explicitly return null when a SELECT or PRAGMA is issued and has 0 columns in the result: https://github.com/appcelerator/titanium_mobile/blob/bc85170157d3bebc5de1d61a9fe6e34bce84a8c9/android/modules/database/src/java/ti/modules/titanium/database/TiDatabaseProxy.java#L125
https://github.com/appcelerator/titanium_mobile_windows/pull/536
Verified using: Windows 10 Pro Visual Studio 2015 Community Update 2 Appc Core: 5.3.0-46 Appc NPM: 4.2.5-5 Ti SDK: 5.3.0.v20160523083840 Lumia 520 8.1, Lumia 930 10.0 When executing pragma table_info("table_name") on a table with no rows the value returned is now null rather than being an empty Ti.Database.ResultSet. Tested classic using the code below and Alloy using the code provided in description
Closing ticket