====== SQLiteでテーブルを作成する ====== [[:powershell|一つ上へ]] Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing # sqlite3.dll を読み込む Add-Type -Path "path\to\dll\System.Data.SQLite.dll" # DBのファイルパス(無ければ新規作成) $dbFile = "path\to\database\database.db" $connStr = "Data Source=$dbFile;Version=3;" # SQLite 接続オブジェクトを作成 $conn = New-Object System.Data.SQLite.SQLiteConnection($connStr) $conn.Open() if (-not (Test-Path $dbFile)) { [System.Data.SQLite.SQLiteConnection]::CreateFile($dbFile) } # コマンドオブジェクト $cmd = $conn.CreateCommand() # 初期化処理 # テーブルが無ければ作成する $cmd.CommandText = @" CREATE TABLE IF NOT EXISTS tablename ( date TEXT NOT NULL, col1 TEXT, col2 TEXT ); "@ $cmd.ExecuteNonQuery() $conn.Close()