I'm going to populate the database using SQLiteadmin, and then I want to connect it to an application written using SugarORM. Is it possible or sugarORM it simply does not know how and i need to use just sqlite. UPD: Or any other way to load the finished data into the application.
1 answer
Maybe! Create a database as you like and connect it to your application using sugar orm. The main thing is that the names of the fields of the classes (which are used by sugar) coincide with the names of the columns of your tables (after all, you will create them "manually"). To do this, you need to copy the base file to the assets folder of your project. Then, the application at startup will check if this file is sitting in data / data and, if not, copy it there from assets. This can be done like this:
private void checkDataBase() { SQLiteDatabase checkDB = null; try { checkDB = SQLiteDatabase.openDatabase(getApplicationContext().getDatabasePath(DB_NAME).getPath(), null, SQLiteDatabase.OPEN_READONLY); } catch (SQLiteException e) { e.printStackTrace(); } if (checkDB != null) { checkDB.close(); } else { try { copyDataBase(); } catch (IOException e) { e.printStackTrace(); } } } private void copyDataBase() throws IOException { InputStream myInput = getApplicationContext().getAssets().open(DB_NAME); OutputStream myOutput = new FileOutputStream(getApplicationContext().getDatabasePath(DB_NAME).getPath()); byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer)) > 0) { myOutput.write(buffer, 0, length); } myOutput.flush(); myOutput.close(); myInput.close(); } |