トップ «前の日記(2013-02-11) 最新 次の日記(2013-03-20)» 編集

Cocoa練習帳

iOS/iPhone/iPad/watchOS/tvOS/MacOSX/Android プログラミング, Objective-C, Cocoa, Swiftなど

2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|09|10|11|12|
2024|01|02|03|

2013-02-19 [Web]INTER-MediatorとSQLite

使えるデータベースはSQLiteのみのサイトをINTER-Mediatorで構築してみる。

ツールとして、Coda2とDiet Codaを使ってみたのだが、iPad miniでPHPが編集できるなんて、素晴らしい世の中になったものだ。

SQLiteのデータベースファイルは、事前に生成した物をサイトにアップする事にしたので、スキーム・ファイルの設計が必要だ。

CREATE TABLE person	(
	id					INTEGER PRIMARY KEY AUTOINCREMENT,
	membership_number	TEXT,
	name				TEXT
);
CREATE UNIQUE INDEX person_id ON person (id);
 
INSERT INTO person(id,membership_number,name) VALUES (1,'012345','Yukio Murakami');
INSERT INTO person(id,membership_number,name) VALUES (2,'000002','Someone');
INSERT INTO person(id,membership_number,name) VALUES (3,'000003','Anyone');
 
CREATE TABLE attendance	(
	id					INTEGER PRIMARY KEY AUTOINCREMENT,
	person_id			INTEGER,
	class_name			TEXT,
	date				DATE
);
CREATE UNIQUE INDEX attendance_id ON attendance (id);
CREATE INDEX attendance_person_id ON attendance (person_id);
 
INSERT INTO attendance (person_id,class_name,date) VALUES (1,'General','2013-1-6');
INSERT INTO attendance (person_id,class_name,date) VALUES (1,'General','2013-1-11');
INSERT INTO attendance (person_id,class_name,date) VALUES (1,'Special','2013-1-12');

スキーム・ファイルの名前は、rollbook_schema_sqlite.txtとした。
次は、データベースファイルを生成。

$ mkdir db
$ mkdir db/im
$ sudo sqlite3 -init rollbook_schema_sqlite.txt db/im/rollbook.sq3
	:
sqlite> .quit
$ sudo chown _www db/im
$ sudo chown _www db/im/rollbook.sq3

定義ファイルは以下のとおり。

< 1,
            'paging' => true,
            'name' => 'person',
            'key' => 'id',
            'query' => array( /* array( 'field'=>'id', 'value'=>'5', 'operator'=>'eq' ),*/),
            'sort' => array(array('field' => 'id', 'direction' => 'asc'),),
            'repeat-control' => 'insert delete',
        ),
        array(
            'name' => 'attendance',
            'key' => 'id',
            'relation' => array(
                array('foreign-key' => 'person_id', 'join-field' => 'id', 'operator' => '=')
            ),
            'repeat-control' => 'insert delete',
        ),
    ),
    array(
        'formatter' => array(),
        'aliases' => array(
            'attendanceid' => 'attendance@person_id@value',
            'attendancename' => 'attendance@name_person@innerHTML',
        ),
    ),
    array(
        'db-class' => 'PDO',
        'dsn' => 'sqlite:/それぞれの環境のパスを記述/db/im/rollbook.sq3',
    ),
    0
);
 
?>

実は、第二引数のaliasesに何を指定したらいいのか分かっていない。nullを指定すると上手く動かなかったので、サンプルを見よう見まねで真似た。

ページファイルは以下のとおり。

<!DOCTYPE html>
<!--
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
    <link rel="stylesheet" type="text/css" href="rollbook.css"/>
    <title>出欠簿</title>
    <script src="include.php"></script>
    <script type="text/javascript">
        window.onload = function() {
            var nodeUnsupport = document.getElementById('nonsupportmessage');
            if (INTERMediatorOnPage.INTERMediatorCheckBrowser(nodeUnsupport)) {
                INTERMediator.construct(true);
            }
        }
    </script>
</head>
<body>
<div id="nonsupportmessage" style="background-color:#333333">
    <div style="text-align:center;color:yellow">
        If you see this, you must use any unsupported web browser.
        Or you should set to active for JavaScript.
        In case of generating the page, Please wait a while.
    </div>
    <div style="text-align:center;color:yellow">
        この表示が見えている場合、非対応ブラウザで参照されています。
        あるいは、JavaScriptを使用しないように設定されています。
        描画処理中の場合はしばらくお待ちください。
    </div>
</div>
<div id="IM_NAVIGATOR">Navigation Controls by INTER-Mediator</div>
<table border="1">
    <tbody>
    <tr>
        <th>id</th>
        <td>
            <div class="IM[person@id]"></div>
        </td>
    </tr>
    <tr>
        <th>membership#</th>
        <td>
            <input type="text" class="IM[person@membership_number]" value=""/>
        </td>
    </tr>
    <tr>
        <th>name</th>
        <td>
            <input type="text" class="IM[person@name]" value=""/>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <table border="1">
                <thead>
                <tr>
                    <th>class_name</th>
                    <th>date</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td><input type="text" class="IM[attendance@class_name]"/></td>
                    <td><input type="text" class="IM[attendance@date]"/></td>
                </tr>
                </tbody>
            </table>
        </td>
    </tr>
    </tbody>
</table>
<!--<button onclick="INTERMediator.saveRecordFromNavi()">Save</button>-->
</body>
</html>

上手く動いているようだ。

Web

今回、サイト側の作業はCoda2を使ったのだが、便利だね!

Coda

_ 関連情報

INTER-Mediator

_ 【Cocoa練習帳】

http://www.bitz.co.jp/weblog/
http://ameblo.jp/bitz/(ミラー・サイト)

トップ «前の日記(2013-02-11) 最新 次の日記(2013-03-20)» 編集