Clover Coverage Report - AnCal Coverage Report
Coverage timestamp: gio dic 18 2014 12:18:42 EST
../../../../../img/srcFileCovDistChart5.png 92% of files have more coverage
74   194   35   5,29
40   165   0,47   7
14     2,5  
2    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  Database       Line # 12 74 35 48,4% 0.484375
  Database.Result       Line # 15 0 0 - -1.0
 
No Tests
 
1   
2    package pl.magot.vetch.ancal.database;
3   
4   
5    import java.util.Vector;
6    import pl.magot.vetch.ancal.R;
7    import android.content.*;
8    import android.database.sqlite.*;
9    import android.database.*;
10   
11   
 
12    public class Database
13    {
14    //types
 
15    public enum Result
16    {
17    Success,
18    errUnknown,
19    errCantInsertNewData,
20    errCantUpdateData,
21    errCantCreateTable,
22    errNoDbAccess,
23    errCantGetDataFromTable,
24    errCantFindData,
25    errCantGetData,
26    errCantDeleteData,
27    errTableNotExists,
28    errCantSetValuesForDataRow,
29    errCantGetValuesFromDataRow,
30    };
31   
32    //fields
33    public static final String sTableNameAppointments = "Appointments";
34    public static final String sTableNameTasks = "Tasks";
35    public static final String sTableNameNotes = "Notes";
36    public static final String sTableNameAlarms = "Alarms";
37   
38    //fields
39    private final String dbName = "AnCalDatabase.db";
40    private Context ctx = null;
41    private SQLiteDatabase db = null;
42    private Result resultDbTablesCreated = Result.errUnknown;
43   
44    //methods
 
45  28 toggle public Database(Context context)
46    {
47  28 ctx = context;
48  28 Open();
49  28 CreateTables();
50    }
51   
 
52  0 toggle public final String Name()
53    {
54  0 return dbName;
55    }
56   
 
57  0 toggle public static int GetErrDesc(Result result)
58    {
59  0 int msgId = R.string.errUnknown;
60  0 if (result == Result.errCantInsertNewData)
61  0 msgId = R.string.errCantInsertNewData;
62  0 if (result == Result.errCantUpdateData)
63  0 msgId = R.string.errCantUpdateData;
64  0 if (result == Result.errCantCreateTable)
65  0 msgId = R.string.errCantCreateTable;
66  0 if (result == Result.errNoDbAccess)
67  0 msgId = R.string.errNoDbAccess;
68  0 if (result == Result.errCantGetDataFromTable)
69  0 msgId = R.string.errCantGetDataFromTable;
70  0 if (result == Result.errCantFindData)
71  0 msgId = R.string.errCantFindData;
72  0 if (result == Result.errCantGetData)
73  0 msgId = R.string.errCantGetData;
74  0 if (result == Result.errCantDeleteData)
75  0 msgId = R.string.errCantDeleteData;
76  0 if (result == Result.errTableNotExists)
77  0 msgId = R.string.errTableNotExists;
78  0 if (result == Result.errCantSetValuesForDataRow)
79  0 msgId = R.string.errCantSetValuesForDataRow;
80  0 if (result == Result.errCantGetValuesFromDataRow)
81  0 msgId = R.string.errCantGetValuesFromDataRow;
82  0 return msgId;
83    }
84   
 
85  28 toggle public boolean Open()
86    {
87  28 boolean bSuccess = false;
88    //open / create database
89  28 db = ctx.openOrCreateDatabase(dbName, Context.MODE_PRIVATE, null);
90    //test result
91  28 if (IsOpened())
92    {
93  28 bSuccess = true;
94    } else {
95  0 db = null;
96    }
97  28 return bSuccess;
98    }
99   
 
100  26 toggle public void Close()
101    {
102  26 if (IsOpened())
103  26 db.close();
104    }
105   
 
106  342 toggle public boolean IsOpened()
107    {
108  342 if (db != null)
109  342 return true;
110  0 return false;
111    }
112   
 
113  141 toggle public SQLiteDatabase GetSQLiteDb()
114    {
115  141 return db;
116    }
117   
 
118  0 toggle public boolean Delete()
119    {
120  0 Close();
121  0 return ctx.deleteDatabase(dbName);
122    }
123   
 
124  4 toggle public boolean ExecSQL(String sql)
125    {
126  4 boolean bSuccess = false;
127  4 try
128    {
129  4 if (IsOpened())
130  4 db.execSQL(sql);
131  4 bSuccess = true;
132    } catch (SQLException e) {
133    }
134  4 return bSuccess;
135    }
136   
 
137  115 toggle public boolean TableExists(String sTableName)
138    {
139  115 boolean bResult = false;
140  115 if (IsOpened())
141    {
142  115 String sql = "select name from sqlite_master where type = 'table' and name = '%s'";
143  115 sql = String.format(sql, sTableName);
144  115 Cursor cr = db.rawQuery(sql, null);
145  115 if (cr.getCount() > 0)
146  111 bResult = true;
147  115 cr.close();
148    }
149  115 return bResult;
150    }
151   
 
152  28 toggle private void CreateTables()
153    {
154  28 resultDbTablesCreated = Database.Result.errUnknown;
155  28 if (IsOpened())
156    {
157  28 Vector<DataRow> vecDataRows = new Vector<DataRow>();
158  28 vecDataRows.add(new DataRowAppointment(this));
159  28 vecDataRows.add(new DataRowTask(this));
160  28 vecDataRows.add(new DataRowNote(this));
161  28 vecDataRows.add(new DataRowAlarm(this));
162   
163  140 for (int i = 0; i < vecDataRows.size(); i++)
164    {
165  112 DataTable dataTable = new DataTable(vecDataRows.get(i));
166  112 if (dataTable.CreateTable())
167    {
168  112 resultDbTablesCreated = Database.Result.Success;
169    } else {
170  0 resultDbTablesCreated = Database.Result.errCantCreateTable;
171  0 break;
172    }
173    }
174    } else {
175  0 resultDbTablesCreated = Database.Result.errNoDbAccess;
176    }
177    }
178   
 
179  120 toggle public boolean TablesCreated()
180    {
181  120 return resultDbTablesCreated == Result.Success;
182    }
183   
 
184  120 toggle public synchronized boolean DatabaseReady()
185    {
186  120 return (IsOpened() && TablesCreated());
187    }
188   
 
189  0 toggle public Result TablesCreationResult()
190    {
191  0 return resultDbTablesCreated;
192    }
193   
194    }