@@ -269,12 +269,13 @@ public long getAccountID(String uid){
269269 new String [] {DatabaseHelper .KEY_ROW_ID , DatabaseHelper .KEY_UID },
270270 DatabaseHelper .KEY_UID + " = '" + uid + "'" , null , null , null , null );
271271 long result = -1 ;
272- if (cursor != null && cursor .moveToFirst ()){
273- Log .v (TAG , "Returning account id" );
274- result = cursor .getLong (DatabaseAdapter .COLUMN_ROW_ID );
275-
276- cursor .close ();
277- }
272+ if (cursor != null ) {
273+ if (cursor .moveToFirst ()) {
274+ Log .v (TAG , "Returning account id" );
275+ result = cursor .getLong (DatabaseAdapter .COLUMN_ROW_ID );
276+ }
277+ cursor .close ();
278+ }
278279 return result ;
279280 }
280281
@@ -291,12 +292,13 @@ public String getParentAccountUID(String uid){
291292 new String []{uid },
292293 null , null , null , null );
293294 String result = null ;
294- if (cursor != null && cursor .moveToFirst ()){
295- Log .d (TAG , "Account already exists. Returning existing id" );
296- result = cursor .getString (cursor .getColumnIndexOrThrow (DatabaseHelper .KEY_PARENT_ACCOUNT_UID ));
297-
298- cursor .close ();
299- }
295+ if (cursor != null ) {
296+ if (cursor .moveToFirst ()) {
297+ Log .d (TAG , "Account already exists. Returning existing id" );
298+ result = cursor .getString (cursor .getColumnIndexOrThrow (DatabaseHelper .KEY_PARENT_ACCOUNT_UID ));
299+ }
300+ cursor .close ();
301+ }
300302 return result ;
301303 }
302304
@@ -320,10 +322,12 @@ public Account getAccount(long rowId){
320322 Account account = null ;
321323 Log .v (TAG , "Fetching account with id " + rowId );
322324 Cursor c = fetchRecord (DatabaseHelper .ACCOUNTS_TABLE_NAME , rowId );
323- if (c != null && c .moveToFirst ()){
324- account = buildAccountInstance (c );
325- c .close ();
326- }
325+ if (c != null ) {
326+ if (c .moveToFirst ()) {
327+ account = buildAccountInstance (c );
328+ }
329+ c .close ();
330+ }
327331 return account ;
328332 }
329333
@@ -348,10 +352,12 @@ public String getAccountUID(long id){
348352 new String []{DatabaseHelper .KEY_ROW_ID , DatabaseHelper .KEY_UID },
349353 DatabaseHelper .KEY_ROW_ID + "=" + id ,
350354 null , null , null , null );
351- if (c != null && c .moveToFirst ()){
352- uid = c .getString (c .getColumnIndexOrThrow (DatabaseHelper .KEY_UID ));
353- c .close ();
354- }
355+ if (c != null ) {
356+ if (c .moveToFirst ()) {
357+ uid = c .getString (c .getColumnIndexOrThrow (DatabaseHelper .KEY_UID ));
358+ }
359+ c .close ();
360+ }
355361 return uid ;
356362 }
357363
@@ -366,8 +372,10 @@ public String getAccountColorCode(long accountId){
366372 new String []{DatabaseHelper .KEY_ROW_ID , DatabaseHelper .KEY_COLOR_CODE },
367373 DatabaseHelper .KEY_ROW_ID + "=" + accountId ,
368374 null , null , null , null );
369- if (c != null && c .moveToFirst ()){
370- colorCode = c .getString (c .getColumnIndexOrThrow (DatabaseHelper .KEY_COLOR_CODE ));
375+ if (c != null ) {
376+ if (c .moveToFirst ()) {
377+ colorCode = c .getString (c .getColumnIndexOrThrow (DatabaseHelper .KEY_COLOR_CODE ));
378+ }
371379 c .close ();
372380 }
373381 return colorCode ;
@@ -399,10 +407,12 @@ public AccountType getAccountType(long accountId){
399407 public String getName (long accountID ) {
400408 String name = null ;
401409 Cursor c = fetchRecord (DatabaseHelper .ACCOUNTS_TABLE_NAME , accountID );
402- if (c != null && c .moveToFirst ()){
403- name = c .getString (DatabaseAdapter .COLUMN_NAME );
404- c .close ();
405- }
410+ if (c != null ) {
411+ if (c .moveToFirst ()) {
412+ name = c .getString (DatabaseAdapter .COLUMN_NAME );
413+ }
414+ c .close ();
415+ }
406416 return name ;
407417 }
408418
0 commit comments