Skip to content

Commit

Permalink
fixup! WIP: Document Microsoft.Data.Sqlite
Browse files Browse the repository at this point in the history
Fix acrolinx errors
  • Loading branch information
bricelam committed Dec 9, 2019
1 parent b7f7b9f commit 2b63e23
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 50 deletions.
4 changes: 2 additions & 2 deletions msdata-sqlite/backup.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ ms.date: 11/22/2019
---
# Online Backup

SQLite can backup database files while the app is running. This functionality is available in Microsoft.Data.Sqlite as the [BackupDatabase](/dotnet/api/microsoft.data.sqlite.sqliteconnection.backupdatabase) method on SqliteConnection.
SQLite can back up database files while the app is running. This functionality is available in Microsoft.Data.Sqlite as the [BackupDatabase](/dotnet/api/microsoft.data.sqlite.sqliteconnection.backupdatabase) method on SqliteConnection.

[!code-csharp[](../samples/msdata-sqlite/BackupSample/Program.cs?name=snippet_Backup)]

Currently, BackupDatabase will backup the database as quickly as possible blocking other connections from writing to the database. Issue [#13834](https://github.com/aspnet/EntityFrameworkCore/issues/13834) would provide an alternative API to backup the database in the background allowing other connections to interrupt the backup and write to the database. If you're interested in this, please provide feedback on the issue.
Currently, BackupDatabase will back up the database as quickly as possible blocking other connections from writing to the database. Issue [#13834](https://github.com/aspnet/EntityFrameworkCore/issues/13834) would provide an alternative API to back up the database in the background allowing other connections to interrupt the backup and write to the database. If you're interested, please provide feedback on the issue.
2 changes: 1 addition & 1 deletion msdata-sqlite/blob-io.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ After inserting the row, open a stream to write the large object using [SqliteBl

[!code-csharp[](../samples/msdata-sqlite/StreamingSample/Program.cs?name=snippet_Write)]

To stream the large object out of the database, you must select the rowid or one of its aliases as show here in addition to the large object's column. If you don't select the rowid, the entire object will be loaded into memory. If done correctly, the object returned by GetStream() will be a SqliteBlob.
To stream the large object out of the database, you must select the rowid or one of its aliases as show here in addition to the large object's column. If you don't select the rowid, the entire object will be loaded into memory. The object returned by GetStream() will be a SqliteBlob when done correctly.

[!code-csharp[](../samples/msdata-sqlite/StreamingSample/Program.cs?name=snippet_Read)]
2 changes: 1 addition & 1 deletion msdata-sqlite/bulk-insert.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ ms.date: 11/22/2019
SQLite doesn't have any special way to bulk insert data. To get optimal performance when inserting or updating data, ensure that you do the following.

1. Use a transaction.
2. Re-use the same parameterized command. Subsequent executions will reuse the compilation of the first one.
2. Reuse the same parameterized command. Subsequent executions will reuse the compilation of the first one.

[!code-csharp[](../samples/msdata-sqlite/BulkInsertSample/Program.cs?name=snippet_BulkInsert)]
2 changes: 1 addition & 1 deletion msdata-sqlite/collation.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Collating sequences are used by SQLite when comparing TEXT values to determine o

| Collation | Description |
| --------- | ----------------------------------------- |
| RTRIM | Ignores trailing white-space |
| RTRIM | Ignores trailing whitespace |
| NOCASE | Case-insensitive for ASCII characters A-Z |
| BINARY | Case-sensitive. Compares bytes directly |

Expand Down
8 changes: 4 additions & 4 deletions msdata-sqlite/compare.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ ms.date: 12/09/2019

In 2005, Robert Simpson created System.Data.SQLite, a SQLite provider for ADO.NET 2.0. In 2010, the SQLite team took over maintenance and development of the project. It's also worth noting that the Mono team forked the code in 2007 as Mono.Data.Sqlite. System.Data.SQLite has a long history and has evolved into a stable and full-featured ADO.NET provider complete with Visual Studio tooling. New releases continue to ship assemblies compatible with every version of .NET Framework back to version 2.0 and even .NET Compact Framework 3.5.

The first version of .NET Core (released in 2016) was a single, lightweight, modern, and cross-platform implementation of .NET. Obsolete APIs and APIs with more modern alternatives were intentionally removed. ADO.NET did not include any of the DataSet APIs (including DataTable and DataAdapter).
The first version of .NET Core (released in 2016) was a single, lightweight, modern, and cross-platform implementation of .NET. Obsolete APIs and APIs with more modern alternatives were intentionally removed. ADO.NET didn't include any of the DataSet APIs (including DataTable and DataAdapter).

The Entity Framework team was somewhat familiar with the System.Data.SQLite codebase. Brice Lambson, a member of the EF team, had previously helped the SQLite team add support for Entity Framework versions 5 and 6. Brice was also experimenting with his own implementation of a SQLite ADO.NET provider around the same time .NET Core was being planned. After a long discussion, the Entity Framework team decided to create Microsoft.Data.Sqlite based on Brice's prototype. This would allow them to create a new lightweight and modern implementation that would align with the goals of .NET Core.
The Entity Framework team was somewhat familiar with the System.Data.SQLite codebase. Brice Lambson, a member of the EF team, had previously helped the SQLite team add support for Entity Framework versions 5 and 6. Brice was also experimenting with his own implementation of a SQLite ADO.NET provider around the same time that .NET Core was being planned. After a long discussion, the Entity Framework team decided to create Microsoft.Data.Sqlite based on Brice's prototype. This would allow them to create a new lightweight and modern implementation that would align with the goals of .NET Core.

As an example of what we mean by more modern, here is code to create a [user-defined function](udfs.md) in both System.Data.SQLite and Microsoft.Data.Sqlite.

Expand All @@ -32,9 +32,9 @@ When new features are added to Microsoft.Data.Sqlite, the design of System.Data.

## Data types

The biggest difference between Microsoft.Data.Sqlite and System.Data.SQLite is how data types are handled. As described in [Data Types](data-types.md), Microsoft.Data.Sqlite does not try to hide the underlying quirkiness of SQLite which allows any arbitrary string to be specified as the column type, and only has four primitive types: INTEGER, REAL, TEXT, and BLOB.
The biggest difference between Microsoft.Data.Sqlite and System.Data.SQLite is how data types are handled. As described in [Data Types](data-types.md), Microsoft.Data.Sqlite doesn't try to hide the underlying quirkiness of SQLite, which allows any arbitrary string to be specified as the column type, and only has four primitive types: INTEGER, REAL, TEXT, and BLOB.

System.Data.SQLite applies additional semantics to column types mapping them directly to .NET types. This gives the provider a more strongly-typed feel, but it has some rough edges. For example, they had to introduced a new SQL statement (TYPES) to specify the column types of expressions in SELECT statements.
System.Data.SQLite applies additional semantics to column types mapping them directly to .NET types. This gives the provider a more strongly-typed feel, but it has some rough edges. For example, they had to introduce a new SQL statement (TYPES) to specify the column types of expressions in SELECT statements.

## Connection strings

Expand Down
4 changes: 2 additions & 2 deletions msdata-sqlite/connection-strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SQLite treats paths relative to the current working directory. Absolute paths ca

If **empty**, SQLite creates a temporary on-disk database that gets deleted when the connection is closed.

If `:memory:`, an in-memory database is used. See [In-Memory Databases](memory.md) for more details.
If `:memory:`, an in-memory database is used. For more information, see [In-Memory Databases](memory.md).

Paths that start with the `|DataDirectory|` substitution string are treated the same as relative paths. If set, paths are made relative to the DataDirectory application domain property value.

Expand Down Expand Up @@ -65,7 +65,7 @@ A value indicating whether to enable foreign key constraints.
| False | Sends `PRAGMA foreign_keys = 0` immediately after opening the connection.
| (empty) | Doesn't send `PRAGMA foreign_keys`. This is the default. |

There is no need enable foreign keys if, like in e_sqlite3, SQLITE_DEFAULT_FOREIGN_KEYS was used to compile the native
There's no need enable foreign keys if, like in e_sqlite3, SQLITE_DEFAULT_FOREIGN_KEYS was used to compile the native
SQLite library.

### Recursive Triggers
Expand Down
10 changes: 5 additions & 5 deletions msdata-sqlite/custom-sqlite.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ Microsoft.Data.Sqlite is built on top of SQLitePCL.raw. You can use custom versi

## Bundles

SQLitePCL.raw provides bundle packages which make it easy to bring in the right dependencies across different platforms.
SQLitePCL.raw provides bundle packages that make it easy to bring in the right dependencies across different platforms.

The main Microsoft.Data.Sqlite package brings in SQLitePCLRaw.bundle_e_sqlite3 by default.

To use a different bundle, install the `Microsoft.Data.Sqlite.Core` package along with the the bundle package you want to use. Bundles are automatically initialized by Microsoft.Data.Sqlite.
To use a different bundle, install the `Microsoft.Data.Sqlite.Core` package along with the bundle package you want to use. Bundles are automatically initialized by Microsoft.Data.Sqlite.

Bundle | Description
--- | ---
SQLitePCLRaw.bundle_e_sqlite3 | Provides a consistent version of SQLite on all platforms. Includes the FTS4, FTS5, JSON1, and R*Tree extensions. This is the default
SQLitePCLRaw.bundle_green | Same as bundle_e_sqlite3, except on iOS where it uses the system SQLite library
SQLitePCLRaw.bundle_zetetic | Uses the official SQLCipher builds from Zetetic (not included)
SQLitePCLRaw.bundle_winsqlite3 | Uses winsqlite3.dll, the system SQLite library on Windows 10
SQLitePCLRaw.bundle_e_sqlcipher | Provides an unofficial, open source build of SQLCipher
SQLitePCLRaw.bundle_e_sqlcipher | Provides an unofficial, open-source build of SQLCipher

For example, to use the unofficial, open source build of SQLCipher use the following commands.
For example, to use the unofficial, open-source build of SQLCipher use the following commands.

### [.NET Core CLI](#tab/netcore-cli)

Expand All @@ -43,7 +43,7 @@ Install-Package SQLitePCLRaw.bundle_e_sqlcipher

## SQLitePCL.raw Providers

You can use your own build of SQLite by leveraging the `SQLitePCLRaw.provider.dynamic_cdecl` package. In this case, you are responsible for deploying the native library with your app.
You can use your own build of SQLite by leveraging the `SQLitePCLRaw.provider.dynamic_cdecl` package. In this case, you're responsible for deploying the native library with your app.

First, you'll need to implement IGetFunctionPointer. The implementation is fairly trivial on .NET Core.

Expand Down
2 changes: 1 addition & 1 deletion msdata-sqlite/dapper.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Dapper also expects parameters to use the `@` prefix. Other prefixes won't work.

## Data types

Dapper reads values using the SqliteDataReader indexer. The return type of this indexer is object which means it will only ever return long, double, string, or byte[] values. See [Data Types](data-types.md) for more details. Dapper handles most conversions between these and other primitive types. Unfortunately, it doesn't handle `DateTimeOffset`, `Guid`, or `TimeSpan`. You need to create type handlers if you want to use these in your results.
Dapper reads values using the SqliteDataReader indexer. The return type of this indexer is object, which means it will only ever return long, double, string, or byte[] values. For more information, see [Data Types](data-types.md). Dapper handles most conversions between these and other primitive types. Unfortunately, it doesn't handle `DateTimeOffset`, `Guid`, or `TimeSpan`. Create type handlers if you want to use these types in your results.

[!code-csharp[](../samples/msdata-sqlite/DapperSample/Program.cs?name=snippet_TypeHandlers)]

Expand Down
6 changes: 3 additions & 3 deletions msdata-sqlite/data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ UInt64 | INTEGER | Large values overflow

## Alternative types

Some .NET types can be read from alternative SQLite types. Parameters can also be configured to use these alternative types. See [Parameters](parameters.md#alternative-types) for more details.
Some .NET types can be read from alternative SQLite types. Parameters can also be configured to use these alternative types. For more information, see [Parameters](parameters.md#alternative-types).

.NET | SQLite | Remarks
--- | --- | ---
Expand All @@ -46,9 +46,9 @@ For example, the following query reads a TimeSpan value from a REAL column in th

## Column types

SQLite uses a dynamic type system where the type of a value is associated with the value itself and not the column where it's stored. You are free to use whatever column type name you want. Microsoft.Data.Sqlite will not apply any additional semantics to these names.
SQLite uses a dynamic type system where the type of a value is associated with the value itself and not the column where it's stored. You're free to use whatever column type name you want. Microsoft.Data.Sqlite won't apply any additional semantics to these names.

The column type name does have an impact on the [type affinity <span class="docon docon-navigate-external" aria-hidden="true" />](https://www.sqlite.org/datatype3.html#type_affinity). One common gotcha is that using a column type of STRING will try to convert values to INTEGER or REAL which can lead to unexpected results. We recommend only using the four primitive SQLite type names: INTEGER, REAL, TEXT, and BLOB.
The column type name does have an impact on the [type affinity <span class="docon docon-navigate-external" aria-hidden="true" />](https://www.sqlite.org/datatype3.html#type_affinity). One common gotcha is that using a column type of STRING will try to convert values to INTEGER or REAL, which can lead to unexpected results. We recommend only using the four primitive SQLite type names: INTEGER, REAL, TEXT, and BLOB.

SQLite allows you to specify type facets like length, precision, and scale, but they are not enforced by the database engine. Your app is responsible for enforcing these.

Expand Down
4 changes: 2 additions & 2 deletions msdata-sqlite/encryption.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ms.date: 11/25/2019
---
# Encryption

SQLite doesn't support encrypting database files by default. Instead, you need to use a modified version of SQLite like [SEE](https://www.hwaci.com/sw/sqlite/see.html), [SQLCipher](https://www.zetetic.net/sqlcipher/), [SQLiteCrypt](http://www.sqlite-crypt.com/), or [wxSQLite3](https://utelle.github.io/wxsqlite3). This article demonstrates using an unsupported, open source build of SQLCipher, but the information also applies to other solutions since they generally follow the same pattern.
SQLite doesn't support encrypting database files by default. Instead, you need to use a modified version of SQLite like [SEE](https://www.hwaci.com/sw/sqlite/see.html), [SQLCipher](https://www.zetetic.net/sqlcipher/), [SQLiteCrypt](http://www.sqlite-crypt.com/), or [wxSQLite3](https://utelle.github.io/wxsqlite3). This article demonstrates using an unsupported, open-source build of SQLCipher, but the information also applies to other solutions since they generally follow the same pattern.

## Installation

Expand All @@ -27,7 +27,7 @@ Install-Package SQLitePCLRaw.bundle_e_sqlcipher

---

If you are using a different native library for encryption, see [Custom SQLite Versions](custom-sqlite.md) for more information.
For more information about using a different native library for encryption, see [Custom SQLite Versions](custom-sqlite.md).

## Specifying the key

Expand Down
6 changes: 3 additions & 3 deletions msdata-sqlite/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ Consider carefully how your app will handle these errors.

## Locking, retries, and timeouts

SQLite is very aggressive when it comes to locking tables and database files. If your app enables any concurrent database access, you will likely encounter busy and locked errors. You can mitigate a lot of these by using a [shared cache](connection-strings.md#cache) and [write-ahead logging](async.md).
SQLite is aggressive when it comes to locking tables and database files. If your app enables any concurrent database access, you'll likely encounter busy and locked errors. You can mitigate many errors by using a [shared cache](connection-strings.md#cache) and [write-ahead logging](async.md).

Whenever Microsoft.Data.Sqlite encounters a busy or locked error, it will automatically retry until is succeeds or the command timeout is reached.
Whenever Microsoft.Data.Sqlite encounters a busy or locked error, it will automatically retry until it succeeds or the command timeout is reached.

You can increase the timeout of command by setting [CommandTimeout](/dotnet/api/microsoft.data.sqlite.sqlitecommand.commandtimeout). The default timeout is 30 seconds. A value of `0` means no timeout.

Expand All @@ -29,7 +29,7 @@ You can increase the timeout of command by setting [CommandTimeout](/dotnet/api/
command.CommandTimeout = 60;
```

Sometimes, Microsoft.Data.Sqlite needs to create an implicit command object. For example, during BeginTransaction. To set the timeout for these commands, use [DefaultTimeout](/dotnet/api/microsoft.data.sqlite.sqliteconnection.defaulttimeout).
Microsoft.Data.Sqlite sometimes needs to create an implicit command object. For example, during BeginTransaction. To set the timeout for these commands, use [DefaultTimeout](/dotnet/api/microsoft.data.sqlite.sqliteconnection.defaulttimeout).

```csharp
// Set the default timeout of all commands on this connection
Expand Down
4 changes: 2 additions & 2 deletions msdata-sqlite/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ ms.date: 11/28/2019

SQLite supports loading extensions at runtime. Extensions include things like additional SQL functions, collations, virtual tables, and more.

.NET Core includes additional logic for locating native libraries in additional places like referenced NuGet packages. Unfortunately, SQLite cannot leverage this logic; it calls the platform API directly to load libraries. Because of this, your app may need to modify the PATH, LD_LIBRARY_PATH, or DYLD_LIBRARY_PATH environment variables before loading SQLite extensions. There is [a sample](https://github.com/aspnet/EntityFramework.Docs/blob/master/samples/msdata-sqlite/ExtensionsSample/Program.cs) on GitHub that demonstrates finding binaries for the current runtime inside a referenced NuGet package.
.NET Core includes additional logic for locating native libraries in additional places like referenced NuGet packages. Unfortunately, SQLite can't leverage this logic; it calls the platform API directly to load libraries. Because of this, your app may need to modify the PATH, LD_LIBRARY_PATH, or DYLD_LIBRARY_PATH environment variables before loading SQLite extensions. There's [a sample](https://github.com/aspnet/EntityFramework.Docs/blob/master/samples/msdata-sqlite/ExtensionsSample/Program.cs) on GitHub that demonstrates finding binaries for the current runtime inside a referenced NuGet package.

To load an extension, call [LoadExtension](/dotnet/api/microsoft.data.sqlite.sqliteconnection.loadextension). Microsoft.Data.Sqlite will ensure that the extension remains loaded even if the connection is closed and re-opened.
To load an extension, call [LoadExtension](/dotnet/api/microsoft.data.sqlite.sqliteconnection.loadextension). Microsoft.Data.Sqlite will ensure that the extension remains loaded even if the connection is closed and reopened.

[!code-csharp[](../samples/msdata-sqlite/ExtensionsSample/Program.cs?name=snippet_LoadExtension)]

Expand Down
2 changes: 1 addition & 1 deletion msdata-sqlite/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Install-Package Microsoft.Data.Sqlite

## Usage

This library implements the common ADO.NET abstractions for connections, commands, data readers, etc.
This library implements the common ADO.NET abstractions for connections, commands, data readers, and so on.

[!code-csharp[](../samples/msdata-sqlite/HelloWorldSample/Program.cs?name=snippet_HelloWorld)]

Expand Down
Loading

0 comments on commit 2b63e23

Please sign in to comment.