Skip to content

Commit 1521132

Browse files
bug fix in setup
1 parent bfe0c13 commit 1521132

File tree

3 files changed

+110
-129
lines changed

3 files changed

+110
-129
lines changed

book/10-setup/02-connect.ipynb

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,16 @@
3131
},
3232
{
3333
"cell_type": "code",
34-
"execution_count": 1,
34+
"execution_count": 5,
3535
"metadata": {},
3636
"outputs": [
37-
{
38-
"name": "stderr",
39-
"output_type": "stream",
40-
"text": [
41-
"[2024-08-14 03:55:54,328][INFO]: Connecting root@localhost:3306\n",
42-
"[2024-08-14 03:55:54,347][INFO]: Connected root@localhost:3306\n"
43-
]
44-
},
4537
{
4638
"data": {
4739
"text/plain": [
4840
"DataJoint connection (connected) root@localhost:3306"
4941
]
5042
},
51-
"execution_count": 1,
43+
"execution_count": 5,
5244
"metadata": {},
5345
"output_type": "execute_result"
5446
}
@@ -66,6 +58,22 @@
6658
"If you are reading this text to also learn SQL, you can use two ways to issue queries: with IPython magic commands or a client library."
6759
]
6860
},
61+
{
62+
"cell_type": "markdown",
63+
"metadata": {},
64+
"source": [
65+
"If you are only learning DataJoint, you are done.\n",
66+
"If you are reading this text to also learn SQL, you can use two ways to issue queries: with IPython magic commands or a client library."
67+
]
68+
},
69+
{
70+
"cell_type": "markdown",
71+
"metadata": {},
72+
"source": [
73+
"If you are only learning DataJoint, you are done.\n",
74+
"If you are reading this text to also learn SQL, you can use two ways to issue queries: with IPython magic commands or a client library."
75+
]
76+
},
6977
{
7078
"cell_type": "markdown",
7179
"metadata": {},
@@ -79,7 +87,7 @@
7987
},
8088
{
8189
"cell_type": "code",
82-
"execution_count": 2,
90+
"execution_count": null,
8391
"metadata": {},
8492
"outputs": [],
8593
"source": [
@@ -94,7 +102,10 @@
94102
")\n",
95103
"\n",
96104
"%load_ext sql\n",
97-
"%sql $connection_string"
105+
"%sql $connection_string\n",
106+
"\n",
107+
"%config SqlMagic.style = '_DEPRECATED_DEFAULT' # addresses a bug in the SQL magic extension\n",
108+
"\n"
98109
]
99110
},
100111
{
@@ -107,7 +118,7 @@
107118
},
108119
{
109120
"cell_type": "code",
110-
"execution_count": 3,
121+
"execution_count": 4,
111122
"metadata": {
112123
"vscode": {
113124
"languageId": "sql"
@@ -123,44 +134,19 @@
123134
]
124135
},
125136
{
126-
"data": {
127-
"text/html": [
128-
"<table>\n",
129-
" <thead>\n",
130-
" <tr>\n",
131-
" <th>User</th>\n",
132-
" </tr>\n",
133-
" </thead>\n",
134-
" <tbody>\n",
135-
" <tr>\n",
136-
" <td>debian-sys-maint</td>\n",
137-
" </tr>\n",
138-
" <tr>\n",
139-
" <td>mysql.infoschema</td>\n",
140-
" </tr>\n",
141-
" <tr>\n",
142-
" <td>mysql.session</td>\n",
143-
" </tr>\n",
144-
" <tr>\n",
145-
" <td>mysql.sys</td>\n",
146-
" </tr>\n",
147-
" <tr>\n",
148-
" <td>root</td>\n",
149-
" </tr>\n",
150-
" </tbody>\n",
151-
"</table>"
152-
],
153-
"text/plain": [
154-
"[('debian-sys-maint',),\n",
155-
" ('mysql.infoschema',),\n",
156-
" ('mysql.session',),\n",
157-
" ('mysql.sys',),\n",
158-
" ('root',)]"
159-
]
160-
},
161-
"execution_count": 3,
162-
"metadata": {},
163-
"output_type": "execute_result"
137+
"ename": "KeyError",
138+
"evalue": "'DEFAULT'",
139+
"output_type": "error",
140+
"traceback": [
141+
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
142+
"\u001b[31mKeyError\u001b[39m Traceback (most recent call last)",
143+
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[4]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mget_ipython\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m.\u001b[49m\u001b[43mrun_cell_magic\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43msql\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43m-- show all users\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[33;43mSELECT User FROM mysql.user\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[33;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n",
144+
"\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.11/site-packages/IPython/core/interactiveshell.py:2565\u001b[39m, in \u001b[36mInteractiveShell.run_cell_magic\u001b[39m\u001b[34m(self, magic_name, line, cell)\u001b[39m\n\u001b[32m 2563\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m.builtin_trap:\n\u001b[32m 2564\u001b[39m args = (magic_arg_s, cell)\n\u001b[32m-> \u001b[39m\u001b[32m2565\u001b[39m result = \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 2567\u001b[39m \u001b[38;5;66;03m# The code below prevents the output from being displayed\u001b[39;00m\n\u001b[32m 2568\u001b[39m \u001b[38;5;66;03m# when using magics with decorator @output_can_be_silenced\u001b[39;00m\n\u001b[32m 2569\u001b[39m \u001b[38;5;66;03m# when the last Python token in the expression is a ';'.\u001b[39;00m\n\u001b[32m 2570\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mgetattr\u001b[39m(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, \u001b[38;5;28;01mFalse\u001b[39;00m):\n",
145+
"\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.11/site-packages/sql/magic.py:219\u001b[39m, in \u001b[36mSqlMagic.execute\u001b[39m\u001b[34m(self, line, cell, local_ns)\u001b[39m\n\u001b[32m 216\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[32m 218\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m219\u001b[39m result = \u001b[43msql\u001b[49m\u001b[43m.\u001b[49m\u001b[43mrun\u001b[49m\u001b[43m.\u001b[49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mconn\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mparsed\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43msql\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43muser_ns\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 221\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m (\n\u001b[32m 222\u001b[39m result \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m 223\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(result, \u001b[38;5;28mstr\u001b[39m)\n\u001b[32m (...)\u001b[39m\u001b[32m 226\u001b[39m \u001b[38;5;66;03m# Instead of returning values, set variables directly in the\u001b[39;00m\n\u001b[32m 227\u001b[39m \u001b[38;5;66;03m# user's namespace. Variable names given by column names\u001b[39;00m\n\u001b[32m 229\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m.autopandas:\n",
146+
"\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.11/site-packages/sql/run.py:374\u001b[39m, in \u001b[36mrun\u001b[39m\u001b[34m(conn, sql, config, user_namespace)\u001b[39m\n\u001b[32m 372\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m result \u001b[38;5;129;01mand\u001b[39;00m config.feedback:\n\u001b[32m 373\u001b[39m \u001b[38;5;28mprint\u001b[39m(interpret_rowcount(result.rowcount))\n\u001b[32m--> \u001b[39m\u001b[32m374\u001b[39m resultset = \u001b[43mResultSet\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresult\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 375\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m config.autopandas:\n\u001b[32m 376\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m resultset.DataFrame()\n",
147+
"\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.11/site-packages/sql/run.py:116\u001b[39m, in \u001b[36mResultSet.__init__\u001b[39m\u001b[34m(self, sqlaproxy, config)\u001b[39m\n\u001b[32m 114\u001b[39m \u001b[38;5;28mlist\u001b[39m.\u001b[34m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m, sqlaproxy.fetchall())\n\u001b[32m 115\u001b[39m \u001b[38;5;28mself\u001b[39m.field_names = unduplicate_field_names(\u001b[38;5;28mself\u001b[39m.keys)\n\u001b[32m--> \u001b[39m\u001b[32m116\u001b[39m \u001b[38;5;28mself\u001b[39m.pretty = PrettyTable(\u001b[38;5;28mself\u001b[39m.field_names, style=\u001b[43mprettytable\u001b[49m\u001b[43m.\u001b[49m\u001b[34;43m__dict__\u001b[39;49m\u001b[43m[\u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m.\u001b[49m\u001b[43mstyle\u001b[49m\u001b[43m.\u001b[49m\u001b[43mupper\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m]\u001b[49m)\n\u001b[32m 117\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m 118\u001b[39m \u001b[38;5;28mlist\u001b[39m.\u001b[34m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m, [])\n",
148+
"\u001b[31mKeyError\u001b[39m: 'DEFAULT'"
149+
]
164150
}
165151
],
166152
"source": [
@@ -250,7 +236,7 @@
250236
"name": "python",
251237
"nbconvert_exporter": "python",
252238
"pygments_lexer": "ipython3",
253-
"version": "3.10.14"
239+
"version": "3.11.13"
254240
}
255241
},
256242
"nbformat": 4,

0 commit comments

Comments
 (0)