From 236a7c021bf43c49158769bbe27996e7f0f53d19 Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Sun, 4 Sep 2022 14:52:14 -0700 Subject: [PATCH] sqlite read --- .../page/s3manager/MainActivity.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/asgardius/page/s3manager/MainActivity.java b/app/src/main/java/asgardius/page/s3manager/MainActivity.java index 94da3af..b854c5b 100644 --- a/app/src/main/java/asgardius/page/s3manager/MainActivity.java +++ b/app/src/main/java/asgardius/page/s3manager/MainActivity.java @@ -9,6 +9,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import android.content.Intent; +import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.View; @@ -53,8 +54,16 @@ public class MainActivity extends AppCompatActivity { MyDbHelper dbHelper = new MyDbHelper(this); SQLiteDatabase db = dbHelper.getWritableDatabase(); if (db != null) { - // Hacer las operaciones que queramos sobre la base de datos + // Database Queries System.out.println("Database OK"); + Name = new ArrayList(); + Img = new ArrayList(); + String query = "SELECT id FROM account"; + Cursor cursor = db.rawQuery(query,null); + while (cursor.moveToNext()){ + Name.add(cursor.getString(0)); + Img.add(R.drawable.account); + } } else { System.out.println("Database Missing"); } @@ -65,12 +74,8 @@ public class MainActivity extends AppCompatActivity { public void run() { try { //Your code goes here - Name = new ArrayList(); - Img = new ArrayList(); // Print bucket names //System.out.println("Buckets:"); - Name.add("account"); - Img.add(R.drawable.account); System.out.println(Name); @@ -160,9 +165,13 @@ public class MainActivity extends AppCompatActivity { MyDbHelper dbHelper = new MyDbHelper(this); SQLiteDatabase db = dbHelper.getWritableDatabase(); if (db != null) { - // Hacer las operaciones que queramos sobre la base de datos - db.execSQL("INSERT INTO account VALUES (\"test account\", \"https://object.asgardius.company\", \"asgardius\", \"DTMp5kftamr49Ke7\")"); - System.out.println("Insert OK"); + // Database Queries + try { + db.execSQL("INSERT INTO account VALUES (\"test account\", \""+endpoint+"\", \""+username+"\", \""+password+"\")"); + System.out.println("Insert OK"); + } catch (Exception e) { + System.out.println("Insert error"); + } } }