Skip to content

Commit

Permalink
fixed update null bug
Browse files Browse the repository at this point in the history
  • Loading branch information
p32929 committed Jul 15, 2020
1 parent d380980 commit 195f2d7
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ allprojects {
Add the dependency
```
dependencies {
implementation 'com.github.p32929:EasiestSqlLibrary:1.0.0.1'
implementation 'com.github.p32929:EasiestSqlLibrary:1.0.0.2'
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

Expand All @@ -19,8 +21,8 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "onCreate: ");

// Init
easiestDB = EasiestDB.init(this)
.addTableColumns("table 1",
new Column("Column a1", "text"),
Expand All @@ -31,27 +33,50 @@ protected void onCreate(Bundle savedInstanceState) {
new Column("Column b2", "text", "unique")
)
.doneAddingTables();
Log.d(TAG, "init: ");
}

// Add
public void add(View view) {
boolean added = easiestDB.addDataInTable(0,
new Datum(1, "Value1"),
new Datum(2, "Value2")
);
Log.d(TAG, "add: " + added);
}

// Get all
public void get(View view) {
Cursor cursor = easiestDB.getAllDataFrom(0);
if (cursor != null) {
while (cursor.moveToNext()) {

// int value1 = cursor.getInt(columnNumber);
// String value2 = cursor.getString(columnNumber);
// double value3 = cursor.getDouble(columnNumber);

String id = cursor.getString(0);

Log.d(TAG, "get: " + id);
}
}
}

boolean deleted = easiestDB.deleteDatabase();
int count = 1;

public void update(View view) {
boolean updated = easiestDB.updateData(0, count,
new Datum(1, "NValue" + count),
new Datum(2, "NValue" + count)
);
count++;
Log.d(TAG, "update: " + updated);
}

public void delete(View view) {
boolean deleted = easiestDB.deleteRow(0, 1);
Log.d(TAG, "delete: " + deleted);
}

public void deleteAll(View view) {
boolean deleted = easiestDB.deleteDatabase();
Log.d(TAG, "deleteAll: " + deleted);
}
}
34 changes: 32 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="add"
android:text="ADD" />

</RelativeLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="get"
android:text="GET" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="update"
android:text="UPDATE" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="delete"
android:text="DELETE" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="deleteAll"
android:text="DELETE ALL" />

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public boolean deleteRowIfValuesMatchIn(int tableIndex, Datum data) {

// Update data
public boolean updateData(int tableIndex, int rowNumber, Datum... data) {
contentValues = new ContentValues();
for (int i = 0; i < data.length; i++) {
if (data[i].getColumnName().isEmpty()) {
contentValues.put(tableArrayList.get(tableIndex).getColumns()[i].getColumnName(), data[i].getValue());
Expand Down Expand Up @@ -251,7 +252,6 @@ private String getColumnNameFromTableAndcolumnIndex(int tableIndex, int columnIn

// Add Table
public EasiestDB addTableColumns(String tableName, Column... columns) {

Table table = new Table(
tableName.replace(" ", "_"),
columns
Expand Down

0 comments on commit 195f2d7

Please sign in to comment.