Skip to content

Commit e1e3c61

Browse files
committed
1. Added new method for altering table.
1 parent 4a3dc1d commit e1e3c61

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

.idea/caches/build_file_checksums.ser

0 Bytes
Binary file not shown.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ android {
1515
defaultConfig {
1616
minSdkVersion 19
1717
targetSdkVersion 28
18-
versionCode 36 // this indicates the number of releases of library
19-
versionName "1.4.0" // this indicates the current version of library
18+
versionCode 42 // this indicates the number of releases of library
19+
versionName "1.6.3" // this indicates the current version of library
2020
}
2121

2222
buildTypes {

app/src/main/java/com/amit/db/DBHelper.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,59 @@ public DBHelper createTable(String tableName)
992992

993993
return this;
994994
}
995+
996+
//#region COMMENTS FOR alterTable method
997+
/**
998+
* 2019 April 15 - Monday - 01:13 PM
999+
* alter table method
1000+
*
1001+
* @param tableName - name of the table where column is to be added
1002+
*
1003+
* this method will alter the table and will add new column to the table
1004+
**/
1005+
//#endregion COMMENTS FOR alterTable method
1006+
public DBHelper alterTable(String tableName)
1007+
{
1008+
try
1009+
{
1010+
if (dbColumnArrayList == null || dbColumnArrayList.size() == 0)
1011+
{
1012+
Log.e(TAG, "alterTable: No Db Columns were provided.");
1013+
return this;
1014+
}
1015+
1016+
for (int i = 0; i < dbColumnArrayList.size(); i++)
1017+
{
1018+
String columnName = dbColumnArrayList.get(i).columnName;
1019+
String columnDataType = dbColumnArrayList.get(i).columnDataType;
1020+
1021+
String query = "SELECT COUNT(*) FROM pragma_table_info('" + tableName + "') " +
1022+
"WHERE name = '" + columnName + "'";
1023+
1024+
int count = db.getRecordCount(query);
1025+
1026+
if (count == 0)
1027+
{
1028+
query = "ALTER TABLE " + tableName + " ADD COLUMN " + columnName + " " + columnDataType;
1029+
Log.e(TAG, "alterTable: query for adding new column or altering table is: " + query);
1030+
db.getWritableDatabase().execSQL(query);
1031+
}
1032+
else
1033+
{
1034+
Log.e(TAG, "alterTable: " + columnName + " already exists in " + tableName);
1035+
}
1036+
}
1037+
1038+
return this;
1039+
}
1040+
catch (Exception e)
1041+
{
1042+
Log.e(TAG, "alterTable: exception while altering table:\n");
1043+
e.printStackTrace();
1044+
1045+
return null;
1046+
}
1047+
}
9951048

9961049
//#region COMMENTS FOR insertData method
9971050
/**

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlinVersion = '1.3.21'
4+
ext.kotlinVersion = '1.3.30'
55
ext.supportLibraryVersion = '28.0.0'
66

77
repositories {
@@ -10,7 +10,7 @@ buildscript {
1010
}
1111

1212
dependencies {
13-
classpath 'com.android.tools.build:gradle:3.3.1'
13+
classpath 'com.android.tools.build:gradle:3.3.2'
1414
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1515
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
1616

0 commit comments

Comments
 (0)