{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "8a701441-7746-4ed0-8b53-88565eb0c1cc", "metadata": {}, "outputs": [], "source": [ "from DATA225utils import make_connection, dataframe_query\n", "from pandas import DataFrame" ] }, { "cell_type": "code", "execution_count": 13, "id": "f1385465-e65d-4c7d-89ea-10529b3934ab", "metadata": {}, "outputs": [], "source": [ "conn = make_connection(config_file = 'school.ini')\n", "cursor = conn.cursor()" ] }, { "cell_type": "markdown", "id": "ba820f06-f09c-4845-8f83-991dda5fcfb4", "metadata": {}, "source": [ "#### A Python function that displays in a dataframe the results from a call to a stored procedure." ] }, { "cell_type": "code", "execution_count": 3, "id": "163737b4-5663-40e4-884d-97183a9d1978", "metadata": {}, "outputs": [], "source": [ "def display_results(cursor):\n", " \"\"\"\n", " If there are results in the cursor from a call to a\n", " stored procedure, display the results in a dataframe. \n", " \"\"\"\n", " columns = result.description\n", " \n", " if columns == None:\n", " return \n", " \n", " else:\n", " column_names = [column_info[0] \n", " for column_info in columns]\n", "\n", " rows = cursor.fetchall()\n", " \n", " if len(rows) > 0:\n", " df = DataFrame(rows)\n", " df.columns = column_names\n", " \n", " display(df)\n", " \n", " else:\n", " return" ] }, { "cell_type": "markdown", "id": "146af91b-35e2-463f-bb0f-944bca316948", "metadata": { "tags": [] }, "source": [ "# Call stored procedure `all_students()`" ] }, { "cell_type": "markdown", "id": "cd108609-4aff-457e-b471-e5e855206f43", "metadata": {}, "source": [ "#### There are two ways to call a stored procedure from Python: use SQL's `CALL` command, or use the cursor's `callproc()` method. Each requires a different way to retrieve the tabular results." ] }, { "cell_type": "markdown", "id": "2e0cfa26-42d3-43de-aee4-0f013acfa27f", "metadata": {}, "source": [ "### Use SQL's `CALL` command" ] }, { "cell_type": "code", "execution_count": 4, "id": "5d18a017-c52e-4e79-ae54-319ce3f93adb", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CALL all_students\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idlastfirstcontact_id
0S1001DoeJohnC03
1S1005NovakTimC04
2S1009KleinLeslieC05
3S1014JaneMaryC01
4S1021SmithKimC02
\n", "
" ], "text/plain": [ " id last first contact_id\n", "0 S1001 Doe John C03\n", "1 S1005 Novak Tim C04\n", "2 S1009 Klein Leslie C05\n", "3 S1014 Jane Mary C01\n", "4 S1021 Smith Kim C02" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "sql = 'CALL all_students'\n", "print(sql)\n", "print()\n", "\n", "generator = cursor.execute(sql, multi=True)\n", "\n", "for result in generator:\n", " display_results(result)" ] }, { "cell_type": "markdown", "id": "82102ab9-db4e-4b96-aa7e-d74d05c17b32", "metadata": {}, "source": [ "### Use the cursor method `callproc()`" ] }, { "cell_type": "code", "execution_count": 5, "id": "1362851c-51fc-4c74-b7fd-1061764f3067", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "cursor.callproc('all_students')\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idlastfirstcontact_id
0S1001DoeJohnC03
1S1005NovakTimC04
2S1009KleinLeslieC05
3S1014JaneMaryC01
4S1021SmithKimC02
\n", "
" ], "text/plain": [ " id last first contact_id\n", "0 S1001 Doe John C03\n", "1 S1005 Novak Tim C04\n", "2 S1009 Klein Leslie C05\n", "3 S1014 Jane Mary C01\n", "4 S1021 Smith Kim C02" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "print(\"cursor.callproc('all_students')\")\n", "print()\n", "\n", "cursor.callproc('all_students')\n", "\n", "for result in cursor.stored_results():\n", " display_results(result)" ] }, { "cell_type": "markdown", "id": "4dcb918b-43d4-4adc-b59c-5664c1c0695a", "metadata": { "tags": [] }, "source": [ "# Call stored procedure `class_codes_of()` for John Doe" ] }, { "cell_type": "markdown", "id": "35f1819b-5af3-4be7-9c1f-31f137ef4389", "metadata": { "tags": [] }, "source": [ "### Use SQL's `CALL` command" ] }, { "cell_type": "code", "execution_count": 7, "id": "081555e4-11d8-4518-9f61-291e2bdf0b44", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "CALL class_codes_of('John', 'Doe')\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
code
0DATA 220
1DATA 225
2DATA 240
\n", "
" ], "text/plain": [ " code\n", "0 DATA 220\n", "1 DATA 225\n", "2 DATA 240" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "sql = f\"CALL class_codes_of('John', 'Doe')\"\n", "print()\n", "print(sql)\n", "print()\n", "\n", "generator = cursor.execute(sql, multi=True)\n", "\n", "for result in generator:\n", " display_results(result)" ] }, { "cell_type": "markdown", "id": "d2b9546a-b900-4680-965f-3be9400282a9", "metadata": {}, "source": [ "### Use the cursor method `callproc()`" ] }, { "cell_type": "code", "execution_count": 15, "id": "5cf1ea50-1593-4a2e-bdbd-d2fe03c0d256", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "cursor.callproc('class_codes_of', ('John', 'Doe')\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
code
0DATA 220
1DATA 225
2DATA 240
\n", "
" ], "text/plain": [ " code\n", "0 DATA 220\n", "1 DATA 225\n", "2 DATA 240" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "print(f\"cursor.callproc('class_codes_of', {('John', 'Doe')}\")\n", "print()\n", "\n", "cursor.callproc('class_codes_of', ('John', 'Doe'))\n", "\n", "for result in cursor.stored_results():\n", " display_results(result)" ] }, { "cell_type": "markdown", "id": "24818fbb-b1aa-46c7-9a9b-b81162699afd", "metadata": { "tags": [] }, "source": [ "# Call stored procedure `class_codes_of()` for each student" ] }, { "cell_type": "markdown", "id": "c42edf7c-8246-4c74-8ac9-47f902933f71", "metadata": {}, "source": [ "### First get a list of students' names." ] }, { "cell_type": "code", "execution_count": 6, "id": "84c7a01a-06f4-4be5-9503-de473cedaf58", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[('John', 'Doe'),\n", " ('Tim', 'Novak'),\n", " ('Leslie', 'Klein'),\n", " ('Mary', 'Jane'),\n", " ('Kim', 'Smith')]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cursor.execute('SELECT first, last FROM student')\n", "\n", "students = cursor.fetchall()\n", "students" ] }, { "cell_type": "markdown", "id": "34842e26-a8b2-4ded-8189-a015ca56ee74", "metadata": { "tags": [] }, "source": [ "### Use SQL's `CALL` command" ] }, { "cell_type": "code", "execution_count": 16, "id": "78a4845d-f5fd-442a-8179-5dd33bbae389", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "CALL class_codes_of('John', 'Doe')\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
code
0DATA 220
1DATA 225
2DATA 240
\n", "
" ], "text/plain": [ " code\n", "0 DATA 220\n", "1 DATA 225\n", "2 DATA 240" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "CALL class_codes_of('Tim', 'Novak')\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
code
0DATA 220
1DATA 225
2DATA 245
\n", "
" ], "text/plain": [ " code\n", "0 DATA 220\n", "1 DATA 225\n", "2 DATA 245" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "CALL class_codes_of('Leslie', 'Klein')\n", "\n", "\n", "CALL class_codes_of('Mary', 'Jane')\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
code
0DATA 200
1DATA 245
\n", "
" ], "text/plain": [ " code\n", "0 DATA 200\n", "1 DATA 245" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "CALL class_codes_of('Kim', 'Smith')\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
code
0DATA 200
1DATA 225
2DATA 240
\n", "
" ], "text/plain": [ " code\n", "0 DATA 200\n", "1 DATA 225\n", "2 DATA 240" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "for first, last in students:\n", " sql = f\"CALL class_codes_of('{first}', '{last}')\"\n", " print()\n", " print(sql)\n", " print()\n", " \n", " generator = cursor.execute(sql, multi=True)\n", " \n", " for result in generator:\n", " display_results(result)" ] }, { "cell_type": "markdown", "id": "600c5f50-5a48-4718-af2d-94d0edac2859", "metadata": {}, "source": [ "### Use the cursor method `callproc()`" ] }, { "cell_type": "code", "execution_count": 17, "id": "ddc45227-8731-470f-8798-4974d37db47c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "cursor.callproc('class_codes_of', ('John', 'Doe'))\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
code
0DATA 220
1DATA 225
2DATA 240
\n", "
" ], "text/plain": [ " code\n", "0 DATA 220\n", "1 DATA 225\n", "2 DATA 240" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "cursor.callproc('class_codes_of', ('Tim', 'Novak'))\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
code
0DATA 220
1DATA 225
2DATA 245
\n", "
" ], "text/plain": [ " code\n", "0 DATA 220\n", "1 DATA 225\n", "2 DATA 245" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "cursor.callproc('class_codes_of', ('Leslie', 'Klein'))\n", "\n", "\n", "cursor.callproc('class_codes_of', ('Mary', 'Jane'))\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
code
0DATA 200
1DATA 245
\n", "
" ], "text/plain": [ " code\n", "0 DATA 200\n", "1 DATA 245" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "cursor.callproc('class_codes_of', ('Kim', 'Smith'))\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
code
0DATA 200
1DATA 225
2DATA 240
\n", "
" ], "text/plain": [ " code\n", "0 DATA 200\n", "1 DATA 225\n", "2 DATA 240" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "for student in students: \n", " print()\n", " print(f\"cursor.callproc('class_codes_of', {student})\")\n", " print()\n", " \n", " cursor.callproc('class_codes_of', student)\n", " \n", " for result in cursor.stored_results():\n", " display_results(result)" ] }, { "cell_type": "markdown", "id": "85cb25fe-a9e3-4b4d-9cd7-0c569222dbf5", "metadata": { "tags": [] }, "source": [ "# Call stored procedure `classmates_of()`" ] }, { "cell_type": "markdown", "id": "ea672181-a1cb-45f0-ba1b-21ec30611d9a", "metadata": { "tags": [] }, "source": [ "### Use SQL's `CALL` command" ] }, { "cell_type": "code", "execution_count": 10, "id": "34221da6-2752-4bb6-8b1e-793a7f4aea34", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "CALL classmates_of('John', 'Doe')\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
firstlastcodesubject
0TimNovakDATA 220Mathematical Models
1TimNovakDATA 225Database Systems
2KimSmithDATA 225Database Systems
3KimSmithDATA 240Data Mining
\n", "
" ], "text/plain": [ " first last code subject\n", "0 Tim Novak DATA 220 Mathematical Models\n", "1 Tim Novak DATA 225 Database Systems\n", "2 Kim Smith DATA 225 Database Systems\n", "3 Kim Smith DATA 240 Data Mining" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "CALL classmates_of('Tim', 'Novak')\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
firstlastcodesubject
0JohnDoeDATA 220Mathematical Models
1JohnDoeDATA 225Database Systems
2KimSmithDATA 225Database Systems
3MaryJaneDATA 245Machine Learning
\n", "
" ], "text/plain": [ " first last code subject\n", "0 John Doe DATA 220 Mathematical Models\n", "1 John Doe DATA 225 Database Systems\n", "2 Kim Smith DATA 225 Database Systems\n", "3 Mary Jane DATA 245 Machine Learning" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "CALL classmates_of('Leslie', 'Klein')\n", "\n", "\n", "CALL classmates_of('Mary', 'Jane')\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
firstlastcodesubject
0KimSmithDATA 200Python Programming
1TimNovakDATA 245Machine Learning
\n", "
" ], "text/plain": [ " first last code subject\n", "0 Kim Smith DATA 200 Python Programming\n", "1 Tim Novak DATA 245 Machine Learning" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "CALL classmates_of('Kim', 'Smith')\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
firstlastcodesubject
0MaryJaneDATA 200Python Programming
1JohnDoeDATA 225Database Systems
2TimNovakDATA 225Database Systems
3JohnDoeDATA 240Data Mining
\n", "
" ], "text/plain": [ " first last code subject\n", "0 Mary Jane DATA 200 Python Programming\n", "1 John Doe DATA 225 Database Systems\n", "2 Tim Novak DATA 225 Database Systems\n", "3 John Doe DATA 240 Data Mining" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "for first, last in students:\n", " sql = f\"CALL classmates_of('{first}', '{last}')\"\n", " print()\n", " print(sql)\n", " print()\n", " \n", " generator = cursor.execute(sql, multi=True)\n", " \n", " for result in generator:\n", " display_results(result)" ] }, { "cell_type": "markdown", "id": "96025eef-a54d-4912-a147-554e12794c73", "metadata": {}, "source": [ "### Use the cursor method `callproc()`" ] }, { "cell_type": "code", "execution_count": 11, "id": "f25fe985-af30-4508-b54b-8adb9835b65a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "cursor.callproc('classmates_of', ('John', 'Doe'))\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
firstlastcodesubject
0TimNovakDATA 220Mathematical Models
1TimNovakDATA 225Database Systems
2KimSmithDATA 225Database Systems
3KimSmithDATA 240Data Mining
\n", "
" ], "text/plain": [ " first last code subject\n", "0 Tim Novak DATA 220 Mathematical Models\n", "1 Tim Novak DATA 225 Database Systems\n", "2 Kim Smith DATA 225 Database Systems\n", "3 Kim Smith DATA 240 Data Mining" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "cursor.callproc('classmates_of', ('Tim', 'Novak'))\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
firstlastcodesubject
0JohnDoeDATA 220Mathematical Models
1JohnDoeDATA 225Database Systems
2KimSmithDATA 225Database Systems
3MaryJaneDATA 245Machine Learning
\n", "
" ], "text/plain": [ " first last code subject\n", "0 John Doe DATA 220 Mathematical Models\n", "1 John Doe DATA 225 Database Systems\n", "2 Kim Smith DATA 225 Database Systems\n", "3 Mary Jane DATA 245 Machine Learning" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "cursor.callproc('classmates_of', ('Leslie', 'Klein'))\n", "\n", "\n", "cursor.callproc('classmates_of', ('Mary', 'Jane'))\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
firstlastcodesubject
0KimSmithDATA 200Python Programming
1TimNovakDATA 245Machine Learning
\n", "
" ], "text/plain": [ " first last code subject\n", "0 Kim Smith DATA 200 Python Programming\n", "1 Tim Novak DATA 245 Machine Learning" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "cursor.callproc('classmates_of', ('Kim', 'Smith'))\n", "\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
firstlastcodesubject
0MaryJaneDATA 200Python Programming
1JohnDoeDATA 225Database Systems
2TimNovakDATA 225Database Systems
3JohnDoeDATA 240Data Mining
\n", "
" ], "text/plain": [ " first last code subject\n", "0 Mary Jane DATA 200 Python Programming\n", "1 John Doe DATA 225 Database Systems\n", "2 Tim Novak DATA 225 Database Systems\n", "3 John Doe DATA 240 Data Mining" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "for student in students:\n", " first, last = student\n", " \n", " print()\n", " print(f\"cursor.callproc('classmates_of', {student})\")\n", " print()\n", " \n", " cursor.callproc('classmates_of', student)\n", " \n", " for result in cursor.stored_results():\n", " display_results(result)" ] }, { "cell_type": "code", "execution_count": 12, "id": "c9f2f764-4da8-4cab-8d47-34892816e0ee", "metadata": {}, "outputs": [], "source": [ "cursor.close()\n", "conn.close()" ] }, { "cell_type": "code", "execution_count": null, "id": "ae3eab62-e0c2-47a1-bbeb-53cacb1e11db", "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 }