sqlite プラグイン
この拡張は二年以上更新されていません。もはや維持管理や対応がされておらず、互換性に問題がある可能性があります。
この拡張機能は 'plugin' または 'template' 名前空間にないため、無視されます。
必要とされるプラグイン addressbook, aichat, approve, bez, blogtng, combo, data, data-au, datagraph, dataloop, datatemplate, davcal, davcard, do, dwcommits, extendpage, ireadit, issuelinks, judge, labeled, notification, questionnaire, randomtables, rating, sql2wiki, starred, struct, structnotification, structnumber, structtasks, swarmwebhook, tagging, telleveryone, timetrack, top, watchcycle, webdavclient
必要条件
このプラグインには、PHP 環境の SQLite 対応が必要です。 SQLite バージョン2 データベースをアクセス・作成するための sqlite 拡張、 または、SQLite バージョン3 データベースをアクセス・作成するための pdo-sqlite 拡張にて動作します。 両方の拡張が稼働する場合、pdo-sqlite を使用します。
アップグレード時の重要情報: このプラグインの旧バージョンは sqlite2 のみ対応していました。両方の拡張が導入されている場合、プラグインは sqlite3 対応となり、データベースを新形式に変換する必要があります。以下の手順で実施してください:
- 管理者メニューに行く。
- “SQLite Access” を選択する。
- sqlite2 data base を選択する。
- “convert format” ボタンを選択する。
ダウンロードとインストール
変更履歴
- Merge pull request #92 from dokuwiki-translate/lang_update_939_172526… (2024-09-03 11:03)
- translation update (2024-09-02 09:40)
- Version upped (2024-06-25 23:51)
- Admin Interface: preserve whitespace in results (2024-06-25 19:54)
- Version upped (2024-03-05 23:51)
- Merge pull request #88 from cosmocode/bot/autofix (2024-03-05 08:57)
- 🤖 Automatic code style fixes (2024-03-05 08:40)
- Merge pull request #90 from dokuwiki-translate/lang_update_832_170962… (2024-03-05 08:39)
管理者メニュー
プラグインには簡単な管理メニューが付属しています。 使用可能なデータベースに対して、独自のSQLクエリを実行できます。
目次の中に利用可能なデータベース(data/meta/*.sqlite
and data/meta/*.sqlite3
)が表示されます。
データベースを選択し、自分のクエリを実行することができます。
開発者向け情報
自分のプラグインの中でこのヘルパープラグインを使用するには、このプラグインを読み込み、データベースに接続するために init() 関数を呼び出します。 自分のコードを実行する前に、プラグインが正しく読み込まれたか、init() 関数がエラーなく実行されたかを確認してください。
// ヘルパープラグインの読み込み $sqlite = plugin_load('helper', 'sqlite'); if(!$sqlite){ msg('This plugin requires the sqlite plugin. Please install it'); return; } // データベース接続の初期化 if(!$sqlite->init('myplugin',DOKU_PLUGIN.'myplugin/db/')){ return; } // プラグインの利用 $res = $sqlite->query("SELECT * FROM mytable"); $arr = $sqlite->res2arr($res); print_r($arr);
関数
init
データベースを初期化し開きます。 ヘルパープラグインの読み込み後、正しく呼び出す必要があります。
- $dbname はデータベース名です。
- $updatedir 更新SQLファイルが置かれている場所(下記参照)のパスです。
$plugin->init($dbname,$updatedir);
query
与えられたパラメータでクエリを実行します。
エスケープ処理に注意が必要です。
- $sql - SQL 文
- arguments…
- 引数は配列として与えることもできる
$plugin->query($sql[,arg1[,arg2[...]]]);
res2arr
配列として、完全な結果を返します。
- $res - クエリ結果
$plugin->res2arr($res){
res2row
結果の中から、連想配列として要求された行を返します。
- $res - クエリ結果
- $numrow - 結果の個数
$plugin->res2row($res,$rownum=0){
quote and join
Join the given values and quote them for SQL insertion
- $vals - values to join
- $sep - separator char
$plugin->quote_and_join($vals,$sep=',');
quote string
Run sqlite_escape_string on the given string and surround it with quotes
$plugin->quote_string($string);
DBスキーマの設定/更新機能
プラグインは、データベーススキーマを作成し、なんらかの初期データでスキーマをを埋める必要があります。 プラグインの新バージョンをリリースする際に、スキーマも更新する必要があるかもしれません。 sqliteプラグインは、これを行う単純な機能を提供します。
この機能は、全て init()
関数内で処理されます。
二番目のパラメータは、SQLファイルを設置したディレクトリを指しています。
各ファイルは特定のデータベースのバージョンに対応しています。
バージョン1は、データベース作成時に実行される最初の設定です。
後続の各バージョンは、前のバージョンの上に適用されます。
最新バージョンの数は latest.version
という名のファイルに格納されます。
更新ファイルは updateXXXX.sql
と命名されます。
XXXX は 0001
から始まる前0の4桁の数字です。
更新機能がトランザクション内に各更新実行を埋め込むので、自分で実施する必要はありません。 更新が失敗した場合、トランザクションはロールバックされ更新は中止されます。
sqliteプラグインは、現状 opt
という名のテーブルを利用して、データベースのバージョンを追跡します。
You may not have a table named like that!
SQL 拡張
プラグインは、標準の SQLite 構文を超えたいくつかの追加機能を提供します。
ALTER TABLE
プラグインは、簡略化された ALTER TABLE
構文に対応しています。
これは更新機能の中で最も有用です。
The plugin supports a simplified ALTER TABLE
syntax. This is probably most useful in the update mechanism. The plugin emulates the alter table call by copying the affected data to a temporary table and dropping, recreating and refilling the original table. When used outside the update mechanism, it is recommended to wrap the call in a transaction.
ALTER TABLE tbl_name alter_specification [, alter_specification] ... alter_specification: ADD column_definition | DROP column_definition | CHANGE old_col_name column_definition column_definition: same as for create table statements
Examples:
ALTER TABLE employees ADD first_name, ADD last_name ALTER TABLE invoices ADD note text, CHANGE idate invoice_date DATETIME ALTER TABLE foo DROP bar, ADD bar2 INTEGER
GROUP_CONCAT
GROUP_CONCAT 関数は、MySQLで定義された同じ関数のコピーです。
add more info.
バグ、機能要望、パッチ
バグと機能要望はissue tracker に提出してください。 パッチは diff ユニファイド形式かgitパッチで送ってください。 github 上でフォークし、merge resuest を送ってくれるとなお良いです。