Skip to content

Microsoft.Data.Sqlite content improvements #16361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions docs/standard/data/sqlite/TOC.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
- name: Overview
href: index.md
- name: Connection Strings
- name: Connection strings
href: connection-strings.md
- name: Data Types
href: data-types.md
- name: Data types
href: types.md
- name: Parameters
href: parameters.md
- name: Database Errors
displayName: Busy, Locked, Retries, Timeouts
href: errors.md
- name: Database errors
displayName: Busy, locked, retries, timeouts
href: database-errors.md
- name: Transactions
href: transactions.md
- name: Batching
href: batching.md
- name: Metadata
href: metadata.md
- name: SQLite Features
- name: SQLite features
items:
- name: In-Memory Databases
href: memory.md
- name: In-memory databases
href: in-memory-databases.md
- name: Encryption
href: encryption.md
- name: Online Backup
- name: Online backup
href: backup.md
- name: User-Defined Functions
- name: User-defined functions
displayName: UDFs
href: udfs.md
- name: Custom SQLite Versions
href: custom-sqlite.md
href: user-defined-functions.md
- name: Custom SQLite versions
href: custom-versions.md
- name: Collation
href: collation.md
- name: BLOB I/O
- name: Blob I/O
displayName: Streams
href: blob-io.md
- name: Interoperability
Expand All @@ -40,20 +40,20 @@
- name: Limitations
items:
- name: ADO.NET
href: limitations.md
href: adonet-limitations.md
- name: Async
href: async.md
- name: Bulk Insert
- name: Bulk insert
href: bulk-insert.md
- name: Entity Framework Core
href: /ef/core/providers/sqlite/limitations
- name: Dapper
href: dapper.md
href: dapper-limitations.md
- name: System.Data.SQLite
href: compare.md
- name: Xamarin
href: xamarin.md
- name: API Reference
- name: API reference >>
href: /dotnet/api/?view=msdata-sqlite-3.0.0
- name: SQL Syntax
- name: SQL syntax >>
href: https://www.sqlite.org/lang.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
---
title: ADO.NET Limitations
title: ADO.NET limitations
ms.date: 12/13/2019
description: Describes some of the ADO.NET limitations you might encounter.
---
# ADO.NET Limitations
# ADO.NET limitations

Microsoft.Data.Sqlite provides implementations of many of the ADO.NET abstractions, but there are some limitations.

## Database schema information

Metadata about query results is available using [GetSchemaTable](/dotnet/api/microsoft.data.sqlite.sqlitedatareader.getschematable).
Metadata about query results is available using the <xref:Microsoft.Data.Sqlite.SqliteDataReader.GetSchemaTable%2A> method.

