<commit_before>package com.example.penguin.timetagger.Database;

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

import com.example.penguin.timetagger.Alarm;
import com.example.penguin.timetagger.Attachment;
import com.example.penguin.timetagger.Note;
import com.example.penguin.timetagger.TimeTable;
import com.example.penguin.timetagger.TimeTag;
//import com.example.penguin.timetagger.TimeTable;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

/**
 * Created by penguin on 17. 5. 15.
 */

public class DatabaseHelper extends SQLiteOpenHelper {
	private static final String DATABASE_NAME = "TimeTaggerDB.db";
	private static final int DATABASE_VERSION = 1;
	private static DatabaseHelper instance = null;
	private static boolean dummyNoteLoaded = false;
	private static final String  TIMETABLES_NAME = "times";
	private static final String  TAGSTABLE_NAME = "tags";
	private static final String  NOTESTABLE_NAME = "notes";
	private static final String  ATTACHESTABLE_NAME = "attaches";
	private static final String ALARMTABLE_NAME = "alarms";

	private DatabaseHelper(Context context){
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	public static synchronized DatabaseHelper getInstance(Context context){

		if(instance == null)
			instance = new DatabaseHelper(context);
		return instance;
	}

	/* NOTES */
	public static synchronized Note insertNote(Note note){
		String query =  " INSERT INTO "     + NOTESTABLE_NAME   +
						" values(NULL,"     + note.getTagID()   + ",'"
										    + note.getTitle()   + "','"
											+ note.getBody()	+ "',"
											+ note.getType()    + ");";

		SQLiteDatabase db = instance.getWritableDatabase();
		db.execSQL(query);

		Cursor cursor = db.rawQuery("SELECT MAX(NOTE_ID) from notes", null);
		cursor.moveToFirst();
		note.setNoteID(cursor.getInt(0));
		cursor.close();

		// Attachment
		insertAttaches(note.getAttaches());
    // Alarm
		insertAlarms(note.getAlarms());
		return note;
	}
	public static synchronized void updateNote(Note note){
		// noteID == 1 일땐 새로운 노트이므로, 업데이트 할 수 없음<commit_msg>신규 노트 추가 시, 사진과 동봉하여 저장 시 사진이 나오지 않던 문제 수정.<commit_after>package com.example.penguin.timetagger.Database;

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

import com.example.penguin.timetagger.Alarm;
import com.example.penguin.timetagger.Attachment;
import com.example.penguin.timetagger.Note;
import com.example.penguin.timetagger.TimeTable;
import com.example.penguin.timetagger.TimeTag;
//import com.example.penguin.timetagger.TimeTable;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

/**
 * Created by penguin on 17. 5. 15.
 */

public class DatabaseHelper extends SQLiteOpenHelper {
	private static final String DATABASE_NAME = "TimeTaggerDB.db";
	private static final int DATABASE_VERSION = 1;
	private static DatabaseHelper instance = null;
	private static boolean dummyNoteLoaded = false;
	private static final String  TIMETABLES_NAME = "times";
	private static final String  TAGSTABLE_NAME = "tags";
	private static final String  NOTESTABLE_NAME = "notes";
	private static final String  ATTACHESTABLE_NAME = "attaches";
	private static final String ALARMTABLE_NAME = "alarms";

	private DatabaseHelper(Context context){
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	public static synchronized DatabaseHelper getInstance(Context context){

		if(instance == null)
			instance = new DatabaseHelper(context);
		return instance;
	}

	/* NOTES */
	public static synchronized Note insertNote(Note note){
		String query =  " INSERT INTO "     + NOTESTABLE_NAME   +
						" values(NULL,"     + note.getTagID()   + ",'"
										    + note.getTitle()   + "','"
											+ note.getBody()	+ "',"
											+ note.getType()    + ");";

		SQLiteDatabase db = instance.getWritableDatabase();
		db.execSQL(query);

		Cursor cursor = db.rawQuery("SELECT MAX(NOTE_ID) from notes", null);
		cursor.moveToFirst();
		note.setNoteID(cursor.getInt(0));
		note.getAttaches().get(0).setNoteID(cursor.getInt(0));
		cursor.close();

		// Attachment
		insertAttaches(note.getAttaches());
    // Alarm
		insertAlarms(note.getAlarms());
		return note;
	}
	public static synchronized void updateNote(Note note){
		// noteID == 1 일땐 새로운 노트이므로, 업데이트 할 수 없음
{'fraction_non_alphanumeric': 0.11012470936377088, 'fraction_numerical': 0.003804692454026633, 'mean_word_length': 4.395667046750285, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6205355', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1579, 'n_words': 356}