Skip to content

Commit 29df553

Browse files
committed
Document manual SQL
Working on #783
1 parent 7135fbd commit 29df553

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,20 @@ var count = await db.ExecuteScalarAsync<int>("select count(*) from Stock");
187187
Console.WriteLine(string.Format("Found '{0}' stock items.", count));
188188
```
189189

190+
## Manual SQL
191+
192+
**sqlite-net** is normally used as a light ORM with the methods `CreateTable` and `Table`. However, you can use it as just a convenient
193+
way to execute explicit queries.
194+
195+
Here is an example of create a table, inserting into it, and
196+
querying it without using the ORM.
197+
198+
```csharp
199+
db.Execute ("create table Stock(Symbol varchar(100) not null)");
200+
db.Execute ("insert into Stock(Symbol) values (?)", "MSFT");
201+
var stocks = db.Query<Stock> ("select * from Stock");
202+
```
203+
190204
## Using SQLCipher
191205

192206
You can use an encrypted database by using the [sqlite-net-sqlcipher NuGet package](https://www.nuget.org/packages/sqlite-net-sqlcipher).

tests/ReadmeTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,18 @@ public void Cipher ()
141141
postKeyAction: db => db.Execute ("PRAGMA kdf_iter = 128000;"));
142142
var encryptedDb2 = new SQLiteAsyncConnection (options2);
143143
}
144+
145+
[Test]
146+
public void Manual()
147+
{
148+
var db = new SQLiteConnection (":memory:");
149+
150+
db.Execute ("create table Stock(Symbol varchar(100) not null)");
151+
db.Execute ("insert into Stock(Symbol) values (?)", "MSFT");
152+
var stocks = db.Query<Stock> ("select * from Stock");
153+
154+
Assert.AreEqual (1, stocks.Count);
155+
Assert.AreEqual ("MSFT", stocks[0].Symbol);
156+
}
144157
}
145158
}

0 commit comments

Comments
 (0)