`DbConnection.GetSchema()` isn't implemented. This API isn't well-defined, so we recommend retrieving database metadata directly using standard SQLite APIs like the [sqlite_master](https://www.sqlite.org/fileformat.html#storage_of_the_sql_database_schema) table and the [table_info](https://www.sqlite.org/pragma.html#pragma_table_info) PRAGMA.

For more information, see [Metadata](metadata.md).

## System.Transactions

Microsoft.Data.Sqlite doesn't yet support System.Transactions. Use [ADO.NET transactions] instead. For more information, see [Transactions](transactions.md).
Microsoft.Data.Sqlite doesn't yet support System.Transactions. Use ADO.NET transactions instead. For more information, see [Transactions](transactions.md).

Provide feedback about the lack of support for System.Transactions on issue [#13825](https://github.com/aspnet/EntityFrameworkCore/issues/13825).

## Data adapters

DbDataAdapter isn't yet implemented by Microsoft.Data.Sqlite. This means you can only use ADO.NET DataSet and DataTable to load data and not update it.
`DbDataAdapter` isn't yet implemented by Microsoft.Data.Sqlite. This means you can only use ADO.NET `DataSet` and `DataTable` to load data and not update it.

Use issue [#13838](https://github.com/aspnet/EntityFrameworkCore/issues/13838) to provide feedback about implementing DbDataAdapter.
Use issue [#13838](https://github.com/aspnet/EntityFrameworkCore/issues/13838) to provide feedback about implementing `DbDataAdapter`.

## Output parameters

Expand All @@ -45,6 +45,6 @@ The `Chaos` and `Snapshot` isolation levels aren't supported in SQLite transacti

## See also

* [Async Limitations](async.md)
* [Data Types](data-types.md)
* [Async limitations](async.md)
* [Data types](types.md)
* [Transactions](transactions.md)
4 changes: 2 additions & 2 deletions docs/standard/data/sqlite/async.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: Async Limitations
title: Async limitations
ms.date: 12/13/2019
description: Explains the limitations of the async APIs and some alternatives that you can use instead.
---
# Async Limitations
# Async limitations

SQLite doesn't support asynchronous I/O. Async ADO.NET methods will execute synchronously in Microsoft.Data.Sqlite. Avoid calling them.

Expand Down
8 changes: 4 additions & 4 deletions docs/standard/data/sqlite/backup.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: Online Backup
title: Online backup
ms.date: 12/13/2019
description: Learn how to use SQLite's online backup feature.
---
# Online Backup
# Online backup

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.
SQLite can back up database files while the app is running. This functionality is available in Microsoft.Data.Sqlite as the <xref:Microsoft.Data.Sqlite.SqliteConnection.BackupDatabase%2A> method on `SqliteConnection`.

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

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.
Currently, `BackupDatabase` will back up the database as quickly as possible and blocks 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 and allow other connections to interrupt the backup and write to the database. If you're interested, provide feedback on the issue.
4 changes: 2 additions & 2 deletions docs/standard/data/sqlite/batching.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ description: Learn how to execute a batch of SQL statements in a single command.
---
# Batching

SQLite doesn't natively support batching SQL statements together into a single command. But because there's no network involved, it wouldn't really help performance anyway. Microsoft.Data.Sqlite does however implements statement batching as a convenience to make it behave more like other ADO.NET providers.
SQLite doesn't natively support batching SQL statements together into a single command. But because there's no network involved, it wouldn't really help performance anyway. Microsoft.Data.Sqlite does, however, implement statement batching as a convenience to make it behave more like other ADO.NET providers.

When calling DbCommand.ExecuteReader(), statements are executed up to the first one that returns results. Calling DbDataReader.NextResult() continues executing statements until the next one that returns results or until it reaches the end of the batch. Calling DbDataReader.Dispose() or Close() will execute any remaining statements that haven't been consumed by NextResult(). If you don't dispose a data reader, the finalizer will try to execute the remaining statements, but any errors it encounters will be ignored. Because of this, it's very important to dispose DbDataReader objects when using batches.
When calling <xref:System.Data.Common.DbCommand.ExecuteReader%2A?displayProperty=nameWithType>, statements are executed up to the first one that returns results. Calling <xref:System.Data.Common.DbDataReader.NextResult%2A?displayProperty=nameWithType> continues executing statements until the next one that returns results or until it reaches the end of the batch. Calling <xref:System.Data.Common.DbDataReader.Dispose%2A?displayProperty=nameWithType> or <xref:System.Data.Common.DbDataReader.Close%2A> executes any remaining statements that haven't been consumed by `NextResult()`. If you don't dispose a data reader, the finalizer tries to execute the remaining statements, but any errors it encounters are ignored. Because of this, it's important to dispose `DbDataReader` objects when using batches.

[!code-csharp[](../../../../samples/snippets/standard/data/sqlite/BatchingSample/Program.cs?name=snippet_Batching)]

Expand Down
10 changes: 5 additions & 5 deletions docs/standard/data/sqlite/blob-io.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
title: BLOB I/O
title: Blob I/O
ms.date: 12/13/2019
description: Learn how to use SQLite's BLOB I/O feature.
---
# BLOB I/O
# Blob I/O

You can reduce memory usage while reading and writing large objects by streaming the data into and out of the database. This can be especially useful when parsing or transforming the data.

Start by inserting a row as normal. Use the zeroblob() SQL function to allocate space in the database to hold the large object. The last_insert_rowid() function provides a convenient way to get its rowid.
Start by inserting a row as normal. Use the `zeroblob()` SQL function to allocate space in the database to hold the large object. The `last_insert_rowid()` function provides a convenient way to get its rowid.

[!code-csharp[](../../../../samples/snippets/standard/data/sqlite/StreamingSample/Program.cs?name=snippet_Insert)]

After inserting the row, open a stream to write the large object using [SqliteBlob](/dotnet/api/microsoft.data.sqlite.sqliteblob).
After inserting the row, open a stream to write the large object using <xref:Microsoft.Data.Sqlite.SqliteBlob>.

[!code-csharp[](../../../../samples/snippets/standard/data/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. The object returned by GetStream() will be a SqliteBlob when done correctly.
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/snippets/standard/data/sqlite/StreamingSample/Program.cs?name=snippet_Read)]
12 changes: 6 additions & 6 deletions docs/standard/data/sqlite/bulk-insert.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
title: Bulk Insert
title: Bulk insert
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a very short article @bricelam. I'd consider moving this into another article.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of people ask how to do bulk insert. This is just a page for them to find saying you don’t have to do anything special on SQLite.

I think if we add a bit more context of what bulk insert is on other databases, how it speeds things up and why it doesn’t apply to SQLite it would be a better article. Also maybe it could use some more details on how these two steps help speed things up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But maybe it can also merge into the ADO.NET limitations

ms.date: 12/13/2019
description: Performance tips you can use when making a lot of changes to the database.
description: Performance tips you can use when making numerous changes to the database.
---
# Bulk Insert
# Bulk insert

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.
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. Reuse the same parameterized command. Subsequent executions will reuse the compilation of the first one.
- Use a transaction.
- Reuse the same parameterized command. Subsequent executions will reuse the compilation of the first one.

[!code-csharp[](../../../../samples/snippets/standard/data/sqlite/BulkInsertSample/Program.cs?name=snippet_BulkInsert)]
10 changes: 5 additions & 5 deletions docs/standard/data/sqlite/collation.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ Collating sequences are used by SQLite when comparing TEXT values to determine o

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

## Custom collation

You can also define your own collating sequences or override the built-in ones using [CreateCollation()](/dotnet/api/microsoft.data.sqlite.sqliteconnection.createcollation). The following example shows overriding the NOCASE collation to support Unicode characters. The [full sample code](https://github.com/dotnet/samples/blob/master/samples/snippets/standard/data/sqlite/CollationSample/Program.cs) is available on GitHub.
You can also define your own collating sequences or override the built-in ones using <xref:Microsoft.Data.Sqlite.SqliteConnection.CreateCollation%2A>. The following example shows overriding the NOCASE collation to support Unicode characters. The [full sample code](https://github.com/dotnet/samples/blob/master/samples/snippets/standard/data/sqlite/CollationSample/Program.cs) is available on GitHub.

[!code-csharp[](../../../../samples/snippets/standard/data/sqlite/CollationSample/Program.cs?name=snippet_Collation)]

## Like operator

The LIKE operator in SQLite doesn't honor collations. The default implementation has the same semantics as the NOCASE collation. It's only case-insensitive for the ASCII characters A through Z.

You can easily make the LIKE operator case-sensitive by using the following pragma statement.
You can easily make the LIKE operator case-sensitive by using the following pragma statement:

```sql
PRAGMA case_sensitive_like = 0
```

See [User-Defined Functions](udfs.md) for details on overriding the implementation of the LIKE operator.
See [User-defined functions](user-defined-functions.md) for details on overriding the implementation of the LIKE operator.

## See also

* [User-Defined Functions](udfs.md)
* [User-defined functions](user-defined-functions.md)
* [SQL Syntax](https://www.sqlite.org/lang.html)
18 changes: 9 additions & 9 deletions docs/standard/data/sqlite/compare.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The first version of .NET Core (released in 2016) was a single, lightweight, mod

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.
As an example of what we mean by more modern, here is code to create a [user-defined function](user-defined-functions.md) in both System.Data.SQLite and Microsoft.Data.Sqlite.

```csharp
// System.Data.SQLite
Expand All @@ -26,15 +26,15 @@ connection.CreateFunction(
(double arg) => Math.Ceiling(arg));
```

In 2017, .NET Core 2.0 experienced a change in strategy. It was decided that compatibility with .NET Framework was vital to the success of .NET Core. Many of the removed APIs, including the DataSet APIs, were added back. Like it did for many others, this unblocked System.Data.SQLite allowing it to also be ported to .NET Core. The original goal of Microsoft.Data.Sqlite to be lightweight and modern, however, still remains. See [ADO.NET Limitations](limitations.md) for details about ADO.NET APIs not implemented by Microsoft.Data.Sqlite.
In 2017, .NET Core 2.0 experienced a change in strategy. It was decided that compatibility with .NET Framework was vital to the success of .NET Core. Many of the removed APIs, including the DataSet APIs, were added back. Like it did for many others, this unblocked System.Data.SQLite allowing it to also be ported to .NET Core. The original goal of Microsoft.Data.Sqlite to be lightweight and modern, however, still remains. See [ADO.NET limitations](adonet-limitations.md) for details about ADO.NET APIs not implemented by Microsoft.Data.Sqlite.

When new features are added to Microsoft.Data.Sqlite, the design of System.Data.SQLite is taken into account. We try to, when possible, minimize changes between the two to ease transitioning between them.
When new features are added to Microsoft.Data.Sqlite, the design of System.Data.SQLite is taken into account. We try, when possible, to minimize changes between the two to ease transitioning between them.

## 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 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.
The biggest difference between Microsoft.Data.Sqlite and System.Data.SQLite is how data types are handled. As described in [Data types](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 introduce 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 Expand Up @@ -69,8 +69,8 @@ Microsoft.Data.Sqlite doesn't have any API for creating virtual table modules. U

## See also

* [Data Types](data-types.md)
* [Connection Strings](connection-strings.md)
* [Data types](types.md)
* [Connection strings](connection-strings.md)
* [Encryption](encryption.md)
* [ADO.NET Limitations](limitations.md)
* [Dapper Limitations](dapper.md)
* [ADO.NET limitations](adonet-limitations.md)
* [Dapper limitations](dapper-limitations.md)
Loading