{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e19ea748-ac50-4162-873c-77db9e8bb552",
   "metadata": {},
   "outputs": [],
   "source": [
    "from data201 import db_connection, df_query"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f43bec04-62b3-4633-bb6f-fb5e6085286a",
   "metadata": {},
   "outputs": [],
   "source": [
    "conn = db_connection(config_file = 'commit_test.ini')\n",
    "cursor = conn.cursor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5a83f9fc-2e3a-42c7-a08b-957fccc90011",
   "metadata": {},
   "outputs": [],
   "source": [
    "cursor.execute('DROP TABLE IF EXISTS data')\n",
    "\n",
    "cursor.execute(\n",
    "    \"\"\"\n",
    "    CREATE TABLE data\n",
    "    (\n",
    "        value INT NOT NULL,\n",
    "        PRIMARY KEY (value)\n",
    "    )\n",
    "    \"\"\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "19420e5a-27cd-451e-9747-d099b8d71e40",
   "metadata": {},
   "outputs": [],
   "source": [
    "for value in range(10, 60, 10):\n",
    "    cursor.execute(f'INSERT INTO data VALUES ({value})')\n",
    "\n",
    "conn.commit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8888931a-a879-4755-a724-caf55f9fe760",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_query(conn, 'SELECT * FROM data')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5820fc9a-4ed2-4943-9b20-eb8557129ee7",
   "metadata": {},
   "outputs": [],
   "source": [
    "cursor.execute('INSERT INTO data VALUES (15)')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "692e37e3-c233-4b70-ac13-5e7cc2f50ab2",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_query(conn, 'SELECT * FROM data')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9a084ca9-a9c8-45fd-b640-e9ddf01c3055",
   "metadata": {},
   "outputs": [],
   "source": [
    "cursor.execute('COMMIT')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0bf02672-536c-4ad8-a403-a6a221b7a57e",
   "metadata": {},
   "outputs": [],
   "source": [
    "cursor.execute('INSERT INTO data VALUES (25), (35)')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "041af766-5704-4e45-b88b-c4c62510f939",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_query(conn, 'SELECT * FROM data')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "19169635-f588-4b38-b75e-a4e05f494729",
   "metadata": {},
   "outputs": [],
   "source": [
    "conn.commit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0b065136-cde2-4ab7-a119-8aa405d677c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "cursor.execute('INSERT INTO data VALUES (45)')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0bdb2d5f-8c70-494a-b660-a9966c5fd70d",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_query(conn, 'SELECT * FROM data')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b51831a-6f67-4291-9f0b-d051c9852754",
   "metadata": {},
   "outputs": [],
   "source": [
    "cursor.close()\n",
    "conn.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "21ccb057-ebfc-4580-bff3-28eff7f3d6c6",
   "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.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
