{ "cells": [ { "cell_type": "markdown", "id": "4797d7df", "metadata": {}, "source": [ "# Introduction to databases" ] }, { "cell_type": "markdown", "id": "11c7d73c", "metadata": {}, "source": [ "## Thought experiment\n", "\n", "A set of tools that\n", "\n", "- manage data about students' grades, and\n", "- do not utilize any dedicated database system.\n", "\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
" ] }, { "cell_type": "markdown", "id": "ff3edbda", "metadata": {}, "source": [ "## Text file based data storage example" ] }, { "cell_type": "code", "execution_count": null, "id": "8110ee4c", "metadata": {}, "outputs": [], "source": [ "from IPython import display" ] }, { "cell_type": "code", "execution_count": null, "id": "2b823019", "metadata": {}, "outputs": [], "source": [ "!./generate_students.py > students.textdb\n", "print(\"idx lab prj exam\")\n", "!cat students.textdb" ] }, { "cell_type": "markdown", "id": "281b1468", "metadata": {}, "source": [ "### Program to set data" ] }, { "cell_type": "code", "execution_count": null, "id": "0382b96e", "metadata": { "scrolled": false }, "outputs": [], "source": [ "display.Code(filename=\"./set_student_1.py\")" ] }, { "cell_type": "code", "execution_count": null, "id": "de7591c6", "metadata": {}, "outputs": [], "source": [ "!./set_student_1.py 512345 5.0 3.0 2.0\n", "print(\"idx lab prj exam\")\n", "!cat students.textdb" ] }, { "cell_type": "markdown", "id": "842c4e01", "metadata": {}, "source": [ "#### Simulated system/program crash" ] }, { "cell_type": "code", "execution_count": null, "id": "973ef24a", "metadata": {}, "outputs": [], "source": [ "!./set_student_1.py 512345 5.0 3.0 4.0 & sleep 1; kill %1\n", "!cat students.textdb" ] }, { "cell_type": "markdown", "id": "e4bf8578", "metadata": {}, "source": [ "### Program to set data — attempt 2" ] }, { "cell_type": "code", "execution_count": null, "id": "53df4dc0", "metadata": {}, "outputs": [], "source": [ "display.Code(filename=\"set_student_2.py\")" ] }, { "cell_type": "code", "execution_count": null, "id": "d9f6691c", "metadata": { "scrolled": true }, "outputs": [], "source": [ "# start anew\n", "!./generate_students.py > students.textdb\n", "print(\"idx lab prj exam\")\n", "!cat students.textdb" ] }, { "cell_type": "code", "execution_count": null, "id": "928b624f", "metadata": {}, "outputs": [], "source": [ "!./set_student_2.py 512345 5.0 3.0 4.0\n", "!cat students.textdb" ] }, { "cell_type": "markdown", "id": "dfae4a16", "metadata": {}, "source": [ "#### Simulated simultaneous update" ] }, { "cell_type": "code", "execution_count": null, "id": "52d3e9db", "metadata": {}, "outputs": [], "source": [ "display.Code(filename=\"./set_students_2.sh\", language=\"shell\")" ] }, { "cell_type": "code", "execution_count": null, "id": "b263fe8f", "metadata": {}, "outputs": [], "source": [ "!./set_students_2.sh 514168 4.5 4.5 3.0\n", "!cat students.textdb" ] }, { "cell_type": "markdown", "id": "af5561e6", "metadata": {}, "source": [ "### Program to set data — attempt 3" ] }, { "cell_type": "code", "execution_count": null, "id": "81c57c0c", "metadata": {}, "outputs": [], "source": [ "display.Code(filename=\"set_student_3.py\")" ] }, { "cell_type": "code", "execution_count": null, "id": "3f2a2692", "metadata": {}, "outputs": [], "source": [ "# start anew once again\n", "!./generate_students.py > students.textdb\n", "print(\"idx lab prj exam\")\n", "!cat students.textdb" ] }, { "cell_type": "markdown", "id": "2775f5f4", "metadata": {}, "source": [ "#### Second simulated simultaneous update" ] }, { "cell_type": "code", "execution_count": null, "id": "f29937aa", "metadata": {}, "outputs": [], "source": [ "display.Code(filename=\"./set_students_3.sh\", language=\"shell\")" ] }, { "cell_type": "code", "execution_count": null, "id": "d97ae6d4", "metadata": {}, "outputs": [], "source": [ "!./set_students_3.sh 514168 4.5 4.5 3.0\n", "!cat students.textdb" ] }, { "cell_type": "markdown", "id": "65edc48c", "metadata": {}, "source": [ "## Text file based data storage — summary\n", "\n", "- pros?\n", "- cons?" ] }, { "cell_type": "code", "execution_count": null, "id": "9ac3d75c", "metadata": {}, "outputs": [], "source": [ "!cat /etc/passwd" ] }, { "cell_type": "markdown", "id": "c77bcb9b", "metadata": {}, "source": [ "### Kinds of databases\n", "\n", "![](server-dekstop-mobile.svg)\n", "\n", "#### Graphics sources\n", "\n", "- https://publicdomainvectors.org/en/free-clipart/Isometric-server-cabinet-vector-graphics/13444.html\n", "- https://publicdomainvectors.org/en/free-clipart/Computer-CPU-and-monitor-vector-image/21942.html\n", "- https://publicdomainvectors.org/en/free-clipart/Smartphone-vector-clip-art/8352.html" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "/gnu/store/q35bxk1i5blx0rcgxphhrq9xqmgha9bz-python-3.11.11/bin/python3", "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.11.11" } }, "nbformat": 4, "nbformat_minor": 5 }