@capacitor-community/sqlite 5.0.2 → 5.0.3-2.test1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,6 +30,7 @@ import com.getcapacitor.community.database.sqlite.SQLite.UtilsSQLCipher;
30
30
  import com.getcapacitor.community.database.sqlite.SQLite.UtilsSQLite;
31
31
  import com.getcapacitor.community.database.sqlite.SQLite.UtilsSecret;
32
32
  import java.io.File;
33
+ import java.nio.ByteBuffer;
33
34
  import java.security.KeyStore;
34
35
  import java.util.ArrayList;
35
36
  import java.util.Collections;
@@ -797,12 +797,15 @@ public class Database {
797
797
  row.put(colName, c.getDouble(index));
798
798
  break;
799
799
  case FIELD_TYPE_BLOB:
800
- // row.put(colName, c.getBlob(index));
801
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
800
+ byte[] blobVal = c.getBlob(index);
801
+ JSArray arr = this._uSqlite.ByteArrayToJSArray(blobVal);
802
+ row.put(colName, arr);
803
+ /* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
802
804
  row.put(colName, Base64.getEncoder().encodeToString(c.getBlob(index)));
803
805
  } else {
804
806
  row.put(colName, JSONObject.NULL);
805
807
  }
808
+ */
806
809
  break;
807
810
  case FIELD_TYPE_NULL:
808
811
  row.put(colName, JSONObject.NULL);
@@ -558,13 +558,12 @@ public class ImportFromJson {
558
558
  // Delete
559
559
  isUpdate = false;
560
560
  Object key = tColNames.get(0);
561
- StringBuilder sbQuery =
562
- new StringBuilder("DELETE FROM ")
563
- .append(tableName)
564
- .append(" WHERE ")
565
- .append(tColNames.get(0))
566
- .append(" = ");
567
-
561
+ StringBuilder sbQuery = new StringBuilder("DELETE FROM ")
562
+ .append(tableName)
563
+ .append(" WHERE ")
564
+ .append(tColNames.get(0))
565
+ .append(" = ");
566
+
568
567
  if (key instanceof Integer) sbQuery.append(row.get(0)).append(";");
569
568
  if (key instanceof String) sbQuery.append("'").append(row.get(0)).append("';");
570
569
  stmt = sbQuery.toString();
@@ -9,7 +9,6 @@ import java.util.ArrayList;
9
9
  import java.util.Arrays;
10
10
  import java.util.Iterator;
11
11
  import java.util.List;
12
-
13
12
  import org.json.JSONArray;
14
13
  import org.json.JSONException;
15
14
  import org.json.JSONObject;
@@ -39,12 +38,12 @@ public class UtilsJson {
39
38
  JSObject namesTypes = getTableColumnNamesTypes(db, tableName);
40
39
  ArrayList<String> colNames = new ArrayList<>();
41
40
  if (namesTypes.has("names")) {
42
- colNames = getColumnNames(namesTypes.get("names"));
41
+ colNames = getColumnNames(namesTypes.get("names"));
43
42
  } else {
44
- throw new Exception("isLastModified: Table " + tableName + " no names");
43
+ throw new Exception("isLastModified: Table " + tableName + " no names");
45
44
  }
46
45
 
47
- if (colNames.size() > 0 && colNames.contains("last_modified")) {
46
+ if (colNames.size() > 0 && colNames.contains("last_modified")) {
48
47
  ret = true;
49
48
  break;
50
49
  }
@@ -55,18 +54,18 @@ public class UtilsJson {
55
54
  }
56
55
  }
57
56
 
58
- /**
59
- * Get Column name's list
60
- * @param obj
61
- * @return
62
- */
57
+ /**
58
+ * Get Column name's list
59
+ * @param obj
60
+ * @return
61
+ */
63
62
  public ArrayList<String> getColumnNames(Object obj) {
63
+ ArrayList<String> colNames = new ArrayList<>();
64
+ if (obj instanceof ArrayList) colNames = (ArrayList<String>) obj;
64
65
 
65
- ArrayList<String> colNames = new ArrayList<>();
66
- if (obj instanceof ArrayList) colNames = (ArrayList<String>) obj;
67
-
68
- return colNames;
66
+ return colNames;
69
67
  }
68
+
70
69
  /**
71
70
  * Check existence of sql_deleted column
72
71
  * @param db
@@ -84,7 +83,7 @@ public class UtilsJson {
84
83
  JSObject namesTypes = getTableColumnNamesTypes(db, tableName);
85
84
  ArrayList<String> colNames = new ArrayList<>();
86
85
  if (namesTypes.has("names")) {
87
- colNames = getColumnNames(namesTypes.get("names"));
86
+ colNames = getColumnNames(namesTypes.get("names"));
88
87
  } else {
89
88
  throw new Exception("isSqlDeleted: Table " + tableName + " no names");
90
89
  }
@@ -3,12 +3,15 @@ package com.getcapacitor.community.database.sqlite.SQLite;
3
3
  import android.util.Log;
4
4
  import androidx.sqlite.db.SupportSQLiteDatabase;
5
5
  import com.getcapacitor.JSArray;
6
+ import java.nio.ByteBuffer;
7
+ import java.nio.charset.StandardCharsets;
6
8
  import java.util.ArrayList;
7
9
  import java.util.Arrays;
8
10
  import java.util.List;
9
11
  import net.sqlcipher.Cursor;
10
12
  import org.json.JSONArray;
11
13
  import org.json.JSONException;
14
+ import org.json.JSONObject;
12
15
 
13
16
  public class UtilsSQLite {
14
17
 
@@ -90,7 +93,7 @@ public class UtilsSQLite {
90
93
  Object[] objectList = listArray.toArray();
91
94
  String[] retArray = Arrays.copyOf(objectList, objectList.length, String[].class);
92
95
 
93
- // String[] retArray = listArray.toArray(new String[listArray.size()]);
96
+ // String[] retArray = listArray.toArray(new String[listArray.size()]);
94
97
  return retArray;
95
98
  }
96
99
 
@@ -108,7 +111,7 @@ public class UtilsSQLite {
108
111
 
109
112
  private List<String> trimArray(List<String> listArray) {
110
113
  List<String> trimmedStrings = new ArrayList<String>();
111
- for(String s : listArray) {
114
+ for (String s : listArray) {
112
115
  trimmedStrings.add(s.trim());
113
116
  }
114
117
  return trimmedStrings;
@@ -120,7 +123,17 @@ public class UtilsSQLite {
120
123
  if (jsArray.isNull(i)) {
121
124
  list.add(null);
122
125
  } else {
123
- list.add(jsArray.get(i));
126
+ Object obj = jsArray.get(i);
127
+ if (obj.getClass() == JSONObject.class) {
128
+ if (((JSONObject) obj).getString("type").equals("Buffer")) {
129
+ byte[] bArr = JSONArrayToByteArray(((JSONObject) obj).getJSONArray("data"));
130
+ list.add(bArr);
131
+ } else {
132
+ throw new JSONException("Object not implemented");
133
+ }
134
+ } else {
135
+ list.add(obj);
136
+ }
124
137
  }
125
138
  }
126
139
  return list;
@@ -139,6 +152,14 @@ public class UtilsSQLite {
139
152
  return list;
140
153
  }
141
154
 
155
+ public byte[] JSONArrayToByteArray(JSONArray arr) throws JSONException {
156
+ byte[] bArr = new byte[arr.length()];
157
+ for (int i = 0; i < arr.length(); i++) {
158
+ bArr[i] = (byte) (((int) arr.get(i)) & 0xFF);
159
+ }
160
+ return bArr;
161
+ }
162
+
142
163
  public Boolean parse(Object mVar) {
143
164
  boolean ret = false;
144
165
  if (mVar instanceof JSONArray) {
@@ -146,4 +167,25 @@ public class UtilsSQLite {
146
167
  }
147
168
  return ret;
148
169
  }
170
+
171
+ public int ByteToInt(byte BVal) {
172
+ String comb;
173
+ int out = 0;
174
+ comb = BVal + "";
175
+ out = Integer.parseInt(comb);
176
+ // Get Unsigned Int
177
+ if (out < 0) {
178
+ out += 256;
179
+ }
180
+ return out;
181
+ }
182
+
183
+ public JSArray ByteArrayToJSArray(byte[] BArr) {
184
+ JSArray arr = new JSArray();
185
+
186
+ for (int i = 0; i < BArr.length; i++) {
187
+ arr.put(ByteToInt(BArr[i]));
188
+ }
189
+ return arr;
190
+ }
149
191
  }