blog/content/post/2012-04-22-00001554.md

281 lines
33 KiB
Markdown
Raw Normal View History

2019-03-31 11:00:21 +00:00
---
title: もう少しgauche-dbd-sqlite3で遊んでみた
author: kazu634
date: 2012-04-22
url: /2012/04/22/_1768/
wordtwit_post_info:
- 'O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:5459;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}'
categories:
- gauche
- sqlite3
---
<div class="section">
<p>
使い方をもう少し勉強してみました。
</p>
<h4>
ソース
</h4>
<pre class="syntax-highlight">
<span class="synError">#!/usr/local/bin/gosh</span>
<span class="synComment">;; ==============================</span>
<span class="synComment">;; Libraries:</span>
<span class="synComment">;; ==============================</span>
<span class="synSpecial">(</span>use dbi<span class="synSpecial">)</span>
<span class="synSpecial">(</span>use gauche.collection<span class="synSpecial">)</span>
<span class="synSpecial">(</span>use gauche.test<span class="synSpecial">)</span>
<span class="synComment">;; ==============================</span>
<span class="synComment">;; Variables:</span>
<span class="synComment">;; ==============================</span>
<span class="synSpecial">(</span><span class="synStatement">define</span> <span class="synConstant">*db-file*</span> <span class="synConstant">&#34;test.db&#34;</span><span class="synSpecial">)</span>
<span class="synComment">;; ==============================</span>
<span class="synComment">;; Functions:</span>
<span class="synComment">;; ==============================</span>
<span class="synComment">;; (execute-sql dbfile sql)</span>
<span class="synComment">;; Arguments:</span>
<span class="synComment">;; - dbfile: path-to-sqlite3-dbfile</span>
<span class="synComment">;; - sql: the sql to be executed</span>
<span class="synComment">;;</span>
<span class="synComment">;; Output:</span>
<span class="synComment">;; Collection objects that dbi module returns</span>
<span class="synSpecial">(</span><span class="synStatement">define</span> <span class="synSpecial">(</span>execute-sql dbfile sql<span class="synSpecial">)</span>
<span class="synSpecial">(</span>guard
<span class="synSpecial">(</span>e <span class="synSpecial">((</span><span class="synConstant">&#60;dbi-parameter-error&#62;</span> e<span class="synSpecial">)</span> <span class="synSpecial">(</span>dbi-close connect<span class="synSpecial">))</span>
<span class="synSpecial">((</span><span class="synConstant">&#60;dbi-error&#62;</span> e<span class="synSpecial">)</span> <span class="synSpecial">(</span>exit <span class="synConstant">1</span><span class="synSpecial">))</span>
<span class="synSpecial">(</span><span class="synStatement">else</span> <span class="synSpecial">(</span>raise e<span class="synSpecial">)))</span>
<span class="synSpecial">(</span><span class="synStatement">let*</span> <span class="synSpecial">((</span>connect <span class="synSpecial">(</span>dbi-connect <span class="synSpecial">(</span><span class="synIdentifier">string-append</span> <span class="synConstant">&#34;dbi:sqlite3:&#34;</span>
dbfile<span class="synSpecial">)))</span>
<span class="synSpecial">(</span>query <span class="synSpecial">(</span>dbi-prepare connect sql<span class="synSpecial">))</span>
<span class="synSpecial">(</span>result <span class="synSpecial">(</span>dbi-execute query<span class="synSpecial">)))</span>
<span class="synSpecial">(</span>dbi-close connect<span class="synSpecial">)</span>
result<span class="synSpecial">)))</span>
<span class="synSpecial">(</span><span class="synStatement">define</span> <span class="synSpecial">(</span>test-db-execute sql<span class="synSpecial">)</span>
<span class="synSpecial">(</span>test* <span class="synSpecial">(</span>format <span class="synConstant">&#34;~s&#34;</span> sql<span class="synSpecial">)</span>
<span class="synConstant">#t</span>
<span class="synSpecial">(</span>dbi-open? <span class="synSpecial">(</span>execute-sql <span class="synConstant">*db-file*</span> sql<span class="synSpecial">))))</span>
<span class="synSpecial">(</span><span class="synStatement">define</span> <span class="synSpecial">(</span>gen-list al proc<span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synIdentifier">map</span> <span class="synSpecial">(</span><span class="synStatement">lambda</span> <span class="synSpecial">(</span>l<span class="synSpecial">)</span>
<span class="synSpecial">(</span>proc l<span class="synSpecial">))</span>
al<span class="synSpecial">))</span>
<span class="synSpecial">(</span><span class="synStatement">define</span> <span class="synSpecial">(</span>gen-key-list al<span class="synSpecial">)</span>
<span class="synSpecial">(</span>gen-list al <span class="synIdentifier">car</span><span class="synSpecial">))</span>
<span class="synSpecial">(</span><span class="synStatement">define</span> <span class="synSpecial">(</span>gen-value-list al<span class="synSpecial">)</span>
<span class="synSpecial">(</span>gen-list al <span class="synIdentifier">cdr</span><span class="synSpecial">))</span>
<span class="synSpecial">(</span><span class="synStatement">define</span> <span class="synSpecial">(</span>append-list-string l<span class="synSpecial">)</span>
<span class="synSpecial">(</span>fold <span class="synSpecial">(</span><span class="synStatement">lambda</span> <span class="synSpecial">(</span>data seed<span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synStatement">if</span> <span class="synSpecial">(</span><span class="synIdentifier">string=?</span> seed <span class="synConstant">&#34;&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>format <span class="synConstant">#f</span>
<span class="synSpecial">(</span><span class="synStatement">cond</span>
<span class="synSpecial">[(</span><span class="synIdentifier">number?</span> data<span class="synSpecial">)</span> <span class="synConstant">&#34;~A&#34;</span><span class="synSpecial">]</span>
<span class="synSpecial">[(</span><span class="synIdentifier">string?</span> data<span class="synSpecial">)</span> <span class="synConstant">&#34;'~A'&#34;</span><span class="synSpecial">]</span>
<span class="synSpecial">[(</span><span class="synIdentifier">symbol?</span> data<span class="synSpecial">)</span> <span class="synConstant">&#34;~A&#34;</span><span class="synSpecial">])</span>
data<span class="synSpecial">)</span>
<span class="synSpecial">(</span>format <span class="synConstant">#f</span>
<span class="synSpecial">(</span><span class="synStatement">cond</span>
<span class="synSpecial">[(</span><span class="synIdentifier">number?</span> data<span class="synSpecial">)</span> <span class="synConstant">&#34;~A, ~A&#34;</span><span class="synSpecial">]</span>
<span class="synSpecial">[(</span><span class="synIdentifier">string?</span> data<span class="synSpecial">)</span> <span class="synConstant">&#34;~A, '~A'&#34;</span><span class="synSpecial">]</span>
<span class="synSpecial">[(</span><span class="synIdentifier">symbol?</span> data<span class="synSpecial">)</span> <span class="synConstant">&#34;~A, ~A&#34;</span><span class="synSpecial">])</span>
seed
data<span class="synSpecial">)))</span>
<span class="synConstant">&#34;&#34;</span>
l<span class="synSpecial">))</span>
<span class="synSpecial">(</span><span class="synStatement">define</span> <span class="synSpecial">(</span>gen-insert-sql table al<span class="synSpecial">)</span>
<span class="synSpecial">(</span>format <span class="synConstant">&#34;INSERT INTO ~A (~A) VALUES (~A);&#34;</span>
table
<span class="synSpecial">(</span>append-list-string <span class="synSpecial">(</span>gen-key-list al<span class="synSpecial">))</span>
<span class="synSpecial">(</span>append-list-string <span class="synSpecial">(</span>gen-value-list al<span class="synSpecial">))))</span>
<span class="synSpecial">(</span><span class="synStatement">define</span> <span class="synSpecial">(</span>append-alist-string al<span class="synSpecial">)</span>
<span class="synSpecial">(</span>fold <span class="synSpecial">(</span><span class="synStatement">lambda</span> <span class="synSpecial">(</span>data seed<span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synStatement">if</span> <span class="synSpecial">(</span><span class="synIdentifier">string=?</span> seed <span class="synConstant">&#34;&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>format <span class="synConstant">&#34;~A ~A&#34;</span>
<span class="synSpecial">(</span><span class="synIdentifier">car</span> data<span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synIdentifier">cdr</span> data<span class="synSpecial">))</span>
<span class="synSpecial">(</span>format <span class="synConstant">&#34;~A, ~A ~A&#34;</span>
seed
<span class="synSpecial">(</span><span class="synIdentifier">car</span> data<span class="synSpecial">)</span>
<span class="synSpecial">(</span><span class="synIdentifier">cdr</span> data<span class="synSpecial">))))</span>
<span class="synConstant">&#34;&#34;</span>
al<span class="synSpecial">))</span>
<span class="synSpecial">(</span><span class="synStatement">define</span> <span class="synSpecial">(</span>gen-create-sql table schema<span class="synSpecial">)</span>
<span class="synSpecial">(</span>format <span class="synConstant">&#34;CREATE TABLE ~A (~A);&#34;</span>
table
<span class="synSpecial">(</span>append-alist-string schema<span class="synSpecial">)))</span>
<span class="synSpecial">(</span><span class="synStatement">define</span> <span class="synSpecial">(</span>test-db-select vecl sql<span class="synSpecial">)</span>
<span class="synSpecial">(</span>test* <span class="synSpecial">(</span>format <span class="synConstant">&#34;~s&#34;</span> sql<span class="synSpecial">)</span>
vecl
<span class="synSpecial">(</span><span class="synIdentifier">map</span> identity
<span class="synSpecial">(</span>execute-sql <span class="synConstant">*db-file*</span>
sql<span class="synSpecial">))))</span>
<span class="synComment">;; ==============================</span>
<span class="synComment">;; Tests:</span>
<span class="synComment">;; ==============================</span>
<span class="synSpecial">(</span>test-start <span class="synConstant">&#34;Gauche-dbd-sqlite3&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>test-section <span class="synConstant">&#34;Test Utilities:&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>test* <span class="synConstant">&#34;Key Arrangement Utility:&#34;</span>
<span class="synSpecial">'(</span>date quote source md5<span class="synSpecial">)</span>
<span class="synSpecial">(</span>gen-key-list
<span class="synSpecial">'((</span>date <span class="synConstant">.</span> <span class="synConstant">1334152804</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>quote <span class="synConstant">.</span> <span class="synConstant">&#34;Do not be evil.&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>source <span class="synConstant">.</span> <span class="synConstant">&#34;http://www.google.com/&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>md5 <span class="synConstant">.</span> <span class="synConstant">&#34;ada3ff1732557af042540d34f37ed0cd&#34;</span><span class="synSpecial">))))</span>
<span class="synSpecial">(</span>test* <span class="synConstant">&#34;Value Arrangement Utility:&#34;</span>
<span class="synSpecial">'(</span><span class="synConstant">1334152804</span>
<span class="synConstant">&#34;Do not be evil.&#34;</span>
<span class="synConstant">&#34;http://www.google.com/&#34;</span>
<span class="synConstant">&#34;ada3ff1732557af042540d34f37ed0cd&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>gen-value-list
<span class="synSpecial">'((</span>date <span class="synConstant">.</span> <span class="synConstant">1334152804</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>quote <span class="synConstant">.</span> <span class="synConstant">&#34;Do not be evil.&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>source <span class="synConstant">.</span> <span class="synConstant">&#34;http://www.google.com/&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>md5 <span class="synConstant">.</span> <span class="synConstant">&#34;ada3ff1732557af042540d34f37ed0cd&#34;</span><span class="synSpecial">))))</span>
<span class="synSpecial">(</span>test* <span class="synConstant">&#34;Concatnation Utility (in case of keys):&#34;</span>
<span class="synConstant">&#34;date, quote, source, md5&#34;</span>
<span class="synSpecial">(</span>append-list-string <span class="synSpecial">'(</span>date quote source md5<span class="synSpecial">)))</span>
<span class="synSpecial">(</span>test* <span class="synConstant">&#34;Concatnation Utility (in case of values):&#34;</span>
<span class="synConstant">&#34;1334152804, 'Do not be evil.', 'http://www.google.com/', 'ada3ff1732557af042540d34f37ed0cd'&#34;</span>
<span class="synSpecial">(</span>append-list-string
<span class="synSpecial">'(</span><span class="synConstant">1334152804</span>
<span class="synConstant">&#34;Do not be evil.&#34;</span>
<span class="synConstant">&#34;http://www.google.com/&#34;</span>
<span class="synConstant">&#34;ada3ff1732557af042540d34f37ed0cd&#34;</span><span class="synSpecial">)))</span>
<span class="synSpecial">(</span>test* <span class="synConstant">&#34;Generating Insertion SQL:&#34;</span>
<span class="synConstant">&#34;INSERT INTO quote (date, quote, source, md5) VALUES (1334152804, 'Do not be evil.', 'http://www.google.com/', 'ada3ff1732557af042540d34f37ed0cd');&#34;</span>
<span class="synSpecial">(</span>gen-insert-sql
<span class="synConstant">&#34;quote&#34;</span>
<span class="synSpecial">'((</span>date <span class="synConstant">.</span> <span class="synConstant">1334152804</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>quote <span class="synConstant">.</span> <span class="synConstant">&#34;Do not be evil.&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>source <span class="synConstant">.</span> <span class="synConstant">&#34;http://www.google.com/&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>md5 <span class="synConstant">.</span> <span class="synConstant">&#34;ada3ff1732557af042540d34f37ed0cd&#34;</span><span class="synSpecial">))))</span>
<span class="synSpecial">(</span>test* <span class="synConstant">&#34;Concatnation Utility (in case of CREATE sql)&#34;</span>
<span class="synConstant">&#34;id INTEGER PRIMARY KEY AUTOINCREMENT, date NUMERIC, quote TEXT, source TEXT, md5 TEXT&#34;</span>
<span class="synSpecial">(</span>append-alist-string
<span class="synSpecial">'((</span>id <span class="synConstant">.</span> <span class="synConstant">&#34;INTEGER PRIMARY KEY AUTOINCREMENT&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>date <span class="synConstant">.</span> <span class="synConstant">&#34;NUMERIC&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>quote <span class="synConstant">.</span> <span class="synConstant">&#34;TEXT&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>source <span class="synConstant">.</span> <span class="synConstant">&#34;TEXT&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>md5 <span class="synConstant">.</span> <span class="synConstant">&#34;TEXT&#34;</span><span class="synSpecial">))))</span>
<span class="synSpecial">(</span>test* <span class="synConstant">&#34;Generating Creation SQL:&#34;</span>
<span class="synConstant">&#34;CREATE TABLE quote (id INTEGER PRIMARY KEY AUTOINCREMENT, date NUMERIC, quote TEXT, source TEXT, md5 TEXT);&#34;</span>
<span class="synSpecial">(</span>gen-create-sql
<span class="synConstant">&#34;quote&#34;</span>
<span class="synSpecial">'((</span>id <span class="synConstant">.</span> <span class="synConstant">&#34;INTEGER PRIMARY KEY AUTOINCREMENT&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>date <span class="synConstant">.</span> <span class="synConstant">&#34;NUMERIC&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>quote <span class="synConstant">.</span> <span class="synConstant">&#34;TEXT&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>source <span class="synConstant">.</span> <span class="synConstant">&#34;TEXT&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>md5 <span class="synConstant">.</span> <span class="synConstant">&#34;TEXT&#34;</span><span class="synSpecial">))))</span>
<span class="synSpecial">(</span>test-section <span class="synConstant">&#34;Table Creation:&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>test-db-execute
<span class="synSpecial">(</span>gen-create-sql
<span class="synConstant">&#34;quote&#34;</span>
<span class="synSpecial">'((</span>id <span class="synConstant">.</span> <span class="synConstant">&#34;INTEGER PRIMARY KEY AUTOINCREMENT&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>date <span class="synConstant">.</span> <span class="synConstant">&#34;NUMERIC&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>quote <span class="synConstant">.</span> <span class="synConstant">&#34;TEXT&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>source <span class="synConstant">.</span> <span class="synConstant">&#34;TEXT&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>md5 <span class="synConstant">.</span> <span class="synConstant">&#34;TEXT&#34;</span><span class="synSpecial">))))</span>
<span class="synSpecial">(</span>test-section <span class="synConstant">&#34;Data Insertion:&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>test-db-execute
<span class="synSpecial">(</span>gen-insert-sql
<span class="synConstant">&#34;quote&#34;</span>
<span class="synSpecial">'((</span>date <span class="synConstant">.</span> <span class="synConstant">1334152804</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>quote <span class="synConstant">.</span> <span class="synConstant">&#34;Do not be evil.&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>source <span class="synConstant">.</span> <span class="synConstant">&#34;http://www.google.com/&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>md5 <span class="synConstant">.</span> <span class="synConstant">&#34;ada3ff1732557af042540d34f37ed0cd&#34;</span><span class="synSpecial">))))</span>
<span class="synSpecial">(</span>test-db-execute
<span class="synSpecial">(</span>gen-insert-sql
<span class="synConstant">&#34;quote&#34;</span>
<span class="synSpecial">'((</span>id <span class="synConstant">.</span> <span class="synConstant">2</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>date <span class="synConstant">.</span> <span class="synConstant">1334359203</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>quote <span class="synConstant">.</span> <span class="synConstant">&#34;抑止力とは、「戦う意思を持たない暴力」ではなく、「戦わない意志を持った暴力」のことなのだと思う。小さな違いだけれど、意思を示さない限り、それは「力」たりえない。 (via @medtoolz)&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>source <span class="synConstant">.</span> <span class="synConstant">&#34;http://twitter.com/medtoolz/status/190930863851184129&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>md5 <span class="synConstant">.</span> <span class="synConstant">&#34;6392e235cebdae0ac9c87ee958648fc0&#34;</span><span class="synSpecial">))))</span>
<span class="synSpecial">(</span>test-section <span class="synConstant">&#34;Data Check:&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>test-db-select
<span class="synSpecial">'(</span><span class="synConstant">#</span><span class="synSpecial">(</span><span class="synConstant">1</span>
<span class="synConstant">1334152804</span>
<span class="synConstant">&#34;Do not be evil.&#34;</span>
<span class="synConstant">&#34;http://www.google.com/&#34;</span>
<span class="synConstant">&#34;ada3ff1732557af042540d34f37ed0cd&#34;</span><span class="synSpecial">))</span>
<span class="synConstant">&#34;SELECT * FROM quote WHERE id=1;&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>test-db-select
<span class="synSpecial">'(</span><span class="synConstant">#</span><span class="synSpecial">(</span><span class="synConstant">2</span>
<span class="synConstant">1334359203</span>
<span class="synConstant">&#34;抑止力とは、「戦う意思を持たない暴力」ではなく、「戦わない意志を持った暴力」のことなのだと思う。小さな違いだけれど、意思を示さない限り、それは「力」たりえない。 (via @medtoolz)&#34;</span>
<span class="synConstant">&#34;http://twitter.com/medtoolz/status/190930863851184129&#34;</span>
<span class="synConstant">&#34;6392e235cebdae0ac9c87ee958648fc0&#34;</span><span class="synSpecial">))</span>
<span class="synConstant">&#34;SELECT * FROM quote WHERE id=2;&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>test-db-select
<span class="synSpecial">'(</span><span class="synConstant">#</span><span class="synSpecial">(</span><span class="synConstant">1</span>
<span class="synConstant">1334152804</span>
<span class="synConstant">&#34;Do not be evil.&#34;</span>
<span class="synConstant">&#34;http://www.google.com/&#34;</span>
<span class="synConstant">&#34;ada3ff1732557af042540d34f37ed0cd&#34;</span><span class="synSpecial">)</span>
<span class="synConstant">#</span><span class="synSpecial">(</span><span class="synConstant">2</span>
<span class="synConstant">1334359203</span>
<span class="synConstant">&#34;抑止力とは、「戦う意思を持たない暴力」ではなく、「戦わない意志を持った暴力」のことなのだと思う。小さな違いだけれど、意思を示さない限り、それは「力」たりえない。 (via @medtoolz)&#34;</span>
<span class="synConstant">&#34;http://twitter.com/medtoolz/status/190930863851184129&#34;</span>
<span class="synConstant">&#34;6392e235cebdae0ac9c87ee958648fc0&#34;</span><span class="synSpecial">))</span>
<span class="synConstant">&#34;SELECT * FROM quote;&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>test-section <span class="synConstant">&#34;Database Manipulation:&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>test-db-execute
<span class="synConstant">&#34;UPDATE quote SET date=1000000000 WHERE id=1;&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>test-db-select
<span class="synSpecial">'(</span><span class="synConstant">#</span><span class="synSpecial">(</span><span class="synConstant">1</span>
<span class="synConstant">1000000000</span>
<span class="synConstant">&#34;Do not be evil.&#34;</span>
<span class="synConstant">&#34;http://www.google.com/&#34;</span>
<span class="synConstant">&#34;ada3ff1732557af042540d34f37ed0cd&#34;</span><span class="synSpecial">))</span>
<span class="synConstant">&#34;SELECT * FROM quote WHERE id=1;&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>test-db-execute
<span class="synConstant">&#34;DELETE FROM quote WHERE id=1;&#34;</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>test-db-select
<span class="synSpecial">'(</span><span class="synConstant">#</span><span class="synSpecial">(</span><span class="synConstant">2</span>
<span class="synConstant">1334359203</span>
<span class="synConstant">&#34;抑止力とは、「戦う意思を持たない暴力」ではなく、「戦わない意志を持った暴力」のことなのだと思う。小さな違いだけれど、意思を示さない限り、それは「力」たりえない。 (via @medtoolz)&#34;</span>
<span class="synConstant">&#34;http://twitter.com/medtoolz/status/190930863851184129&#34;</span>
<span class="synConstant">&#34;6392e235cebdae0ac9c87ee958648fc0&#34;</span><span class="synSpecial">))</span>
<span class="synConstant">&#34;SELECT * FROM quote;&#34;</span><span class="synSpecial">)</span>
<span class="synComment">;; ==============================</span>
<span class="synComment">;; Teardown:</span>
<span class="synComment">;; ==============================</span>
<span class="synSpecial">(</span>sys-unlink <span class="synConstant">*db-file*</span><span class="synSpecial">)</span>
<span class="synSpecial">(</span>test-end<span class="synSpecial">)</span>
</pre>
<h4>
実行結果
</h4>
<p>
実行すると、こんな感じになります:
</p>
<pre class="syntax-highlight">
Testing Gauche-dbd-sqlite3 ...
<span class="synStatement">&#60;</span>Test Utilities:<span class="synStatement">&#62;</span>--------------------------------------------------------------
<span class="synStatement">test</span> Key Arrangement Utility:, expects <span class="synStatement">(</span>date quote <span class="synStatement">source</span> md5<span class="synStatement">)</span> <span class="synStatement">==&#62;</span> ok
<span class="synStatement">test</span> Value Arrangement Utility:, expects <span class="synStatement">(</span><span class="synConstant">1334152804</span> <span class="synStatement">&#34;</span><span class="synConstant">Do not be evil.</span><span class="synStatement">&#34;</span> <span class="synStatement">&#34;</span><span class="synConstant">http://www.google.com/</span><span class="synStatement">&#34;</span> <span class="synStatement">&#34;</span><span class="synConstant">ada3ff1732557af042540d34f37ed0cd</span><span class="synStatement">&#34;)</span> <span class="synStatement">==&#62;</span> ok
<span class="synStatement">test</span> Concatnation Utility <span class="synStatement">(</span>in <span class="synStatement">case</span> of keys<span class="synStatement">)</span>:, expects <span class="synStatement">&#34;</span><span class="synConstant">date, quote, source, md5</span><span class="synStatement">&#34;</span> <span class="synStatement">==&#62;</span> ok
<span class="synStatement">test</span> Concatnation Utility <span class="synStatement">(</span>in <span class="synStatement">case</span> of values<span class="synStatement">)</span>:, expects <span class="synStatement">&#34;</span><span class="synConstant">1334152804, 'Do not be evil.', 'http://www.google.com/', 'ada3ff1732557af042540d34f37ed0cd'</span><span class="synStatement">&#34;</span> <span class="synStatement">==&#62;</span> ok
<span class="synStatement">test</span> Generating Insertion SQL:, expects <span class="synStatement">&#34;</span><span class="synConstant">INSERT INTO quote (date, quote, source, md5) VALUES (1334152804, 'Do not be evil.', 'http://www.google.com/', 'ada3ff1732557af042540d34f37ed0cd');</span><span class="synStatement">&#34;</span> <span class="synStatement">==&#62;</span> ok
<span class="synStatement">test</span> Concatnation Utility <span class="synStatement">(</span>in <span class="synStatement">case</span> of CREATE sql<span class="synStatement">)</span>, expects <span class="synStatement">&#34;</span><span class="synConstant">id INTEGER PRIMARY KEY AUTOINCREMENT, date NUMERIC, quote TEXT, source TEXT, md5 TEXT</span><span class="synStatement">&#34;</span> <span class="synStatement">==&#62;</span> ok
<span class="synStatement">test</span> Generating Creation SQL:, expects <span class="synStatement">&#34;</span><span class="synConstant">CREATE TABLE quote (id INTEGER PRIMARY KEY AUTOINCREMENT, date NUMERIC, quote TEXT, source TEXT, md5 TEXT);</span><span class="synStatement">&#34;</span> <span class="synStatement">==&#62;</span> ok
<span class="synStatement">&#60;</span>Table Creation:<span class="synStatement">&#62;</span>--------------------------------------------------------------
<span class="synStatement">test</span> <span class="synStatement">&#34;</span><span class="synConstant">CREATE TABLE quote (id INTEGER PRIMARY KEY AUTOINCREMENT, date NUMERIC, quote TEXT, source TEXT, md5 TEXT);</span><span class="synStatement">&#34;</span>, expects<span class="synComment"> #t ==&#62; ok</span>
<span class="synStatement">&#60;</span>Data Insertion:<span class="synStatement">&#62;</span>--------------------------------------------------------------
<span class="synStatement">test</span> <span class="synStatement">&#34;</span><span class="synConstant">INSERT INTO quote (date, quote, source, md5) VALUES (1334152804, 'Do not be evil.', 'http://www.google.com/', 'ada3ff1732557af042540d34f37ed0cd');</span><span class="synStatement">&#34;</span>, expects<span class="synComment"> #t ==&#62; ok</span>
<span class="synStatement">test</span> <span class="synStatement">&#34;</span><span class="synConstant">INSERT INTO quote (id, date, quote, source, md5) VALUES (2, 1334359203, '</span><span class="synSpecial">抑止力とは、「戦う意思を持たない暴力」ではなく、「戦わない意志を持った暴力」のことなのだと思う。小さな違いだけれど、意思を示さない限り、それは「力」たりえない。</span><span class="synConstant"> (via @medtoolz)', 'http://twitter.com/medtoolz/status/190930863851184129', '6392e235cebdae0ac9c87ee958648fc0');</span><span class="synStatement">&#34;</span>, expects<span class="synComment"> #t ==&#62; ok</span>
<span class="synStatement">&#60;</span>Data Check:<span class="synStatement">&#62;</span>------------------------------------------------------------------
<span class="synStatement">test</span> <span class="synStatement">&#34;</span><span class="synConstant">SELECT * FROM quote WHERE id=1;</span><span class="synStatement">&#34;</span>, expects <span class="synComment">(#(1 1334152804 &#34;Do not be evil.&#34; &#34;http://www.google.com/&#34; &#34;ada3ff1732557af042540d34f37ed0cd&#34;)) ==&#62; ok</span>
<span class="synStatement">test</span> <span class="synStatement">&#34;</span><span class="synConstant">SELECT * FROM quote WHERE id=2;</span><span class="synStatement">&#34;</span>, expects <span class="synComment">(#(2 1334359203 &#34;抑止力とは、「戦う意思を持たない暴力」ではなく、「戦わない意志を持った暴力」のことなのだと思う。小さな違いだけれど、意思を示さない限り、それは「力」たりえない。 (via @medtoolz)&#34; &#34;http://twitter.com/medtoolz/status/190930863851184129&#34; &#34;6392e235cebdae0ac9c87ee958648fc0&#34;)) ==&#62; ok</span>
<span class="synStatement">test</span> <span class="synStatement">&#34;</span><span class="synConstant">SELECT * FROM quote;</span><span class="synStatement">&#34;</span>, expects <span class="synComment">(#(1 1334152804 &#34;Do not be evil.&#34; &#34;http://www.google.com/&#34; &#34;ada3ff1732557af042540d34f37ed0cd&#34;) #(2 1334359203 &#34;抑止力とは、「戦う意思を持たない暴力」ではなく、「戦わない意志を持った暴力」のことなのだと思う。小さな違いだけれど、意思を示さない限り、それは「力」たりえない。 (via @medtoolz)&#34; &#34;http://twitter.com/medtoolz/status/190930863851184129&#34; &#34;6392e235cebdae0ac9c87ee958648fc0&#34;)) ==&#62; ok</span>
<span class="synStatement">&#60;</span>Database Manipulation:<span class="synStatement">&#62;</span>-------------------------------------------------------
<span class="synStatement">test</span> <span class="synStatement">&#34;</span><span class="synConstant">UPDATE quote SET date=1000000000 WHERE id=1;</span><span class="synStatement">&#34;</span>, expects<span class="synComment"> #t ==&#62; ok</span>
<span class="synStatement">test</span> <span class="synStatement">&#34;</span><span class="synConstant">SELECT * FROM quote WHERE id=1;</span><span class="synStatement">&#34;</span>, expects <span class="synComment">(#(1 1000000000 &#34;Do not be evil.&#34; &#34;http://www.google.com/&#34; &#34;ada3ff1732557af042540d34f37ed0cd&#34;)) ==&#62; ok</span>
<span class="synStatement">test</span> <span class="synStatement">&#34;</span><span class="synConstant">DELETE FROM quote WHERE id=1;</span><span class="synStatement">&#34;</span>, expects<span class="synComment"> #t ==&#62; ok</span>
<span class="synStatement">test</span> <span class="synStatement">&#34;</span><span class="synConstant">SELECT * FROM quote;</span><span class="synStatement">&#34;</span>, expects <span class="synComment">(#(2 1334359203 &#34;抑止力とは、「戦う意思を持たない暴力」ではなく、「戦わない意志を持った暴力」のことなのだと思う。小さな違いだけれど、意思を示さない限り、それは「力」たりえない。 (via @medtoolz)&#34; &#34;http://twitter.com/medtoolz/status/190930863851184129&#34; &#34;6392e235cebdae0ac9c87ee958648fc0&#34;)) ==&#62; ok</span>
passed.
</pre>
</div>