Еще немного закрытия соединения с базой

This commit is contained in:
2024-08-09 07:25:00 +05:00
parent d2ccd6bc8f
commit 3c5b23465d

View File

@ -293,19 +293,13 @@ public class LocustActivity extends FragmentActivity implements LocationListener
if (((selectDB)spiCountry).getValue() != null && !((selectDB)spiCountry).getValue().equals("")) { if (((selectDB)spiCountry).getValue() != null && !((selectDB)spiCountry).getValue().equals("")) {
DbOpenHelper dboh = new DbOpenHelper(LocustActivity.this); DbOpenHelper dboh = new DbOpenHelper(LocustActivity.this);
String sql = "select id, name, lon_min from countriesregions where del=0 and country_id=" + ((selectDB)spiCountry).getValue() + " order by name"; String sql = "select id, name, lon_min from countriesregions where del=0 and country_id=" + ((selectDB)spiCountry).getValue() + " order by name";
SQLiteDatabase rdb=null; Cursor cursor = dboh.getReadableDatabase().rawQuery(sql, null);
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery(sql, null);
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
do { do {
((selectDB)spiRegion).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); ((selectDB)spiRegion).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext()); } while (cursor.moveToNext());
} }
cursor.close(); cursor.close();
}finally{
if(rdb!=null) { rdb.close();}
}
dboh.close(); dboh.close();
} }
} }
@ -340,7 +334,8 @@ public class LocustActivity extends FragmentActivity implements LocationListener
// @Override // @Override
// public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// //
// //SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); // //SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
// //format.setTimeZone(TimeZone.getTimeZone("UTC"));
// //LocustActivity.this.edtDate.setText(format.format(curDateTime)); // //LocustActivity.this.edtDate.setText(format.format(curDateTime));
// //
// //Теперь выбираем время // //Теперь выбираем время
@ -376,7 +371,8 @@ public class LocustActivity extends FragmentActivity implements LocationListener
// //
// if (!LocustActivity.this.edtDate.getText().toString().equals("")) { // if (!LocustActivity.this.edtDate.getText().toString().equals("")) {
// Date date = null; // Date date = null;
// SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); // SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
// //format.setTimeZone(TimeZone.getTimeZone("UTC"));
// try { // try {
// date = format.parse(LocustActivity.this.edtDate.getText().toString()); // date = format.parse(LocustActivity.this.edtDate.getText().toString());
// } catch (ParseException e) { // } catch (ParseException e) {
@ -434,14 +430,19 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiBioBiotope).addField("", ""); ((selectDB)spiBioBiotope).addField("", "");
// Выбираем страны и заполняем поля // Выбираем страны и заполняем поля
dboh = new DbOpenHelper(this); dboh = new DbOpenHelper(this);
SQLiteDatabase rdb = null;
cursor = dboh.getReadableDatabase().rawQuery("select b.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = b.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),b.name) name from list_biotope b where b.del=0 order by b.name", null); try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select b.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = b.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),b.name) name from list_biotope b where b.del=0 order by b.name", null);
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
do { do {
((selectDB)spiBioBiotope).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id"))); ((selectDB)spiBioBiotope).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext()); } while (cursor.moveToNext());
} }
cursor.close(); cursor.close();
}finally{
if(rdb!=null){ rdb.close(); }
}
dboh.close(); dboh.close();
spiBioGreenery = findViewById(R.id.spiBioGreenery); // Растительность spiBioGreenery = findViewById(R.id.spiBioGreenery); // Растительность