MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_NextPart_01D0027A.A5070230" このドキュメントは単一ファイル Web ページ (Web アーカイブ ファイル) です。お使いのブラウザー、またはエディターは Web アーカイブ ファイルをサポートしていません。Windows? Internet Explorer? など、Web アーカイブをサポートするブラウザーをダウンロードしてください。 ------=_NextPart_01D0027A.A5070230 Content-Location: file:///C:/B1341C75/db5.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="shift_jis"
データベース特論資料 5 (Advanced Database Exercise =
5)
2014年11月17日
概要 Abstract
今日の授業では、Web
サーバとデータベースの連携について=
燒セする。前回の授業の
MySQL Employees Sample データベースを使用する
Tod=
ay's
class is Web and database. MySQL Exmployees Sample is used as a sample data=
set.
■ Web
サーバ Web server=
Web=
サーバは、Webブラウザ等からの要求に対して、返答を返す。返答はHTMLであったり、他のオブジェクトであったりする.
Web
server send a response to a request from Web browser, etc. A response may be
HTML or another object.
■
Web サーバのポート番号 Port number of Web server
Web=
サーバの起動時には、通信に使うポート番号を指定できる。今回の授業では、=
次のようにして、ポート番号8080番を指定する.
We =
can
specify the port number of Web server when it's launch. Today. port number =
8080
is specified as follows.
■
リクエストのルーティング Request routing
Webサーバに送られた
URL に応じて処理を変えたいとする.例え=
ホ、Web
ブラウザで 「http://localhost/db」としたときには「welcome」を、「http://localhost/db/hoge」としたときには「hoge」を表示したいとする.
このとき、次のようなプログラムを書く
We
would like to generate a Web server response on-time, and generate different
types of response for different URLs. For example, a response
"welcome" for the URL "http://localhost/db", and a resp=
onse
"hoge" for the URL "http://localhsot/db/hoge".
# -*- coding:=
utf-8
-*-
import bottle=
@bottle.route=
('/db')
def tables():=
return 'welcome'
@bottle.route=
('/db/hoge')
def list():
return 'hoge'
bottle.run(ho=
st=3D'localhost',
port=3D8080, debug=3DTrue,
reloader=3DTrue)
■ SQLite3
でのテーブル一覧取得 get the list of tables of SQLite3
database
SQLite3でテーブル一覧を取得したいときは、次のようなSQLプログラムを書く.
Write
a SQL program as follows to get the list of tables of a SQLite3 database
SELECT name FROM sqlite_master WHERE type=3D'table';<=
/span>
演習
5 (Exercises 5)
前準備
(preparation)
・pythonxy
のインストール &=
nbsp; (install
pythonxy)
・spyder
のインストール
・MySQL
Empolyees Sample データベース
・python
の bo=
ttle パッケージのインストール
(install python's bottle package)
MySQL employees samp=
le データベースの出典と著作権表示
出典:MySQL
employees sample database https://dev.mysql.com/doc/employee/en/
=3D=3D=3D
This work is licensed under the Creative C=
ommons
Attribution-Share Alike 3.0 Unported License. To view a copy of this licens=
e,
visit <=
span
style=3D'font-size:10.0pt;font-family:"Times New Roman",serif;color:#6611CC;
background:white'>http://creativecommons.org/licenses/by-sa/3.0/=
or send a letter to Creative Commons, 171 Second
Street, Suite 300, San Francisco, California, 94105, USA.
Please contact http://www.mysql.com/about/contact/ for more information.
■ <=
/span>ステップ1
(Step 1)
課題:以下の手順で Spyderの設定を行いなさい =
(Setup the Spyder software)
1.&n=
bsp;
Spyder の起動
(execute the Spyder)
&=
nbsp; &nbs=
p; &=
nbsp; &nbs=
p;
2.&n=
bsp;
Interpreters で =
span>「Open an IPython Console<=
/b>」を選ぶ. (Select Interpreters, and Select =
gOpen
an IPython console”)
3.&n=
bsp;
「IPy=
thon
console」をクリック. (Click “IPython console”)
■ <=
/span>ステップ2
(Step 2)
spy=
der のエディタを使いたい. Use editor in the spyder
1. =
Spyder
で File -> =
New
file… と操作する
2.<=
/span>エディタ・ウインドウで、試しに「print
1 + 2」と書いてみる Tr=
y to
write "print 1 + 2" in the editor window
3. =
実行ボタンをクリックする click the "run button"
4. =
初めて実行するときは、ファイル名を指定して保存する
Save the program file if it is the first run.
5. =
結果を確認する Examine
the result
■ <=
/span>ステップ3
(Step 3)
1.S=
pyder のエディタで次のプログラムを記述する Write
a program in spyder editor.
2. =
実行ボタンをクリックする click the "run button"
3. =
Web ブラウザを開き、http://localhost:8080/db
を指定すると we=
lcome と表示される
Open Web browser and specify the URL "http://localhost:8080/db". =
"welcome"
will be displayed.
※
Windows でうまく動かない場合=
ファイヤウオールが設定されている可=
\性がある。次の手順で、ポート番号8080に関するファイヤウオールを解除して=
ンる.
■ <=
/span>ステップ4
(Step 4)
2. =
Web ブラウザで、http://localhost:8080/db
を指定すると、今度は、hoge
と表示される
Open Web browser and specify the URL "http://localhost:8080/db". =
"hoge"
will be displayed.
■ <=
/span>ステップ5
(Step 5)
1.S=
pyder のエディタで次のプログラムを記述する Write
a program in spyder editor.
File ->Save と操作する
3. =
Web ブラウザを開き、http://localhost:8080/db
を指定するとテーブル一覧が表示される Open Web browser and specify t=
he
URL "http://localhost:8080/db". The list of tables will be displa=
yed.
■ <=
/span>ステップ6
(Step 6)
1.S=
pyder のエディタで次のプログラムを記述する Write
a program in spyder editor.
2. =
ファイルを書き換えたので File ->Save と操作する
3. =
Web ブラウザを開き、http://localhost:8080/db/depart=
ments
を指定するとデータが表示される Op=
en Web
browser and specify the URL "=
http://localhost:8080/db/departments ". The table data will be
displayed.
演習シート 5
(Exercises Sheet 5) 201=
4/11/17
氏名 =
鼾U 学生番号
Name =
&nb=
sp;
Department &=
nbsp; &nbs=
p;
Student number =
記入して提出しなさい Fill out and submit
Q1 ステップ1は終わったか 終わっていないか? Did you finish the step 1 ?
□ はい
Yes =
□ いいえ No
Q1b もし終わっていないなら、理由、エラ=
[メッセージなどを書きなさい.
If 'No', please explai=
n your
situation
Q2 ステップ2は終わったか 終わっていないか? Did you finish the step 2 ?
□ はい
Yes =
□ いいえ No
Q2b もし終わっていないなら、理由、エラ=
[メッセージなどを書きなさい.
If 'No', please explai=
n your
situation
Q3 ステップ3は終わったか 終わっていないか? Did you finish the step 3 ?
□ はい
Yes =
□ いいえ No
Q3b もし終わっていないなら、理由、エラ=
[メッセージなどを書きなさい.
If 'No', please explai=
n your
situation
Q4 ステップ4は終わったか 終わっていないか? Did you finish the step 4 ?
□ はい
Yes =
□ いいえ No
Q4b もし終わっていないなら、理由、エラ=
[メッセージなどを書きなさい.
If 'No', please explai=
n your
situation
Q5 ステップ5は終わったか 終わっていないか? Did you finish the step 5 ?
□ はい
Yes =
□ いいえ No
Q5b もし終わっていないなら、理由、エラ=
[メッセージなどを書きなさい.
If 'No', please explai=
n your
situation