281 lines
33 KiB
Markdown
281 lines
33 KiB
Markdown
|
---
|
||
|
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">"test.db"</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"><dbi-parameter-error></span> e<span class="synSpecial">)</span> <span class="synSpecial">(</span>dbi-close connect<span class="synSpecial">))</span>
|
||
|
<span class="synSpecial">((</span><span class="synConstant"><dbi-error></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">"dbi:sqlite3:"</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">"~s"</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">""</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">"~A"</span><span class="synSpecial">]</span>
|
||
|
<span class="synSpecial">[(</span><span class="synIdentifier">string?</span> data<span class="synSpecial">)</span> <span class="synConstant">"'~A'"</span><span class="synSpecial">]</span>
|
||
|
<span class="synSpecial">[(</span><span class="synIdentifier">symbol?</span> data<span class="synSpecial">)</span> <span class="synConstant">"~A"</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">"~A, ~A"</span><span class="synSpecial">]</span>
|
||
|
<span class="synSpecial">[(</span><span class="synIdentifier">string?</span> data<span class="synSpecial">)</span> <span class="synConstant">"~A, '~A'"</span><span class="synSpecial">]</span>
|
||
|
<span class="synSpecial">[(</span><span class="synIdentifier">symbol?</span> data<span class="synSpecial">)</span> <span class="synConstant">"~A, ~A"</span><span class="synSpecial">])</span>
|
||
|
seed
|
||
|
data<span class="synSpecial">)))</span>
|
||
|
<span class="synConstant">""</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">"INSERT INTO ~A (~A) VALUES (~A);"</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">""</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>format <span class="synConstant">"~A ~A"</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">"~A, ~A ~A"</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">""</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">"CREATE TABLE ~A (~A);"</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">"~s"</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">"Gauche-dbd-sqlite3"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>test-section <span class="synConstant">"Test Utilities:"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>test* <span class="synConstant">"Key Arrangement Utility:"</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">"Do not be evil."</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>source <span class="synConstant">.</span> <span class="synConstant">"http://www.google.com/"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>md5 <span class="synConstant">.</span> <span class="synConstant">"ada3ff1732557af042540d34f37ed0cd"</span><span class="synSpecial">))))</span>
|
||
|
<span class="synSpecial">(</span>test* <span class="synConstant">"Value Arrangement Utility:"</span>
|
||
|
<span class="synSpecial">'(</span><span class="synConstant">1334152804</span>
|
||
|
<span class="synConstant">"Do not be evil."</span>
|
||
|
<span class="synConstant">"http://www.google.com/"</span>
|
||
|
<span class="synConstant">"ada3ff1732557af042540d34f37ed0cd"</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">"Do not be evil."</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>source <span class="synConstant">.</span> <span class="synConstant">"http://www.google.com/"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>md5 <span class="synConstant">.</span> <span class="synConstant">"ada3ff1732557af042540d34f37ed0cd"</span><span class="synSpecial">))))</span>
|
||
|
<span class="synSpecial">(</span>test* <span class="synConstant">"Concatnation Utility (in case of keys):"</span>
|
||
|
<span class="synConstant">"date, quote, source, md5"</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">"Concatnation Utility (in case of values):"</span>
|
||
|
<span class="synConstant">"1334152804, 'Do not be evil.', 'http://www.google.com/', 'ada3ff1732557af042540d34f37ed0cd'"</span>
|
||
|
<span class="synSpecial">(</span>append-list-string
|
||
|
<span class="synSpecial">'(</span><span class="synConstant">1334152804</span>
|
||
|
<span class="synConstant">"Do not be evil."</span>
|
||
|
<span class="synConstant">"http://www.google.com/"</span>
|
||
|
<span class="synConstant">"ada3ff1732557af042540d34f37ed0cd"</span><span class="synSpecial">)))</span>
|
||
|
<span class="synSpecial">(</span>test* <span class="synConstant">"Generating Insertion SQL:"</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="synSpecial">(</span>gen-insert-sql
|
||
|
<span class="synConstant">"quote"</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">"Do not be evil."</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>source <span class="synConstant">.</span> <span class="synConstant">"http://www.google.com/"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>md5 <span class="synConstant">.</span> <span class="synConstant">"ada3ff1732557af042540d34f37ed0cd"</span><span class="synSpecial">))))</span>
|
||
|
<span class="synSpecial">(</span>test* <span class="synConstant">"Concatnation Utility (in case of CREATE sql)"</span>
|
||
|
<span class="synConstant">"id INTEGER PRIMARY KEY AUTOINCREMENT, date NUMERIC, quote TEXT, source TEXT, md5 TEXT"</span>
|
||
|
<span class="synSpecial">(</span>append-alist-string
|
||
|
<span class="synSpecial">'((</span>id <span class="synConstant">.</span> <span class="synConstant">"INTEGER PRIMARY KEY AUTOINCREMENT"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>date <span class="synConstant">.</span> <span class="synConstant">"NUMERIC"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>quote <span class="synConstant">.</span> <span class="synConstant">"TEXT"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>source <span class="synConstant">.</span> <span class="synConstant">"TEXT"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>md5 <span class="synConstant">.</span> <span class="synConstant">"TEXT"</span><span class="synSpecial">))))</span>
|
||
|
<span class="synSpecial">(</span>test* <span class="synConstant">"Generating Creation SQL:"</span>
|
||
|
<span class="synConstant">"CREATE TABLE quote (id INTEGER PRIMARY KEY AUTOINCREMENT, date NUMERIC, quote TEXT, source TEXT, md5 TEXT);"</span>
|
||
|
<span class="synSpecial">(</span>gen-create-sql
|
||
|
<span class="synConstant">"quote"</span>
|
||
|
<span class="synSpecial">'((</span>id <span class="synConstant">.</span> <span class="synConstant">"INTEGER PRIMARY KEY AUTOINCREMENT"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>date <span class="synConstant">.</span> <span class="synConstant">"NUMERIC"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>quote <span class="synConstant">.</span> <span class="synConstant">"TEXT"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>source <span class="synConstant">.</span> <span class="synConstant">"TEXT"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>md5 <span class="synConstant">.</span> <span class="synConstant">"TEXT"</span><span class="synSpecial">))))</span>
|
||
|
<span class="synSpecial">(</span>test-section <span class="synConstant">"Table Creation:"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>test-db-execute
|
||
|
<span class="synSpecial">(</span>gen-create-sql
|
||
|
<span class="synConstant">"quote"</span>
|
||
|
<span class="synSpecial">'((</span>id <span class="synConstant">.</span> <span class="synConstant">"INTEGER PRIMARY KEY AUTOINCREMENT"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>date <span class="synConstant">.</span> <span class="synConstant">"NUMERIC"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>quote <span class="synConstant">.</span> <span class="synConstant">"TEXT"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>source <span class="synConstant">.</span> <span class="synConstant">"TEXT"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>md5 <span class="synConstant">.</span> <span class="synConstant">"TEXT"</span><span class="synSpecial">))))</span>
|
||
|
<span class="synSpecial">(</span>test-section <span class="synConstant">"Data Insertion:"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>test-db-execute
|
||
|
<span class="synSpecial">(</span>gen-insert-sql
|
||
|
<span class="synConstant">"quote"</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">"Do not be evil."</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>source <span class="synConstant">.</span> <span class="synConstant">"http://www.google.com/"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>md5 <span class="synConstant">.</span> <span class="synConstant">"ada3ff1732557af042540d34f37ed0cd"</span><span class="synSpecial">))))</span>
|
||
|
<span class="synSpecial">(</span>test-db-execute
|
||
|
<span class="synSpecial">(</span>gen-insert-sql
|
||
|
<span class="synConstant">"quote"</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">"抑止力とは、「戦う意思を持たない暴力」ではなく、「戦わない意志を持った暴力」のことなのだと思う。小さな違いだけれど、意思を示さない限り、それは「力」たりえない。 (via @medtoolz)"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>source <span class="synConstant">.</span> <span class="synConstant">"http://twitter.com/medtoolz/status/190930863851184129"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>md5 <span class="synConstant">.</span> <span class="synConstant">"6392e235cebdae0ac9c87ee958648fc0"</span><span class="synSpecial">))))</span>
|
||
|
<span class="synSpecial">(</span>test-section <span class="synConstant">"Data Check:"</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">"Do not be evil."</span>
|
||
|
<span class="synConstant">"http://www.google.com/"</span>
|
||
|
<span class="synConstant">"ada3ff1732557af042540d34f37ed0cd"</span><span class="synSpecial">))</span>
|
||
|
<span class="synConstant">"SELECT * FROM quote WHERE id=1;"</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">"抑止力とは、「戦う意思を持たない暴力」ではなく、「戦わない意志を持った暴力」のことなのだと思う。小さな違いだけれど、意思を示さない限り、それは「力」たりえない。 (via @medtoolz)"</span>
|
||
|
<span class="synConstant">"http://twitter.com/medtoolz/status/190930863851184129"</span>
|
||
|
<span class="synConstant">"6392e235cebdae0ac9c87ee958648fc0"</span><span class="synSpecial">))</span>
|
||
|
<span class="synConstant">"SELECT * FROM quote WHERE id=2;"</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">"Do not be evil."</span>
|
||
|
<span class="synConstant">"http://www.google.com/"</span>
|
||
|
<span class="synConstant">"ada3ff1732557af042540d34f37ed0cd"</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">"抑止力とは、「戦う意思を持たない暴力」ではなく、「戦わない意志を持った暴力」のことなのだと思う。小さな違いだけれど、意思を示さない限り、それは「力」たりえない。 (via @medtoolz)"</span>
|
||
|
<span class="synConstant">"http://twitter.com/medtoolz/status/190930863851184129"</span>
|
||
|
<span class="synConstant">"6392e235cebdae0ac9c87ee958648fc0"</span><span class="synSpecial">))</span>
|
||
|
<span class="synConstant">"SELECT * FROM quote;"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>test-section <span class="synConstant">"Database Manipulation:"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>test-db-execute
|
||
|
<span class="synConstant">"UPDATE quote SET date=1000000000 WHERE id=1;"</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">"Do not be evil."</span>
|
||
|
<span class="synConstant">"http://www.google.com/"</span>
|
||
|
<span class="synConstant">"ada3ff1732557af042540d34f37ed0cd"</span><span class="synSpecial">))</span>
|
||
|
<span class="synConstant">"SELECT * FROM quote WHERE id=1;"</span><span class="synSpecial">)</span>
|
||
|
<span class="synSpecial">(</span>test-db-execute
|
||
|
<span class="synConstant">"DELETE FROM quote WHERE id=1;"</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">"抑止力とは、「戦う意思を持たない暴力」ではなく、「戦わない意志を持った暴力」のことなのだと思う。小さな違いだけれど、意思を示さない限り、それは「力」たりえない。 (via @medtoolz)"</span>
|
||
|
<span class="synConstant">"http://twitter.com/medtoolz/status/190930863851184129"</span>
|
||
|
<span class="synConstant">"6392e235cebdae0ac9c87ee958648fc0"</span><span class="synSpecial">))</span>
|
||
|
<span class="synConstant">"SELECT * FROM quote;"</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"><</span>Test Utilities:<span class="synStatement">></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">==></span> ok
|
||
|
<span class="synStatement">test</span> Value Arrangement Utility:, expects <span class="synStatement">(</span><span class="synConstant">1334152804</span> <span class="synStatement">"</span><span class="synConstant">Do not be evil.</span><span class="synStatement">"</span> <span class="synStatement">"</span><span class="synConstant">http://www.google.com/</span><span class="synStatement">"</span> <span class="synStatement">"</span><span class="synConstant">ada3ff1732557af042540d34f37ed0cd</span><span class="synStatement">")</span> <span class="synStatement">==></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">"</span><span class="synConstant">date, quote, source, md5</span><span class="synStatement">"</span> <span class="synStatement">==></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">"</span><span class="synConstant">1334152804, 'Do not be evil.', 'http://www.google.com/', 'ada3ff1732557af042540d34f37ed0cd'</span><span class="synStatement">"</span> <span class="synStatement">==></span> ok
|
||
|
<span class="synStatement">test</span> Generating Insertion SQL:, expects <span class="synStatement">"</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">"</span> <span class="synStatement">==></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">"</span><span class="synConstant">id INTEGER PRIMARY KEY AUTOINCREMENT, date NUMERIC, quote TEXT, source TEXT, md5 TEXT</span><span class="synStatement">"</span> <span class="synStatement">==></span> ok
|
||
|
<span class="synStatement">test</span> Generating Creation SQL:, expects <span class="synStatement">"</span><span class="synConstant">CREATE TABLE quote (id INTEGER PRIMARY KEY AUTOINCREMENT, date NUMERIC, quote TEXT, source TEXT, md5 TEXT);</span><span class="synStatement">"</span> <span class="synStatement">==></span> ok
|
||
|
<span class="synStatement"><</span>Table Creation:<span class="synStatement">></span>--------------------------------------------------------------
|
||
|
<span class="synStatement">test</span> <span class="synStatement">"</span><span class="synConstant">CREATE TABLE quote (id INTEGER PRIMARY KEY AUTOINCREMENT, date NUMERIC, quote TEXT, source TEXT, md5 TEXT);</span><span class="synStatement">"</span>, expects<span class="synComment"> #t ==> ok</span>
|
||
|
<span class="synStatement"><</span>Data Insertion:<span class="synStatement">></span>--------------------------------------------------------------
|
||
|
<span class="synStatement">test</span> <span class="synStatement">"</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">"</span>, expects<span class="synComment"> #t ==> ok</span>
|
||
|
<span class="synStatement">test</span> <span class="synStatement">"</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">"</span>, expects<span class="synComment"> #t ==> ok</span>
|
||
|
<span class="synStatement"><</span>Data Check:<span class="synStatement">></span>------------------------------------------------------------------
|
||
|
<span class="synStatement">test</span> <span class="synStatement">"</span><span class="synConstant">SELECT * FROM quote WHERE id=1;</span><span class="synStatement">"</span>, expects <span class="synComment">(#(1 1334152804 "Do not be evil." "http://www.google.com/" "ada3ff1732557af042540d34f37ed0cd")) ==> ok</span>
|
||
|
<span class="synStatement">test</span> <span class="synStatement">"</span><span class="synConstant">SELECT * FROM quote WHERE id=2;</span><span class="synStatement">"</span>, expects <span class="synComment">(#(2 1334359203 "抑止力とは、「戦う意思を持たない暴力」ではなく、「戦わない意志を持った暴力」のことなのだと思う。小さな違いだけれど、意思を示さない限り、それは「力」たりえない。 (via @medtoolz)" "http://twitter.com/medtoolz/status/190930863851184129" "6392e235cebdae0ac9c87ee958648fc0")) ==> ok</span>
|
||
|
<span class="synStatement">test</span> <span class="synStatement">"</span><span class="synConstant">SELECT * FROM quote;</span><span class="synStatement">"</span>, expects <span class="synComment">(#(1 1334152804 "Do not be evil." "http://www.google.com/" "ada3ff1732557af042540d34f37ed0cd") #(2 1334359203 "抑止力とは、「戦う意思を持たない暴力」ではなく、「戦わない意志を持った暴力」のことなのだと思う。小さな違いだけれど、意思を示さない限り、それは「力」たりえない。 (via @medtoolz)" "http://twitter.com/medtoolz/status/190930863851184129" "6392e235cebdae0ac9c87ee958648fc0")) ==> ok</span>
|
||
|
<span class="synStatement"><</span>Database Manipulation:<span class="synStatement">></span>-------------------------------------------------------
|
||
|
<span class="synStatement">test</span> <span class="synStatement">"</span><span class="synConstant">UPDATE quote SET date=1000000000 WHERE id=1;</span><span class="synStatement">"</span>, expects<span class="synComment"> #t ==> ok</span>
|
||
|
<span class="synStatement">test</span> <span class="synStatement">"</span><span class="synConstant">SELECT * FROM quote WHERE id=1;</span><span class="synStatement">"</span>, expects <span class="synComment">(#(1 1000000000 "Do not be evil." "http://www.google.com/" "ada3ff1732557af042540d34f37ed0cd")) ==> ok</span>
|
||
|
<span class="synStatement">test</span> <span class="synStatement">"</span><span class="synConstant">DELETE FROM quote WHERE id=1;</span><span class="synStatement">"</span>, expects<span class="synComment"> #t ==> ok</span>
|
||
|
<span class="synStatement">test</span> <span class="synStatement">"</span><span class="synConstant">SELECT * FROM quote;</span><span class="synStatement">"</span>, expects <span class="synComment">(#(2 1334359203 "抑止力とは、「戦う意思を持たない暴力」ではなく、「戦わない意志を持った暴力」のことなのだと思う。小さな違いだけれど、意思を示さない限り、それは「力」たりえない。 (via @medtoolz)" "http://twitter.com/medtoolz/status/190930863851184129" "6392e235cebdae0ac9c87ee958648fc0")) ==> ok</span>
|
||
|
passed.
|
||
|
</pre>
|
||
|
</div>
|