Skip to content
This repository was archived by the owner on Jul 7, 2022. It is now read-only.

Commit 1896549

Browse files
committed
getContext can't be a instance function as the majority of what calls it is static.
1 parent cd48871 commit 1896549

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Nathanael Anderson
3+
Copyright (c) 2015, 2016 Nathanael Anderson
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "nativescript-sqlite",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "A sqlite NativeScript module for Android and iOS",
55
"main": "sqlite.js",
66
"nativescript": {
77
"platforms": {
8-
"android": "0.1.1",
8+
"android": "0.1.2",
99
"ios": "0.1.0"
1010
}
1111
},

sqlite.android.js

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**************************************************************************************
2-
* (c) 2015, Master Technology
2+
* (c) 2015, 2016, Master Technology
33
* Licensed under the MIT license or contact me for a support, changes, enhancements,
44
* and/or if you require a commercial licensing
55
*
66
* Any questions please feel free to email me or put a issue up on github
7-
* Version 0.1.0 - Android Nathan@master-technology.com
7+
* Version 0.1.2 - Android Nathan@master-technology.com
88
*************************************************************************************/
99

1010
"use strict";
@@ -241,7 +241,7 @@ function Database(dbname, options, callback) {
241241
if (dbname !== "" && dbname !== ":memory:") {
242242
//var pkgName = appModule.android.context.getPackageName();
243243
//noinspection JSUnresolvedFunction
244-
dbname = this._getContext().getDatabasePath(dbname).getAbsolutePath();
244+
dbname = _getContext().getDatabasePath(dbname).getAbsolutePath();
245245
var path = dbname.substr(0, dbname.lastIndexOf('/') + 1);
246246

247247
// Create "databases" folder if it is missing. This causes issues on Emulators if it is missing
@@ -292,22 +292,6 @@ function Database(dbname, options, callback) {
292292
*/
293293
Database.prototype._isSqlite = true;
294294

295-
/**
296-
* gets the current application context
297-
* @returns {*}
298-
* @private
299-
*/
300-
Database.prototype._getContext = function() {
301-
if (appModule.android.context) {
302-
return (appModule.android.context);
303-
}
304-
var ctx = java.lang.Class.forName("android.app.AppGlobals").getMethod("getInitialApplication", null).invoke(null, null);
305-
if (ctx) return ctx;
306-
307-
ctx = java.lang.Class.forName("android.app.ActivityThread").getMethod("currentApplication", null).invoke(null, null);
308-
return ctx;
309-
};
310-
311295
/***
312296
* This gets or sets the database version
313297
* @param valueOrCallback to set or callback(err, version)
@@ -767,7 +751,7 @@ Database.isSqlite = function(obj) {
767751
*/
768752
Database.exists = function(name) {
769753
//noinspection JSUnresolvedFunction
770-
var dbName = this._getContext().getDatabasePath(name).getAbsolutePath();
754+
var dbName = _getContext().getDatabasePath(name).getAbsolutePath();
771755
var dbFile = new java.io.File(dbName);
772756
return dbFile.exists();
773757
};
@@ -778,7 +762,7 @@ Database.exists = function(name) {
778762
*/
779763
Database.deleteDatabase = function(name) {
780764
//noinspection JSUnresolvedFunction
781-
var dbName = this._getContext().getDatabasePath(name).getAbsolutePath();
765+
var dbName = _getContext().getDatabasePath(name).getAbsolutePath();
782766
var dbFile = new java.io.File(dbName);
783767
if (dbFile.exists()) {
784768
dbFile.delete();
@@ -797,10 +781,10 @@ Database.copyDatabase = function(name) {
797781

798782
//Open your local db as the input stream
799783
//noinspection JSUnresolvedFunction
800-
var myInput = this._getContext().getAssets().open("app/"+name);
784+
var myInput = _getContext().getAssets().open("app/"+name);
801785

802786
//noinspection JSUnresolvedFunction
803-
var dbname = this._getContext().getDatabasePath(name).getAbsolutePath();
787+
var dbname = _getContext().getDatabasePath(name).getAbsolutePath();
804788
var path = dbname.substr(0, dbname.lastIndexOf('/') + 1);
805789

806790
// Create "databases" folder if it is missing. This causes issues on Emulators if it is missing
@@ -856,3 +840,18 @@ Database.VALUESARESTRINGS = 8;
856840

857841
module.exports = Database;
858842

843+
/**
844+
* gets the current application context
845+
* @returns {*}
846+
* @private
847+
*/
848+
function _getContext() {
849+
if (appModule.android.context) {
850+
return (appModule.android.context);
851+
}
852+
var ctx = java.lang.Class.forName("android.app.AppGlobals").getMethod("getInitialApplication", null).invoke(null, null);
853+
if (ctx) return ctx;
854+
855+
ctx = java.lang.Class.forName("android.app.ActivityThread").getMethod("currentApplication", null).invoke(null, null);
856+
return ctx;
857+
}

sqlite.ios.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/************************************************************************************
2-
* (c) 2015, Master Technology
2+
* (c) 2015, 2016 Master Technology
33
* Licensed under the MIT license or contact me for a support, changes, enhancements,
44
* and/or if you require a commercial licensing
55
*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy