SQLiteman のソースコードからのインストール,データベース作成,テーブル定義(Windows 上)

SQLitemanSQLite 3 のデータベースを操作する機能を持ったソフトウェア. Windows 版,Linux 版,Max OS X 版がある.ソースコードも配布されている.

目次

  1. 前準備
  2. SQLiteman のインストール
  3. SQLiteman で SQLite 3 のデータベースの新規作成
  4. テーブル定義を行ってみる

前準備

SQLite 3 のインストール

マイクロソフト C++ ビルドツール (Build Tools) のインストール

Qt 4 のインストール

SQLiteman のインストール

  1. 新しいディレクトリ C:\sqlite3 を作る

    あとで,ここに データベースファイルを置くことにする.

  2. Sqliteman を入手したい.SourceForge のウェブページを開く

    https://sourceforge.net/projects/sqliteman/

  3. Files」をクリック
  4. sqliteman」をクリック
  5. 最新版が欲しいので,「1.2.2」をクリック
  6. ソースコードが欲しいので,sqliteman-1.2.2.tar.gz を選ぶ
  7. ダウンロードが始まる.
  8. ダウンロードしたファイルを展開(解凍)する.
    Windows での展開(解凍)に便利な 7-Zip: 別ページ »で説明
  9. 展開(解凍)してできたファイルを,「C:\sqliteman-1.2.2」のようなディレクトリに移す.

    展開(解凍)してできたファイルを, 分かりやすいディレクトリの下に移したい.

  10. 以下の操作をx64 Native Tools コマンドプロンプト (x64 Native Tools Command Prompt)で実行する   (手順:スタートメニュー →」の下の「x64 Native Tools コマンドプロンプト (x64 Native Tools Command Prompt)」を選ぶ)。
    「x64 Native Tools コマンドプロンプト」がないときは,ビルドツール (Build Tools) をインストールすると,x64 Native Tools コマンドプロンプトもインストールされる.その手順は,別ページ »で説明している.
  11. cmake の実行

    次のコマンドをx64 Native Tools コマンドプロンプト (x64 Native Tools Command Prompt)で実行する

    cd C:\sqliteman-1.2.2
    cmake -G "NMake Makefiles" -DWANT_RESOURCES=1 -DWANT_INTERNAL_QSCINTILLA=1 .
    
  12. cmake の結果の確認

    エラーメッセージが出ていないこと.

  13. nmake の実行

    次のコマンドをx64 Native Tools コマンドプロンプト (x64 Native Tools Command Prompt)で実行する   (手順:スタートメニュー →」の下の「x64 Native Tools コマンドプロンプト (x64 Native Tools Command Prompt)」を選ぶ)。

    nmake
    
  14. nmake の結果の確認

    エラーメッセージが出ていないこと.

  15. Windowsシステム環境変数 Pathに,C:\sqliteman-1.2.2\sqliteman追加することにより,パスを通す

    Windows で,管理者権限コマンドプロンプトを起動(手順:Windowsキーまたはスタートメニュー > cmd と入力 > 右クリック > 「管理者として実行」)。

    次のコマンドを実行

    powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";C:\sqliteman-1.2.2\sqliteman\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
    
  16. sqliteman にパスが通っていることを確認する

    Windowsコマンドプロンプト新しく開き、次のコマンドを実行する.

    where sqliteman
    
  17. 確認のため, Windowsコマンドプロンプトで、次のコマンドを実行する.
    sqliteman
    

SQLite 3 の起動と終了,ヘルプの表示,エンコーディングの確認

使い方の詳しい説明は https://www.sqlite.org/sqlite.html

空のデータベースの新規作成

ここでの設定

  1. SQLite を実行する.

    * パスが通っていないときは,パスを通すか,フルパスで実行する

    sqlite3
    
  2. 空のデータベースを保存したいので次のように操作
    .open --new C:/sqlite3/hoge.db
    .exit
    

テーブル定義

  1. SQLite を実行する.

    * パスが通っていないときは,パスを通すか,フルパスで実行する

    sqliteman
    
  2. データベースオープン
    create table order_records (
        id            integer primary key not null,
        year          integer not null CHECK ( year > 2008 ),
        month         integer not null CHECK ( month >= 1 AND month <= 12 ),
        day           integer not null CHECK ( day >= 1 AND day <= 31 ),
        customer_name text not null,
        product_name  text not null,
        unit_price    real not null check ( unit_price > 0 ),
        qty           integer not null default 1 check ( qty > 0 ),
        created_at    timestamp with time zone not null,
        updated_at    timestamp with time zone,
        check ( ( unit_price * qty ) < 200000 ) );
    

    * テーブル名に日本語を使うとエラーが出る場合がある.

  3. 「.tables」を実行して,テーブルが定義できたことを確認.
    .tables
    
  4. SQL を用いたレコード挿入
    begin transaction;
    insert into order_records (id, year, month, day, customer_name, product_name, unit_price, qty) values( 1, 2023, 7, 26,  'kaneko', 'orange A', 1.2, 10 );
    insert into order_records (id, year, month, day, customer_name, product_name, unit_price, qty) values( 2, 2023, 7, 26,  'miyamoto', 'Apple M',  2.5, 2 );
    insert into order_records (id, year, month, day, customer_name, product_name, unit_price, qty) values( 3, 2023, 7, 27,  'kaneko',   'orange B', 1.2, 8 );
    insert into order_records (id, year, month, day, customer_name, product_name, unit_price) values( 4, 2023, 7, 28,  'miyamoto',   'Apple L', 3 );
    commit;
    
  5. 確認表示
    select * from order_records;
    
  6. psql の終了
    \q