Skip to content
Permalink
Browse files

add magic command step 1

  • Loading branch information...
sdpython committed Nov 7, 2014
1 parent 643b77c commit d4845d2b40f618a3bec8d6159039209b59e2d0fc
Showing with 141 additions and 3 deletions.
  1. +137 −0 _doc/notebooks/pyensae_sql_magic.ipynb
  2. +4 −3 src/pyensae/sql/magic_sql.py
@@ -0,0 +1,137 @@
{
"metadata": {
"name": "",
"signature": "sha256:f987f6877862e27651eaf91ad366f98f6120f1c560114d929dec1cbb3282ead9"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"SQL Magic Command with SQLite"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[SQLiteSpy](http://www.yunqa.de/delphi/doku.php/products/sqlitespy/index)"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import pyensae\n",
"pyensae.download_data(\"velib_vanves.zip\", website = \"xd\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 1,
"text": [
"['velib_vanves.txt']"
]
}
],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"if pyensae.__version__ < \"0.9.1\" : print(\"it will not work\")"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%SQL_connect notebook_example.db3"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 2,
"text": [
"<pyensae.sql.sql_interface_database.InterfaceSQLDatabase at 0x6b6a7b0>"
]
}
],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%SQL_tables"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 3,
"text": [
"[]"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%SQL_import_flat_file velib_vanves.txt"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"ERROR: Line magic function `%SQL_import_flat_file` not found.\n"
]
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
@@ -9,7 +9,7 @@
from IPython.core.magic import line_cell_magic
from IPython.core.display import HTML

from .sql_interface import InterfaceSQLDatabase
from .sql_interface import InterfaceSQL

@magics_class
class MagicSQL(Magics):
@@ -39,7 +39,8 @@ def SQL_connect(self, line):
print("Usage:")
print(" %SQL_connect <filename>")
else:
obj = InterfaceSQLDatabase.create(file)
obj = InterfaceSQL.create(filename)
obj.connect()
self.shell.user_ns["DB"] = obj
return obj

@@ -112,7 +113,7 @@ def usage():
return df


def register_sql_magicss():
def register_sql_magics():
"""
register magics function, can be called from a notebook
"""

0 comments on commit d4845d2

Please sign in to comment.
You can’t perform that action at this time.