8000 Fixed in Blob handling · NathanaelA/nativescript-sqlite@271c78a · GitHub
[go: up one dir, main page]

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

Commit 271c78a

Browse files
committed
Fixed in Blob handling
1 parent 6d7b158 commit 271c78a

File tree

14 files changed

+20158
-90
lines changed

14 files changed

+20158
-90
lines changed

demo/app/App_Resources/Android/app.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
android {
1313
defaultConfig {
14-
minSdkVersion 17
14+
minSdkVersion 21
1515
generatedDensities = []
1616
}
1717
aaptOptions {

demo/app/App_Resources/Android/src/main/AndroidManifest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
android:allowBackup="true"
2020
android:icon="@drawable/icon"
2121
android:label="@string/app_name"
22-
android:theme="@style/AppTheme">
22+
android:theme="@style/AppTheme"
23+
android:requestLegacyExternalStorage="true"
24+
>
2325

2426
<activity
2527
android:name="com.tns.NativeScriptActivity"
28+
android:launchMode="singleInstance"
2629
android:label="@string/title_activity_kimera"
2730
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|locale|uiMode"
2831
android:theme="@style/LaunchScreenTheme">

demo/app/App_Resources/Android/src/main/java/RedundantClassNameWithTooManyMethods.java

Lines changed: 20004 additions & 0 deletions
Large diffs are not rendered by default.

demo/app/App_Resources/Android/src/main/res/values-v21/styles.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<resources>
2+
<resources xmlns:android="http://schemas.android.com/apk/res/android">
33

44
<!-- Application theme -->
5-
<style name="AppTheme" parent="AppThemeBase">
5+
<style name="AppThemeBase21" parent="AppThemeBase">
6+
<item name="android:windowTranslucentStatus">true</item>
67
<item name="android:datePickerStyle">@style/SpinnerDatePicker</item>
78
<item name="android:timePickerStyle">@style/SpinnerTimePicker</item>
89
</style>
910

11+
<style name="AppTheme" parent="AppThemeBase21">
12+
</style>
13+
1014
<!-- Default style for DatePicker - in spinner mode -->
1115
<style name="SpinnerDatePicker" parent="android:Widget.Material.Light.DatePicker">
1216
<item name="android:datePickerMode">spinner</item>
@@ -19,5 +23,6 @@
1923

2024
<style name="NativeScriptToolbarStyle" parent="NativeScriptToolbarStyleBase">
2125
<item name="android:elevation">4dp</item>
22-
</style>
26+
<item name="android:paddingTop">24dp</item>
27+
</style>
2328
</resources>

demo/app/App_Resources/Android/src/main/res/values/colors.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
<color name="ns_primaryDark">#757575</color>
55
<color name="ns_accent">#33B5E5</color>
66
<color name="ns_blue">#272734</color>
7-
</resources>
7+
<color name="green">#36b115</color>
8+
<color name="red">#960b0b</color>
9+
</resources>

demo/app/App_Resources/Android/src/main/res/values/styles.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<item name="colorAccent">@color/ns_accent</item>
1111

1212
<item name="android:windowBackground">@drawable/splash_screen</item>
13-
14-
<item name="android:windowActionBarOverlay">true</item>
13+
14+
<item name="android:windowActionBarOverlay">true</item>
1515
<item name="android:windowTranslucentStatus">true</item>
1616

1717
</style>
@@ -42,4 +42,4 @@
4242

4343
<style name="NativeScriptToolbarStyle" parent="NativeScriptToolbarStyleBase">
4444
</style>
45-
</resources>
45+
</resources>

demo/app/icon.sqlite

41.3 KB
Binary file not shown.

demo/app/main-page.js

Lines changed: 78 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
const sqlite = require('@proplugins/nativescript-sqlite');
1+
const sqlite = require('nativescript-sqlite');
22
const ObservableArray = require("@nativescript/core/data/observable-array").ObservableArray;
3+
const FileSystemAccess = require("@nativescript/core/file-system/file-system-access").FileSystemAccess;
34

45

56
//var Tracing = require('./tracing.js');
67
//Tracing(sqlite, {ignore: ["close", "resultType", "valueType", "_toStringArray", "_getResultEngine"], disableAddedFunction: true});
78

8-
var dbname = 'name_db.sqlite';
9-
var db = null;
10-
var page = null;
9+
let dbname = 'name_db.sqlite';
10+
let db = null;
11+
let page = null;
1112

12-
var data = new ObservableArray();
13+
const data = new ObservableArray();
1314

1415
if (sqlite.HAS_COMMERCIAL) {
1516
console.log("Using Commercial");
@@ -36,34 +37,40 @@ if (sqlite.HAS_SYNC) {
3637
}
3738

3839

39-
exports.pageLoaded = function(args) {
40+
exports.pageLoaded = async function (args) {
4041
page = args.object;
4142
page.bindingContext = {names: data};
4243

4344
if (!sqlite.exists(dbname)) {
4445
sqlite.copyDatabase(dbname);
4546
}
46-
new sqlite(dbname, {key: 'testing', multithreading: !!sqlite.HAS_COMMERCIAL, migrate: true}, function(err, dbConnection) {
47-
if (err) {
48-
console.log(err, err.stack);
49-
}
50-
db = dbConnection;
51-
db.resultType(sqlite.RESULTSASOBJECT);
47+
try {
48+
let myDb = await sqlite(dbname, {key: 'testing', multithreading: !!sqlite.HAS_COMMERCIAL , migrate: true},
49+
);
5250

53-
db.version().then(function (results) {
54-
console.log("User Version: ", results, typeof results, Number.isNumber(results)); //, String.isString(results));
55-
});
51+
let b = function (err, dbConnection) {
52+
if (err) {
53+
console.log(err, err.stack);
54+
}
55+
db = dbConnection;
56+
db.resultType(sqlite.RESULTSASOBJECT);
5657

57-
if (sqlite.HAS_ENCRYPTION) {
58-
db.get("PRAGMA cipher_version;").then(function(results) {
59-
console.log("Cipher version", results['cipher_version']);
58+
db.version().then(function (results) {
59+
console.log("User Version: ", results, typeof results, Number.isNumber(results)); //, String.isString(results));
6060
});
61-
}
6261

63-
reloadData();
64-
}).catch(function(val) {
65-
console.log("sqlite error", val);
66-
});
62+
if (sqlite.HAS_ENCRYPTION) {
63+
db.get("PRAGMA cipher_version;").then(function (results) {
64+
console.log("Cipher version", results['cipher_version']);
65+
});
66+
}
67+
68+
reloadData();
69+
};
70+
b(null, myDb);
71+
} catch(err) {
72+
console.log("sqlite error", err, err.stack);
73+
}
6774
};
6875

6976
exports.addNewName = function() {
@@ -144,7 +151,19 @@ function reloadData() {
144151
});
145152
}
146153

154+
// So we only keep one copy in memory; we cache this...
155+
let blob;
156+
function loadBlob() {
157+
if (blob != null) { return; }
158+
let fsa = new FileSystemAccess();
159+
blob = fsa.readSync(fsa.getCurrentAppPath()+"/icon.sqlite", (err) => {
160+
console.error("Error", err);
161+
});
162+
}
163+
164+
147165
function setupTests(callback) {
166+
loadBlob();
148167
data.push({name: 'Creating tables and data...', css: 'one'});
149168
db.execSQL('drop table if exists tests;', function(err) {
150169
if (err) { console.log("!---- Drop Err", err); }
@@ -177,21 +196,36 @@ function setupTests(callback) {
177196

178197
function checkRowOfData(inData, validData) {
179198
if (Array.isArray(inData)) {
180-
for (var i = 0; i < inData.length; i++) {
199+
for (let i = 0; i < inData.length; i++) {
181200
if (typeof inData[i] === "number") {
182201
if (inData[i] !== validData[i]) {
183-
if (inData[i]-0.1 > validData[i] || inData[i]+0.1 < validData[i]) {
202+
if (inData[i] - 0.1 > validData[i] || inData[i] + 0.1 < validData[i]) {
184203
return ({status: false, field: i});
185204
}
186205
}
187206
} else {
188207
if (inData[i] !== validData[i]) {
189-
return ({status: false, field: i});
208+
if (inData[i].count && inData[i].count === validData[i].count) {
209+
for (let j = 0; j < inData[i].count; j++) {
210+
if (inData[i][j] !== validData[i][j]) {
211+
return ({status: false, field: i});
212+
}
213+
}
214+
if (inData[i].length && inData[i].length === validData[i].length) {
215+
for (let j = 0; j < inData[i].length; j++) {
216+
if (inData[i][j] !== validData[i][j]) {
217+
return ({status: false, field: i});
218+
}
219+
}
220+
} else {
221+
return ({status: false, field: i});
222+
}
223+
}
190224
}
191225
}
192226
}
193227
} else {
194-
for (var key in inData) {
228+
for (let key in inData) {
195229
if (inData.hasOwnProperty(key)) {
196230
if (typeof inData[key] === "number") {
197231
if (inData[key] !== validData[key]) {
@@ -215,9 +249,9 @@ function runATest(options, callback) {
215249
//console.log("!-------------- Starting Test", options.name);
216250

217251
//data.push({name: "Starting test"+options.name});
218-
var checkResults = function(err, inData) {
252+
const checkResults = function(err, inData) {
219253
//console.log("!-------------- Checking Results", options.name, "Error: ", err, "Data:", inData);
220-
var passed = true;
254+
let passed = true;
221255
if (err) {
222256
console.log("!------------ Error", err.toString());
223257
data.push({name: options.name + " test failed with: ", css: 'one'});
@@ -236,8 +270,8 @@ function runATest(options, callback) {
236270
return callback(passed);
237271
}
238272
//console.log("!------------ Data Returned", inData.length, inData);
239-
for (var i=0;i<inData.length;i++) {
240-
var result = checkRowOfData(inData[i], options.results[i]);
273+
for (let i=0;i<inData.length;i++) {
274+
let result = checkRowOfData(inData[i], options.results[i]);
241275
if (!result.status) {
242276
passed = false;
243277
data.push({name: options.name + " test failed on row: "+i+", field: "+result.field, css: 'one'});
@@ -248,17 +282,17 @@ function runATest(options, callback) {
248282
callback(passed);
249283
};
250284

251-
var checkRow = 0;
252-
var checksPassed = true;
253-
var checkEachResults = function(err, inData) {
285+
let checkRow = 0;
286+
let checksPassed = true;
287+
const checkEachResults = function(err, inData) {
254288
if (!checksPassed) return;
255289
if (err) {
256290
data.push({name: options.name + " test failed with "+err.toString(), css: 'one'});
257291
console.log(options.name + " test failed with ",err.toString());
258292
checksPassed = false;
259293
return;
260294
}
261-
var result = checkRowOfData(inData, options.results[checkRow]);
295+
const result = checkRowOfData(inData, options.results[checkRow]);
262296
if (!result.status) {
263297
checksPassed = false;
264298
data.push({name: options.name + " test failed on row: "+checkRow+", field: "+result.field, css: 'one'});
@@ -470,7 +504,7 @@ function setupPreparedTests(callback) {
470504
if (err) {
471505
console.log("!---- Drop Err", err);
472506
}
473-
db.execSQL('create table preparetests (`int_field` integer, `num_field` numeric, `real_field` real, `text_field` text)', function (err) {
507+
db.execSQL('create table preparetests (`int_field` integer, `num_field` numeric, `real_field` real, `text_field` text, `blob_field` blob)', function (err) {
474508
if (err) {
475509
data.push({name: 'Failed to create tables and data...', css: 'one'});
476510
console.log("!---- Create Table err", err);
@@ -509,9 +543,9 @@ function runPreparedTests(callback) {
509543
},
510544
{
511545
name: 'Commit/Prepare All', sql: 'select * from preparetests order by int_field', results: [
512-
[1, 1.2, 2.4, 'Text1'],
513-
[2, 2.4, 3.6, 'Text2'],
514-
[3, 3.6, 4.8, 'Text3']
546+
[1, 1.2, 2.4, 'Text1', blob],
547+
[2, 2.4, 3.6, 'Text2', blob],
548+
[3, 3.6, 4.8, 'Text3', blob]
515549
], use: 1
516550
}];
517551
runTestGroup(tests, callback);
@@ -528,18 +562,18 @@ function createPreparedData(rollback, callback) {
528562
}
529563
try {
530564
console.log("!------------- Create Prepared Tests");
531-
var prepared = db.prepare("insert into preparetests (int_field, num_field, real_field, text_field) values (?,?,?,?);");
565+
var prepared = db.prepare("insert into preparetests (int_field, num_field, real_field, text_field, blob_field) values (?,?,?,?,?);");
532566
} catch(err) {
533567
console.log("Error creating prepare data", err);
534568
}
535569
db.begin();
536-
prepared.execute([1,1.2,2.4,"Text1"], function(err) {
570+
prepared.execute([1,1.2,2.4,"Text1", blob], function(err) {
537571
if (err) {
538572
data.push({name: 'Failed to insert data...', 'css': 'one'});
539573
console.log("!---- Insert err", err, err.stack);
540574
return;
541575
}
542-
prepared.execute([[2,2.4,3.6,"Text2"], [3,3.6,4.8,"Text3"]], function(err2) {
576+
prepared.execute([[2,2.4,3.6,"Text2", blob], [3,3.6,4.8,"Text3", blob]], function(err2) {
543577
if (err2) {
544578
data.push({name: 'Failed to create tables and data...', css: 'one'});
545579
console.log("!---- Insert err", err, err && err.stack);
@@ -570,6 +604,8 @@ function runTests() {
570604
runPreparedTests(function () {
571605
data.push({name: "-----------------------------", css: 'two'});
572606
data.push({name: 'Tests completed...', css: 'two'});
607+
console.log("-----------------------------");
608+
console.log("Tests completed!");
573609
});
574610
});
575611
});

demo/app/main-page.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<GridLayout row="1" rows="*,auto" columns="*,auto" class="border" >
1414
<TextField id="entry" hint="Type a new name" text=""/>
1515
<Button id="go" col="1" text="Add" tap="addNewName"/>
16-
<Label row="1" colSpan="2" text="(c) 2015-2019, Master Technology" class="copyright" android:tap="openMT"/>
16+
<Label row="1" colSpan="2" text="(c) 2015-2020, Master Technology" class="copyright" android:tap="openMT"/>
1717
</GridLayout>
1818
</GridLayout>
1919
</Page>

demo/package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22
"nativescript": {
33
"id": "org.proplugins.demo.sqlite",
44
"tns-ios": {
5-
"version": "6.2.0"
5+
"version": "6.5.0"
66
},
77
"tns-android": {
8-
"version": "6.3.1"
8+
"version": "6.5.0"
99
}
1010
},
1111
"description": "SQLite Demo Application",
1212
"license": "MIT",
1313
"repository": "<fill-your-repository-here>",
1414
"dependencies": {
15-
"@proplugins/nativescript-sqlite": "file:../src",
16-
"nativescript-sqlite-commercial": "file:../nativescript-sqlite-commercial-1.4.1.tgz",
15+
"nativescript-sqlite": "file:../src",
16+
"nativescript-sqlite-commercial": "file:../nativescript-sqlite-commercial-1.4.2.tgz",
17+
"nativescript-sqlite-sync": "file:../nativescript-sqlite-sync-1.4.0.tgz",
1718
"nativescript-theme-core": "~1.0.4",
18-
"tns-core-modules": "~6.3.0"
19+
"tns-core-modules": "latest"
1920
},
2021
"devDependencies": {
21-
"nativescript-dev-webpack": "~1.4.0",
22-
"nativescript-worker-loader": "^0.9.5"
22+
"nativescript-dev-webpack": "latest",
23+
"nativescript-worker-loader": "latest"
2324
},
2425
"readme": "SQLite Demo Application"
2526
}

0 commit comments

Comments
 (0)
0