<commit_before>package com.ehpefi.iforgotthat;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * Performs CRUD operations on lists in the 'I Forgot This' app.
 * 
 * @author <NAME>
 * @since 1.0
 */

public class ListHelper extends SQLiteOpenHelper {
	// Important constants for handling the database
	private static final int VERSION = 1;
	private static final String DATABASE_NAME = "ift.db";
	private static final String TABLE_NAME = "list";

	// Column names in the database
	public static final String COL_ID = "_id";
	public static final String COL_TITLE = "title";
	public static final String COL_TIMESTAMP = "created_timestamp";

	// Specify which class that logs messages
	private static final String TAG = "ListHelper";

	/**
	 * Constructs a new instance of the ListHelper class
	 * 
	 * @param context The context in which the new instance should be created, usually 'this'.
	 * @since 1.0
	 */
	public ListHelper(Context context) {
		// Call the super class' constructor
		super(context, DATABASE_NAME, null, VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		Log.d(TAG, "onCreate() was called. Creating the table '" + TABLE_NAME + "'...");

		// SQL to create the 'list' table
		String createListsSQL = String
				.format("CREATE TABLE %s (%s integer PRIMARY KEY AUTOINCREMENT NOT NULL, %s varchar(255) NOT NULL, %s DATETIME DEFAULT CURRENT_TIMESTAMP)",
						TABLE_NAME, COL_ID, COL_TITLE, COL_TIMESTAMP);

		// Create the table
		try {
			db.execSQL(createListsSQL);
			Log.i(TAG, "The table '" + TABLE_NAME + "' was successfully created");
		} catch (SQLException sqle) {
			Log.e(TAG, "Invalid SQL detected", sqle);
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.d(TAG, "onUpgrade() was called, but nothing to upgrade...");
	}

	/**
	 * Creates a new list in the database.
	 * 
	 * @param listTitle The title of the list
	 * @return A boolean indication whether a new list was created or not
	 * @since 1.0
	 */
	public boolean createNewList(String listTitle) {
		// Create a pointer to the database
		SQLiteDatabase db = getWritableDatabase();

		// Create the data to insert
		ContentValues values = new ContentValues();
		values.put(COL_TITLE, listTitle);
		
		// Try to save the list
		try {
			// Check for success
			if (db.insertOrThrow(TABLE_NAME, null, values) != -1) {
				// Success
				Log.i(TAG, "The list '" + listTitle + "' was successfully saved");

				// Close the database connection
				db.close();

				return true;
			}

			// Failure
			Log.e(TAG, "Could not save the list '" + listTitle + "'. That's all I know...");

			// Close the database connection
			db.close();

			return false;
		} catch (SQLException sqle) {
			// Something wrong with the SQL
			Log.e(TAG, "Error in inserting the list named " + listTitle, sqle);

			// Close the database connection
			db.close();

			return false;
		}<commit_msg>createNewList() now returns the id of the list on success<commit_after>package com.ehpefi.iforgotthat;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * Performs CRUD operations on lists in the 'I Forgot This' app.
 * 
 * @author <NAME>
 * @since 1.0
 */

public class ListHelper extends SQLiteOpenHelper {
	// Important constants for handling the database
	private static final int VERSION = 1;
	private static final String DATABASE_NAME = "ift.db";
	private static final String TABLE_NAME = "list";

	// Column names in the database
	public static final String COL_ID = "_id";
	public static final String COL_TITLE = "title";
	public static final String COL_TIMESTAMP = "created_timestamp";

	// Specify which class that logs messages
	private static final String TAG = "ListHelper";

	/**
	 * Constructs a new instance of the ListHelper class
	 * 
	 * @param context The context in which the new instance should be created, usually 'this'.
	 * @since 1.0
	 */
	public ListHelper(Context context) {
		// Call the super class' constructor
		super(context, DATABASE_NAME, null, VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		Log.d(TAG, "onCreate() was called. Creating the table '" + TABLE_NAME + "'...");

		// SQL to create the 'list' table
		String createListsSQL = String
				.format("CREATE TABLE %s (%s integer PRIMARY KEY AUTOINCREMENT NOT NULL, %s varchar(255) NOT NULL, %s DATETIME DEFAULT CURRENT_TIMESTAMP)",
						TABLE_NAME, COL_ID, COL_TITLE, COL_TIMESTAMP);

		// Create the table
		try {
			db.execSQL(createListsSQL);
			Log.i(TAG, "The table '" + TABLE_NAME + "' was successfully created");
		} catch (SQLException sqle) {
			Log.e(TAG, "Invalid SQL detected", sqle);
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.d(TAG, "onUpgrade() was called, but nothing to upgrade...");
	}

	/**
	 * Creates a new list in the database.
	 * 
	 * @param listTitle The title of the list
	 * @return The id of the inserted list on success, 0 on failure
	 * @since 1.0
	 */
	public int createNewList(String listTitle) {
		// Create a pointer to the database
		SQLiteDatabase db = getWritableDatabase();

		// Create the data to insert
		ContentValues values = new ContentValues();
		values.put(COL_TITLE, listTitle);
		
		// Try to save the list
		try {
			// Check for success
			long returnId = db.insertOrThrow(TABLE_NAME, null, values);

			// Check for success
			if (returnId != -1) {
				// Success
				Log.i(TAG, "The list '" + listTitle + "' was successfully saved");

				// Close the database connection
				db.close();

				return (int) returnId;
			}

			// Failure
			Log.e(TAG, "Could not save the list '" + listTitle + "'. That's all I know...");

			// Close the database connection
			db.close();

			return 0;
		} catch (SQLException sqle) {
			// Something wrong with the SQL
			Log.e(TAG, "Error in inserting the list named " + listTitle, sqle);

			// Close the database connection
			db.close();

			return 0;
		}
{'fraction_non_alphanumeric': 0.10639950295122709, 'fraction_numerical': 0.003883193538365952, 'mean_word_length': 3.5091036414565826, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3951068', 'n_tokens_mistral': 2164, 'n_tokens_neox': 1896, 'n_words': 692}