sqlite base

This commit is contained in:
Page Asgardius 2022-09-04 14:21:29 -07:00
parent 22b2884162
commit c532171848
2 changed files with 44 additions and 1 deletions

View file

@ -9,6 +9,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
@ -49,6 +50,15 @@ public class MainActivity extends AppCompatActivity {
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(linearLayoutManager);
MyDbHelper dbHelper = new MyDbHelper(this);
SQLiteDatabase db = dbHelper.getWritableDatabase();
if (db != null) {
// Hacer las operaciones que queramos sobre la base de datos
System.out.println("Database OK");
} else {
System.out.println("Database Missing");
}
Thread listaccount = new Thread(new Runnable() {
@Override
@ -122,7 +132,8 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onClick(View view) {
//buttonaction
explorer();
//explorer();
testaccount();
//videoplayer("https://video.asgardius.company/download/videos/41780585-a935-4d53-84c8-45ce97141231-480.mp4");
}
});
@ -145,4 +156,14 @@ public class MainActivity extends AppCompatActivity {
}
private void testaccount() {
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");
}
}
}

View file

@ -0,0 +1,22 @@
package asgardius.page.s3manager;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class MyDbHelper extends SQLiteOpenHelper {
private static final String atcreate = "CREATE TABLE IF NOT EXISTS account(id text UNIQUE, endpoint text, username text, password text)";
private static final String dbname = "accounts.sqlite3";
private static final int dbversion = 3;
public MyDbHelper(Context context) {
super(context, dbname, null, dbversion);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(atcreate);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}