-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStore_Trips.java
115 lines (85 loc) · 3.44 KB
/
Store_Trips.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.example.documems;
//import java.util.ArrayList;
//import java.util.List;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Store_Trips{
public static ArrayList<Trip> storeTrips = new ArrayList<>();
public static int i ;
public static int lengt = 0;
public static void setI (int num){
i = num;
}
public static void setLengt (){
lengt++;
}
}
/* public class Store_Trips extends SQLiteOpenHelper {
List<Trip> documentedTrips;
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "MY_TRIPS";
public static final String TABLE_TRIPS = "trips";
public static final String COLUMN_TRIP_NUMBER = "trip_number";
public static final String COLUMN_TRIP_NAME = "trip_name";
public static final String COLUMN_TRIP_TRAVELERS = "trip_travelers";
public static final String COLUMN_TRIP_DATES = "trip_dates";
public static final int COLUMN_TRIP_DAYS = 0; //not sure if this will be written over?
public static final String COLUMN_TRIP_MEMO = "trip_memo";
//stores information about the table (Database)
public Store_Trips(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super (context, DATABASE_NAME, factory, DATABASE_VERSION);
//documentedTrips = new ArrayList<Trip>();
//Trip maui = new Trip("Maui", "Gavrilenkos","Spring Break",9,"Super fun");
//documentedTrips.add(0,maui);
}
@Override
public void onCreate (SQLiteDatabase db) {
String query = "Create Table " + TABLE_TRIPS + "(" +
COLUMN_TRIP_NUMBER + "INTEGER PRIMARY KEY AUTOINCREMENT " +
COLUMN_TRIP_NAME + "TEXT" +
COLUMN_TRIP_TRAVELERS + "TEXT" +
COLUMN_TRIP_DATES + "TEXT" +
COLUMN_TRIP_DAYS + "INTEGER" + //not sure if this is right
COLUMN_TRIP_MEMO + "TEXT" +
");";
db.execSQL(query);
}
@Override
public void onUpgrade (SQLiteDatabase db, int oldVersion, int newVersion){
db.execSQL("DROP TABLE IF EXISTS " + TABLE_TRIPS);
onCreate(db);
}
//add row to the database
public void addTripToDatabase(Trip trip) {
ContentValues values = new ContentValues();
values.put(COLUMN_TRIP_NAME, trip.getName()) ;
SQLiteDatabase db = getWritableDatabase();
db.insert(TABLE_TRIPS,null,values);
db.close();
}
//delete a product from the datablase
//print out the database as a string
public String databaseToString() {
String dbString = "";
SQLiteDatabase db = getWritableDatabase();
String query = "SELECT * FROM " + TABLE_TRIPS + " WHERE 1"; //selects every column and row
//cursor points to a location in the results
Cursor c = db.rawQuery(query,null);
//move it to the first row
c.moveToFirst();
while (!c.isAfterLast()){
if(c.getString(c.getColumnIndex("MY_TRIPS")) != null) {
dbString += c.getString(c.getColumnIndex("MY_TRIPS"));
dbString += "\n";
}
}
db.close();
return dbString;
}
*/