From 116f1e5606b8443c2e04b41de2104b80b4c67ac8 Mon Sep 17 00:00:00 2001 From: igor Date: Sat, 10 Aug 2024 14:09:23 +0500 Subject: [PATCH] +catch Exception --- .../main/java/kz/istt/locust/DBGUITable.java | 7 +- .../java/kz/istt/locust/DbOpenHelper.java | 156 +++++++++++------- .../java/kz/istt/locust/LocustActivity.java | 62 ++++++- .../kz/istt/locust/LocustDelActivity.java | 58 ++++++- .../kz/istt/locust/LocustDelListActivity.java | 7 +- .../kz/istt/locust/LocustHealthActivity.java | 44 ++++- .../istt/locust/LocustHealthListActivity.java | 6 + .../kz/istt/locust/LocustListActivity.java | 6 + .../java/kz/istt/locust/MainActivity.java | 11 +- .../main/java/kz/istt/locust/MainService.java | 3 +- .../java/kz/istt/locust/MapsActivity.java | 2 + .../kz/istt/locust/MySynchronizationNew.java | 14 +- .../kz/istt/locust/MySynchronizationOld.java | 31 +++- .../java/kz/istt/locust/ScanActivity.java | 14 +- .../java/kz/istt/locust/SetupActivity.java | 2 + .../java/kz/istt/locust/SplashScreen.java | 2 + 16 files changed, 339 insertions(+), 86 deletions(-) diff --git a/app/src/main/java/kz/istt/locust/DBGUITable.java b/app/src/main/java/kz/istt/locust/DBGUITable.java index 6d12177..b43187d 100644 --- a/app/src/main/java/kz/istt/locust/DBGUITable.java +++ b/app/src/main/java/kz/istt/locust/DBGUITable.java @@ -10,7 +10,6 @@ import android.util.Log; import android.widget.CheckBox; import android.widget.EditText; import android.widget.Spinner; -import java.sql.SQLException; import com.google.android.material.textfield.TextInputEditText; import java.util.ArrayList; @@ -75,6 +74,8 @@ public class DBGUITable } while (cursor.moveToNext()); } cursor.close(); + }catch(Exception e){ + e.printStackTrace(); }finally{ if(rdb != null) { rdb.close(); } } @@ -121,6 +122,8 @@ public class DBGUITable }while (cursor.moveToNext()); } cursor.close(); + }catch(Exception e){ + e.printStackTrace(); } finally { if (rdb != null) { rdb.close(); } } @@ -303,6 +306,8 @@ public class DBGUITable } } cursor.close(); + }catch(Exception e){ + e.printStackTrace(); }finally{ if(rdb != null) { rdb.close(); } } diff --git a/app/src/main/java/kz/istt/locust/DbOpenHelper.java b/app/src/main/java/kz/istt/locust/DbOpenHelper.java index 92a813c..66bf718 100644 --- a/app/src/main/java/kz/istt/locust/DbOpenHelper.java +++ b/app/src/main/java/kz/istt/locust/DbOpenHelper.java @@ -1588,12 +1588,14 @@ public class DbOpenHelper extends SQLiteOpenHelper } } catch (Exception e) { Log.v(tableName, e.toString(), e); - e.printStackTrace(); + //e.printStackTrace(); } finally { if (c != null) c.close(); } + }catch(Exception e){ + e.printStackTrace(); }finally{ if(rdb != null) { rdb.close(); } } @@ -1603,6 +1605,8 @@ public class DbOpenHelper extends SQLiteOpenHelper /**Функция для обновления или вставки табличных данных*/ public Boolean updateTable(TCTable tbl) { + if(tbl==null) return false; + Cursor cursor; if(tbl.name.equals("countries")) Log.i("igor", "tbl0=" + tbl.name); @@ -1624,88 +1628,102 @@ public class DbOpenHelper extends SQLiteOpenHelper } } - SQLiteDatabase wdb = null; - try { - wdb = this.getWritableDatabase(); - //Переписываем значения существующих полей и выполняем запросы - while(tbl.ReadNextRecord()) + //Переписываем значения существующих полей и выполняем запросы + while(tbl.ReadNextRecord()) + { + if(tbl.name.equals("frmlocustdel")){ + Log.i("igor","tbl.name="+tbl.name); + } + String sql="select 1 from "+tbl.name+" where id = ?"; + String[] par = new String[] { tbl.getRowByName("id").getStrVal() }; + + boolean exists=false; + SQLiteDatabase rdb=null; + try { + rdb = getReadableDatabase(); + cursor = rdb.rawQuery(sql, par); + exists=cursor.moveToFirst(); + cursor.close(); + }catch(Exception e){ + e.printStackTrace(); + }finally{ + if(rdb != null) { rdb.close(); } + } + + ContentValues cv = new ContentValues(); + for(int i=0;i