Skip to content

Commit ab391dc

Browse files
author
Andrew Porebski
committed
Add support for ALTER TABLe command. Upgrade buildToolsVersion to 27.0.3 - min revision for com.android.tools.build:gradle:3.1.4.
Issue: https://github.com/andpor/react-native-sqlite-storage/issues/312
1 parent 35be64c commit ab391dc

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

src/android-native/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def safeExtGet(prop, fallback) {
1717

1818
android {
1919
compileSdkVersion safeExtGet('compileSdkVersion', 23)
20-
buildToolsVersion safeExtGet('buildToolsVersion', '23.0.1')
20+
buildToolsVersion safeExtGet('buildToolsVersion', '27.0.3')
2121

2222
defaultConfig {
2323
minSdkVersion safeExtGet('minSdkVersion', 16)
@@ -39,6 +39,6 @@ repositories {
3939
}
4040

4141
dependencies {
42-
compile 'com.facebook.react:react-native:0.14.+'
43-
compile files('libs/sqlite-connector.jar')
42+
implementation 'com.facebook.react:react-native:0.14.+'
43+
implementation files('libs/sqlite-connector.jar')
4444
}

src/android-native/src/main/java/io/liteglue/SQLiteAndroidDatabase.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,25 @@ else if (queryType == QueryType.insert && queryParams != null) {
172172
}
173173
}
174174

175+
// ALTER:
176+
else if (queryType == QueryType.alter) {
177+
FLog.d("executeSqlBatch","ALTER");
178+
needRawQuery = false;
179+
180+
try {
181+
mydb.execSQL(query);
182+
183+
queryResult = Arguments.createMap();
184+
queryResult.putInt("rowsAffected", 0);
185+
} catch (SQLiteException ex) {
186+
// report error result with the error message
187+
// could be constraint violation or some other error
188+
ex.printStackTrace();
189+
errorMessage = ex.getMessage();
190+
FLog.v("executeSqlBatch", "SQLiteDatabase.execSQL(): Error=" + errorMessage);
191+
}
192+
}
193+
175194
else if (queryType == QueryType.begin) {
176195
needRawQuery = false;
177196
try {
@@ -367,6 +386,7 @@ static enum QueryType {
367386
insert,
368387
delete,
369388
select,
389+
alter,
370390
begin,
371391
commit,
372392
rollback,

src/android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def safeExtGet(prop, fallback) {
1717

1818
android {
1919
compileSdkVersion safeExtGet('compileSdkVersion', 23)
20-
buildToolsVersion safeExtGet('buildToolsVersion', '23.0.1')
20+
buildToolsVersion safeExtGet('buildToolsVersion', '27.0.3')
2121

2222
defaultConfig {
2323
minSdkVersion safeExtGet('minSdkVersion', 16)
@@ -35,5 +35,5 @@ repositories {
3535
}
3636

3737
dependencies {
38-
compile 'com.facebook.react:react-native:0.14.+'
38+
implementation 'com.facebook.react:react-native:0.14.+'
3939
}

src/android/src/main/java/org/pgsqlite/SQLitePlugin.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ private void executeSqlBatch(String dbname, String[] queries, ReadableArray[] qu
637637

638638
// INSERT:
639639
else if (queryType == QueryType.insert && queryParams != null) {
640+
FLog.d("executeSqlBatch","INSERT");
640641
needRawQuery = false;
641642

642643
SQLiteStatement myStatement = mydb.compileStatement(query);
@@ -666,6 +667,25 @@ else if (queryType == QueryType.insert && queryParams != null) {
666667
}
667668
}
668669

670+
// ALTER:
671+
else if (queryType == QueryType.alter) {
672+
FLog.d("executeSqlBatch","ALTER");
673+
needRawQuery = false;
674+
675+
try {
676+
mydb.execSQL(query);
677+
678+
queryResult = Arguments.createMap();
679+
queryResult.putInt("rowsAffected", 0);
680+
} catch (SQLiteException ex) {
681+
// report error result with the error message
682+
// could be constraint violation or some other error
683+
ex.printStackTrace();
684+
errorMessage = ex.getMessage();
685+
FLog.v("executeSqlBatch", "SQLiteDatabase.execSQL(): Error=" + errorMessage);
686+
}
687+
}
688+
669689
else if (queryType == QueryType.begin) {
670690
needRawQuery = false;
671691
try {
@@ -1027,6 +1047,7 @@ private enum QueryType {
10271047
insert,
10281048
delete,
10291049
select,
1050+
alter,
10301051
begin,
10311052
commit,
10321053
rollback,

0 commit comments

Comments
 (0)