{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a07482f-daf4-43e4-8714-df2862a5dd5f",
   "metadata": {},
   "outputs": [],
   "source": [
    "from DATA225utils import make_connection, dataframe_query\n",
    "import pandas as pd\n",
    "from pandas import DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a45081b-11ec-464f-90d3-9636cb57f868",
   "metadata": {},
   "outputs": [],
   "source": [
    "conn = make_connection(config_file = 'titanic.ini')\n",
    "cursor = conn.cursor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bd86bfbc-f1fa-48d2-9a2a-e702926d12f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "from mysql.connector import Error\n",
    "\n",
    "try:\n",
    "    cursor.execute(\"DROP INDEX age_index ON passengers\")\n",
    "except Error as e:\n",
    "    print(f'DROP INDEX failed: {e}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7536e416-f52b-4f67-9ff0-0ef9cf17b24b",
   "metadata": {},
   "outputs": [],
   "source": [
    "cursor.execute(\"CREATE INDEX age_index ON passengers(name)\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "33ff0f0d-649b-465c-833b-ee257b98ee57",
   "metadata": {},
   "outputs": [],
   "source": [
    "_, df = dataframe_query(conn, \"\"\"\n",
    "    SELECT *\n",
    "    FROM passengers\n",
    "    WHERE age = 45.5\n",
    "    OR    age = 55.5\n",
    "    OR    age = 60.5\n",
    "    OR    age = 75.5\n",
    "    OR    age = 80\n",
    "    \"\"\"\n",
    "                       )\n",
    "\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "84d469cc-7b05-4955-be60-aecd7191dc6e",
   "metadata": {},
   "outputs": [],
   "source": [
    "cursor.close()\n",
    "conn.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7b00e010-d695-427e-a1b6-a6770cd7caac",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "46f7e961-cc2b-43a9-a8c1-af1fb5866eff",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
