Clover Coverage Report - AnCal Coverage Report
Coverage timestamp: gio dic 18 2014 12:18:42 EST
../../../../../img/srcFileCovDistChart9.png 40% of files have more coverage
74   192   33   5,29
30   163   0,45   14
14     2,36  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  DataTable       Line # 8 74 33 82,2% 0.8220339
 
No Tests
 
1   
2    package pl.magot.vetch.ancal.database;
3   
4   
5    import android.database.Cursor;
6   
7   
 
8    public class DataTable
9    {
10    //fields
11    private DataRow dataRow = null;
12   
13    //methods
 
14  140 toggle public DataTable(DataRow dataRow)
15    {
16  140 this.dataRow = dataRow;
17    }
18   
 
19  193 toggle public Database GetUserDb()
20    {
21  193 return dataRow.GetUserDb();
22    }
23   
 
24  212 toggle public String GetTableName()
25    {
26  212 return dataRow.GetTableName();
27    }
28   
 
29  18 toggle public DataRow GetDataRow()
30    {
31  18 return dataRow;
32    }
33   
 
34  112 toggle public boolean CreateTable()
35    {
36  112 if (GetUserDb().TableExists(GetTableName()))
37    {
38  108 return true;
39    } else {
40  4 return GetUserDb().ExecSQL(GetSqlTableDefinition(GetTableName(), dataRow.GetTableDef()));
41    }
42    }
43   
 
44  4 toggle public String GetSqlTableDefinition(String sTableName, DataField[] vecTableDef)
45    {
46  4 String def = "CREATE TABLE " + sTableName + " (";
47  27 for (int i = 0; i < vecTableDef.length; i++)
48    {
49  23 def += vecTableDef[i].GetColumnDefinition();
50  23 if (i < (vecTableDef.length - 1))
51  19 def += ", ";
52    }
53  4 def += ")";
54  4 return def;
55    }
56   
 
57  13 toggle public long InsertValues()
58    {
59  13 long lRowId = GetUserDb().GetSQLiteDb().insert(GetTableName(), null, dataRow.GetContentValues());
60  13 return lRowId;
61    }
62   
 
63  5 toggle public long UpdateValues(long lRowId)
64    {
65  5 String sWhere = String.format("_ID = %d", lRowId);
66  5 long lRowsUpdated = GetUserDb().GetSQLiteDb().update(GetTableName(), dataRow.GetContentValues(), sWhere, null);
67  5 return lRowsUpdated;
68    }
69   
 
70  3 toggle public long DeleteDataRow(long lRowId)
71    {
72  3 String sWhere = String.format("_ID = %d", lRowId);
73  3 long lRowsUpdated = GetUserDb().GetSQLiteDb().delete(GetTableName(), sWhere, null);
74  3 return lRowsUpdated;
75    }
76   
 
77  8 toggle public Cursor LocateDataRow(long lRowId)
78    {
79  8 final String s = "select * from %s where _ID = %d";
80  8 String sql = String.format(s, GetTableName(), lRowId);
81  8 Cursor cr = GetUserDb().GetSQLiteDb().rawQuery(sql, null);
82    //if cursor valid, set first data row as current
83  8 if ((cr != null) && (cr.getCount() > 0))
84  8 cr.moveToFirst();
85  8 return cr;
86    }
87   
 
88  24 toggle public Cursor LocateAlarmDataRow(int iType, long lRefID)
89    {
90  24 final String s = "select * from %s where Type = %d and RefID = %d";
91  24 String sql = String.format(s, GetTableName(), iType, lRefID);
92  24 Cursor cr = GetUserDb().GetSQLiteDb().rawQuery(sql, null);
93    //if cursor valid, set first data row as current
94  24 if ((cr != null) && (cr.getCount() > 0))
95  7 cr.moveToFirst();
96  24 return cr;
97    }
98   
 
99  18 toggle public Database.Result UpdateData(boolean bInsertMode, long lEditRowId)
100    {
101  18 Database.Result result = Database.Result.errUnknown;
102  18 if (GetUserDb().IsOpened())
103    {
104  18 try
105    {
106  18 dataRow.SetValuesForDataRow();
107    } catch (Exception e) {
108  0 return Database.Result.errCantSetValuesForDataRow;
109    }
110    //select update mode
111  18 if (bInsertMode)
112    {
113    //insert new data row
114  13 long lRowId = InsertValues();
115  13 if (lRowId > 0)
116    {
117  13 result = Database.Result.Success;
118    } else {
119  0 result = Database.Result.errCantInsertNewData;
120    }
121    } else {
122    //update existing data row
123  5 long lRowsUpdated = UpdateValues(lEditRowId);
124  5 if (lRowsUpdated == 1)
125    {
126  5 result = Database.Result.Success;
127    } else {
128  0 result = Database.Result.errCantUpdateData;
129    }
130    }
131    } else {
132  0 result = Database.Result.errNoDbAccess;
133    }
134  18 return result;
135    }
136   
 
137  3 toggle public Database.Result DeleteData(long iRowId)
138    {
139  3 Database.Result result = Database.Result.errUnknown;
140  3 if (GetUserDb().IsOpened())
141    {
142  3 if (GetUserDb().TableExists(GetTableName()))
143    {
144  3 long lRowsDeleted = DeleteDataRow(iRowId);
145  3 if (lRowsDeleted == 1)
146    {
147  3 result = Database.Result.Success;
148    } else {
149  0 result = Database.Result.errCantDeleteData;
150    }
151    } else {
152  0 result = Database.Result.errTableNotExists;
153    }
154    } else {
155  0 result = Database.Result.errNoDbAccess;
156    }
157  3 return result;
158    }
159   
 
160  8 toggle public Database.Result GetRowDataForEdit(long lRowId)
161    {
162  8 Database.Result result = Database.Result.errUnknown;
163    //get requested data row
164  8 Cursor cr = LocateDataRow(lRowId);
165  8 if (cr == null)
166    {
167  0 result = Database.Result.errCantGetData;
168    } else {
169  8 if (cr.getCount() > 0)
170    {
171  8 if (dataRow.GetValuesFromCursor(cr))
172    {
173  8 try
174    {
175  8 dataRow.GetValuesFromDataRow();
176    } catch (Exception e) {
177  0 return Database.Result.errCantGetValuesFromDataRow;
178    }
179  8 result = Database.Result.Success;
180    } else {
181  0 result = Database.Result.errCantGetDataFromTable;
182    }
183  8 cr.close();
184    } else {
185  0 result = Database.Result.errCantFindData;
186    }
187    }
188  8 return result;
189    }
190   
191    }
192