Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/apursley2012/PunctuOwlity/llms.txt

Use this file to discover all available pages before exploring further.

DatabaseHelper extends SQLiteOpenHelper and is the single point of access for all persistent data in the PunctuOwlity Android app. It manages punctuowlity.db (version 1) and exposes separate method groups for user account management and event CRUD operations. Every Activity that needs database access instantiates DatabaseHelper directly by passing the Android Context to its constructor.
DatabaseHelper db = new DatabaseHelper(this);

Database Schema

The database contains two tables created in onCreate. Both are created with INTEGER PRIMARY KEY AUTOINCREMENT surrogate keys.
CREATE TABLE users (
    id       INTEGER PRIMARY KEY AUTOINCREMENT,
    username TEXT UNIQUE,
    password TEXT
);

CREATE TABLE events (
    id    INTEGER PRIMARY KEY AUTOINCREMENT,
    title TEXT,
    date  TEXT,
    time  TEXT
);
The username column in the users table carries a UNIQUE constraint. Attempting to insert a duplicate username returns -1 from db.insert(), which causes insertUser to return false.

User Methods

These methods handle account creation and credential verification for LoginActivity and SignupActivity.

insertUser

public boolean insertUser(String username, String password)
Inserts a new row into the users table using ContentValues. Returns false if the insert fails — most commonly because username already exists (enforced by the UNIQUE constraint).
username
String
required
The account username. Must be unique across all rows in the users table.
password
String
required
The account password stored as plain text.
Returns: true if the row was inserted successfully (db.insert() returned a row ID ≥ 0); false if the insert failed.

checkUser

public boolean checkUser(String username, String password)
Queries the users table for a row matching both username and password. Used by LoginActivity to validate credentials before navigating to MainActivity.
username
String
required
The username to look up.
password
String
required
The password to verify against the stored value.
Returns: true if at least one matching row exists (cursor.getCount() > 0); false otherwise. The cursor is always closed before returning.

Event Methods

These methods manage the full lifecycle of events displayed in MainActivity and edited via AddEventActivity.

insertEvent

public boolean insertEvent(String title, String date, String time)
Inserts a new row into the events table. The id is assigned automatically by SQLite’s AUTOINCREMENT.
title
String
required
The event name, e.g. "Dentist".
date
String
required
The event date in MM/dd/yyyy format, e.g. "04/14/2025".
time
String
required
The display time string, e.g. "01:30PM" or "ALL DAY".
Returns: true if the row was inserted successfully; false otherwise.

updateEvent

public boolean updateEvent(int id, String title, String date, String time)
Updates the title, date, and time columns of the events row identified by id. Uses db.update() with COL_EVENT_ID + "=?" as the WHERE clause.
id
int
required
The SQLite row ID of the event to update.
title
String
required
The new event title.
date
String
required
The new date in MM/dd/yyyy format.
time
String
required
The new display time string.
Returns: true if at least one row was affected (db.update() returned > 0); false if no row matched the given id.

deleteEvent

public boolean deleteEvent(int id)
Deletes the events row with the matching id. Called from MainActivity when the user taps the delete button on an event card.
id
int
required
The SQLite row ID of the event to delete.
Returns: true if at least one row was deleted; false if no row matched.

getAllEvents

public ArrayList<Event> getAllEvents()
Executes SELECT * FROM events and maps every row to an Event(id, title, date, time) instance. Called by MainActivity.loadEvents() on onCreate and onResume. Returns: An ArrayList<Event> containing all stored events in their natural insertion order. Returns an empty list (not null) if the table is empty.
ArrayList<Event> events = db.getAllEvents();
for (Event event : events) {
    textDay.setText(event.getDayOfWeek());   // e.g. "SAT"
    textDate.setText(event.getDateDay());    // e.g. "05"
    eventTitle.setText(event.getTitle());   // e.g. "Project Two Due"
    textTime.setText(event.getTime());      // e.g. "ALL DAY"
}

getEventById

public Event getEventById(int id)
Queries the events table for a single row by primary key. Used by AddEventActivity when launched with an "event_id" extra to pre-populate the edit form.
id
int
required
The SQLite row ID of the event to retrieve.
Returns: An Event(id, title, date, time) instance if a matching row is found; null if no row exists for the given id. Callers must null-check the return value.
Event event = db.getEventById(eventId);
if (event != null) {
    editEventTitle.setText(event.getTitle());
    textEventDate.setText(event.getDate());
    textEventTime.setText(event.getTime());
}

Upgrade Behavior

When the database version is incremented, onUpgrade drops both tables and recreates them by calling onCreate:
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_EVENTS);
    onCreate(db);
}
onUpgrade unconditionally drops both the users and events tables, permanently deleting all stored data. This approach is suitable for early development only. Any production release that increments DATABASE_VERSION must implement a proper migration strategy (e.g. ALTER TABLE statements) to preserve existing user accounts and events.

Build docs developers (and LLMs) love