PowerShell example
Creating a simple table …
add-type -path '.\System.Data.SQLite.dll'
$sqlite = new-object -typeName System.Data.SQLite.SQLiteConnection
$sqlite.ConnectionString = "Data Source=""$pwd\test.db"""
$sqlite.Open()
$sql = $sqlite.CreateCommand()
$sql.CommandText = 'create table tab (col_1, col_2, col_3)'
$null = $sql.ExecuteNonQuery()
$sql.Dispose()
$sqlite.Close()
… then inserting some values …
$sqlite = new-object -typeName System.Data.SQLite.SQLiteConnection
$sqlite.ConnectionString = "Data Source=""$pwd\test.db"""
$sqlite.Open()
$cmd = $sqlite.CreateCommand()
$cmd.CommandText = "INSERT INTO tab (col_1, col_2, col_3) values(@A, @B, @C)";
$null = $cmd.Parameters.AddWithValue("@A", 42);
$null = $cmd.Parameters.AddWithValue("@B", 'Hello');
$null = $cmd.Parameters.AddWithValue("@C", 'World');
$null = $cmd.ExecuteNonQuery()
$null = $cmd.Parameters.AddWithValue("@A", 99);
$null = $cmd.Parameters.AddWithValue("@B", 'ninty');
$null = $cmd.Parameters.AddWithValue("@C", 'nine');
$null = $cmd.ExecuteNonQuery()
$cmd.Dispose()
$SQLite.Close()
… and finally selecting these values again.
add-type -path '.\System.Data.SQLite.dll'
$sqlite = new-object -typeName System.Data.SQLite.SQLiteConnection
$sqlite.ConnectionString = "Data Source=""$pwd\test.db"""
$sqlite.Open()
$sql = $sqlite.CreateCommand()
$sql.CommandText = 'select * from tab'
$adapter = New-Object -TypeName System.Data.SQLite.SQLiteDataAdapter $sql
$data = New-Object System.Data.DataSet
$null = $adapter.Fill($data)
foreach ($datarow in $data.Tables.rows) {
write-host "$($datarow.col_1) $($datarow.col_2) $($datarow.col_3)"
}
$sql.Dispose()
$SQLite.Close()