package com.example.yochi.shiftcal;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

class ShiftDao {

    private SQLiteDatabase mydb = null;

    public MySQLiteOpenHelper(Context c) {
    }

    public ArrayList<ShiftDao> getMonthlyShift(Timestamp from, Timestamp to){
        String format = "select date, shift from cal where date bitween %s and %s";
        String sql = String.format(format, top, bottom);
        Cursor c = openDb().rawQuery(sql);
        f(c.moveToFirst()){
          do{
            long date = c.getLong(c.getColumnIndex("date"));
            long shift = c.getLong(c.getColumnIndex("shift"));
          }while(c.moveToNext());
        }

    }

    private SQLiteDatabase openDb(){
        if(mydb == null){
            MySQLiteOpenHelper hlpr = new MySQLiteOpenHelper(mContext);
            mydb = hlpr.getWritableDatabase();
        }
        return mydb;
    }

    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_CAL);
        db.execSQL(CREATE_TABLE_SHIFT);

        // shiftテーブル初期データ投入
        ContentValues values = new ContentValues();
        values.put("shift", 1);
        values.put("title", "早番");
        values.put("color", "#ff0000ff");
        values.put("order", 1);
        db.insert("shift", null, values);
        values.put("shift", 2);
        values.put("title", "日勤");
        values.put("color", "#ff00ff00");
        values.put("order", 2);
        db.insert("shift", null, values);
        values.put("shift", 3);
        values.put("title", "遅番");
        values.put("color", "#ffff0000");
        values.put("order", 3);
        db.insert("shift", null, values);
    }

    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //db.execSQL(DROP_TABLE);
        //onCreate(db);
    }
}

@@ -100,16 +100,48 @@
 ontext;%0A
+import android.database.Cursor;%0A
 import a
@@ -233,109 +233,305 @@
 r;%0A%0A
-class ShiftDao %7B%0A%0A    private SQLiteDatabase mydb = null;%0A%0A    public MySQLiteOpenHelper(Context c) %7B
+import java.sql.Timestamp;%0Aimport java.util.ArrayList;%0A%0Aclass ShiftDao %7B%0A%0A    public Long date = null;%0A    public Integer shift = null;%0A%0A    private Context context = null;%0A    private SQLiteDatabase mydb = null;%0A%0A    public ShiftDao() %7B%0A    %7D%0A    public ShiftDao(Context c) %7B%0A        context = c;
 %0A   
@@ -624,21 +624,82 @@
     
-String format
+ArrayList%3CShiftDao%3E result = new ArrayList%3CShiftDao%3E();%0A        String sql
  = %22
@@ -749,17 +749,15 @@
 een 
-%25s
+?
  and 
-%25s
+?
 %22;%0A 
@@ -767,97 +767,114 @@
     
-String sql = String.format(format, top, bottom);%0A        Cursor c = openDb().rawQuery(sql
+Cursor c = openDb().rawQuery(sql, new String%5B%5D%7BLong.toString(from.getTime()), Long.toString(to.getTime())%7D
 );%0A 
@@ -880,16 +880,17 @@
         
+i
 f(c.move
@@ -927,21 +927,59 @@
         
-long 
+ShiftDao s = new ShiftDao();%0A            s.
 date = c
@@ -1030,13 +1030,10 @@
     
-long 
+s.
 shif
@@ -1033,36 +1033,35 @@
  s.shift = c.get
-Long
+Int
 (c.getColumnInde
@@ -1069,24 +1069,51 @@
 (%22shift%22));%0A
+            result.add(s);%0A
           %7Dw
@@ -1140,24 +1140,45 @@
 ;%0A        %7D%0A
+        return reslt;
 %0A    %7D%0A%0A    
@@ -1301,10 +1301,9 @@
 per(
-mC
+c
 onte
@@ -1396,910 +1396,6 @@
  %7D%0A%0A
-    public void onCreate(SQLiteDatabase db) %7B%0A        db.execSQL(CREATE_TABLE_CAL);%0A        db.execSQL(CREATE_TABLE_SHIFT);%0A%0A        // shift%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB%E5%88%9D%E6%9C%9F%E3%83%87%E3%83%BC%E3%82%BF%E6%8A%95%E5%85%A5%0A        ContentValues values = new ContentValues();%0A        values.put(%22shift%22, 1);%0A        values.put(%22title%22, %22%E6%97%A9%E7%95%AA%22);%0A        values.put(%22color%22, %22#ff0000ff%22);%0A        values.put(%22order%22, 1);%0A        db.insert(%22shift%22, null, values);%0A        values.put(%22shift%22, 2);%0A        values.put(%22title%22, %22%E6%97%A5%E5%8B%A4%22);%0A        values.put(%22color%22, %22#ff00ff00%22);%0A        values.put(%22order%22, 2);%0A        db.insert(%22shift%22, null, values);%0A        values.put(%22shift%22, 3);%0A        values.put(%22title%22, %22%E9%81%85%E7%95%AA%22);%0A        values.put(%22color%22, %22#ffff0000%22);%0A        values.put(%22order%22, 3);%0A        db.insert(%22shift%22, null, values);%0A    %7D%0A%0A    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) %7B%0A        //db.execSQL(DROP_TABLE);%0A        //onCreate(db);%0A    %7D%0A
 %7D%0A

edit shiftDao