· 9 years ago · Nov 15, 2016, 10:52 AM
102-27 18:38:45.956: I/Database(3559): sqlite returned: error code = 1, msg = no such table: inspections
2 02-27 18:38:45.967: E/Database(3559): Error inserting co_driver= driver=ewrre vehicle_id=ET 432 status=1 date_time=40 vehicle_type=truck
3 02-27 18:38:45.967: E/Database(3559): android.database.sqlite.SQLiteException: no such table: inspections: , while compiling: INSERT INTO inspections(co_driver, driver, vehicle_id, status, date_time, vehicle_type) VALUES(?, ?, ?, ?, ?, ?);
402-27 18:38:45.967: E/Database(3559): at android.view.View.performClick(View.java:2408)
5
6private static final String DATABASE_CREATE = "create table inspections ("
7 + "_id integer primary key autoincrement, "
8 + "vehicle_id string not null, "
9 + "vehicle_type string not null, "
10 + "datetime integer not null, "
11 + "driver string not null, "
12 + "codriver string , "
13 + "status integer not null "
14 + ");";
15
16public static void onCreate(SQLiteDatabase database) {
17 database.execSQL(DATABASE_CREATE);
18}
19
20public static void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
21 Log.w(InspectionsTable.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data");
22 database.execSQL("DROP TABLE IF EXISTS inspections");
23 onCreate(database);
24}
25
26public class SignalSetDBHelper extends SQLiteOpenHelper {
27private static final String DATABASE_NAME = "db";
28private static final int DATABASE_VERSION = 1;
29
30public SignalSetDBHelper(Context context) {
31 super(context, DATABASE_NAME, null, DATABASE_VERSION);
32}
33
34// Method is called during creation of the database
35@Override
36public void onCreate(SQLiteDatabase db) {
37 CurrentStateTable.onCreate(db);
38 HoursOfServiceTable.onCreate(db);
39 InspectionsTable.onCreate(db);
40 }
41
42// Method is called during an upgrade of the database,
43// e.g. if you increase the database version
44@Override
45public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
46 CurrentStateTable.onUpgrade(database, oldVersion, newVersion);
47 HoursOfServiceTable.onUpgrade(database, oldVersion, newVersion);
48}
49 }
50
51public class InspectionDBAdapter {
52private static final String KEY_ROWID ="_id";
53private static final String KEY_VEHICLE_ID="vehicle_id";
54private static final String KEY_VEHICLE_TYPE="vehicle_type";
55private static final String KEY_DATETIME="date_time";
56private static final String KEY_DRIVER="driver";
57private static final String KEY_CO_DRIVER="co_driver";
58private static final String KEY_STATUS="status";
59private static final String DB_TABLE="inspections";
60private Context context;
61private SQLiteDatabase db;
62private SignalSetDBHelper dbHelper;
63
64public InspectionDBAdapter(Context context) {
65 this.context = context;
66}
67
68public InspectionDBAdapter open() throws SQLException {
69 dbHelper = new SignalSetDBHelper(context);
70 db = dbHelper.getWritableDatabase();
71 return this;
72}
73
74public void close() {
75 dbHelper.close();
76}
77
78public void insertInspection( String vehicle_id, String vehicle_type,
79 int datetime, String driver, String codriver, int status)
80{
81
82 ContentValues newContact= createContentValue(vehicle_id, vehicle_type,
83 datetime, driver, codriver, status);
84
85 db.insert(DB_TABLE, KEY_STATUS, newContact);
86
87}
88
89private static ContentValues createContentValue(String vehicle_id, String vehicle_type,
90 int datetime, String driver, String codriver, int status)
91{
92 ContentValues newContact= new ContentValues();
93 newContact.put(KEY_VEHICLE_ID , vehicle_id);
94 newContact.put(KEY_VEHICLE_TYPE , vehicle_type);
95 newContact.put(KEY_DATETIME , datetime);
96 newContact.put(KEY_DRIVER , driver);
97 newContact.put(KEY_CO_DRIVER , codriver);
98 newContact.put(KEY_STATUS , status);
99
100 return newContact;
101
102public class SignalSetDBHelper extends SQLiteOpenHelper {
103
104 private static final String DATABASE_NAME = "db";
105 private static final int DATABASE_VERSION = 1;
106 private static final String INSPECTION_CREATE = "create table inspections ("
107 + "_id integer primary key autoincrement, "
108 + "vehicle_id string not null, "
109 + "vehicle_type string not null, "
110 + "datetime integer not null, "
111 + "driver string not null, "
112 + "codriver string , "
113 + "status integer not null "
114 + ");";
115
116 public SignalSetDBHelper(Context context) {
117 super(context, DATABASE_NAME, null, DATABASE_VERSION);
118 }
119 @Override
120 public void onCreate(SQLiteDatabase db) {
121
122 database.execSQL(INSPECTION_CREATE);
123 //do same for other two tables
124 }
125 public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
126
127 database.execSQL("DROP TABLE IF EXISTS inspections");
128 // do same for other two tables
129 onCreate(database);
130 }
131}