Commits

Matt Bone committed e915fac

adding db examples

  • Participants
  • Parent commits f2bd9fd

Comments (0)

Files changed (2)

XML Programming.ipynb

      "language": "python",
      "metadata": {},
      "outputs": [],
-     "prompt_number": 12
+     "prompt_number": 1
     },
     {
      "cell_type": "code",
        "output_type": "pyout",
        "prompt_number": 6,
        "text": [
-        "[<Element 'article' at 0x2b37c50>]"
+        "[<Element 'article' at 0x21e61d0>]"
        ]
       }
      ],
      "cell_type": "code",
      "collapsed": false,
      "input": [
-      "article_xml = ET.tostring(articles)"
+      "article_xml = ET.tostring(articles)\n",
+      "print article_xml"
      ],
      "language": "python",
      "metadata": {},
-     "outputs": [],
-     "prompt_number": 8
+     "outputs": [
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "<articles><article end_page=\"5\" journal=\"Journal of Article Greatness\" start_page=\"4\" title=\"My Great Article\" /><article end_page=\"9\" journal=\"Journal of Article Greatness\" start_page=\"8\" title=\"My Second Great Article\" /></articles>\n"
+       ]
+      }
+     ],
+     "prompt_number": 12
     },
     {
      "cell_type": "code",
      "language": "python",
      "metadata": {},
      "outputs": [],
-     "prompt_number": 22
+     "prompt_number": 8
     },
     {
      "cell_type": "code",
        ]
       }
      ],
-     "prompt_number": 23
+     "prompt_number": 13
     },
     {
      "cell_type": "markdown",
      "language": "python",
      "metadata": {},
      "outputs": [],
-     "prompt_number": 24
+     "prompt_number": 10
     },
     {
      "cell_type": "code",
        ]
       }
      ],
-     "prompt_number": 25
+     "prompt_number": 14
     },
     {
      "cell_type": "code",
      "input": [],
      "language": "python",
      "metadata": {},
-     "outputs": []
+     "outputs": [],
+     "prompt_number": 11
     }
    ],
    "metadata": {}

database_examples.ipynb

+{
+ "metadata": {
+  "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+  {
+   "cells": [
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "import sqlite3"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 2
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "conn = sqlite3.connect('database_example.db')"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 3
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "c = conn.cursor()\n",
+      "\n",
+      "c.execute(\"\"\"\\\n",
+      "CREATE TABLE students (\n",
+      "    id INTEGER NOT NULL,\n",
+      "    name CHAR(30),\n",
+      "    age SMALLINT NOT NULL,\n",
+      "    PRIMARY KEY (id));\n",
+      "\"\"\")\n",
+      "\n",
+      "c.execute(\"\"\"\\\n",
+      "CREATE TABLE grades (\n",
+      "    id INTEGER NOT NULL,\n",
+      "    course CHAR(30) NOT NULL,\n",
+      "    grade CHAR(2) NOT NULL,\n",
+      "    student_id INTEGER NOT NULL\n",
+      ");\n",
+      "\"\"\")"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "ename": "OperationalError",
+       "evalue": "table students already exists",
+       "output_type": "pyerr",
+       "traceback": [
+        "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mOperationalError\u001b[0m                          Traceback (most recent call last)",
+        "\u001b[1;32m<ipython-input-5-53886e308ce1>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      6\u001b[0m     \u001b[0mage\u001b[0m \u001b[0mSMALLINT\u001b[0m \u001b[0mNOT\u001b[0m \u001b[0mNULL\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      7\u001b[0m     PRIMARY KEY (id));\n\u001b[1;32m----> 8\u001b[1;33m \"\"\")\n\u001b[0m\u001b[0;32m      9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     10\u001b[0m c.execute(\"\"\"CREATE TABLE grades (\n",
+        "\u001b[1;31mOperationalError\u001b[0m: table students already exists"
+       ]
+      }
+     ],
+     "prompt_number": 5
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    }
+   ],
+   "metadata": {}
+  }
+ ]
+}