This repository was archived by the owner on Nov 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
Add SqliteConnection.CreateCollation method #340
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
94c8e1d
Add SqliteConnection.CreateCollation method.
AlexanderTaeschner f705fb4
Add CreateCollation<T> method.
AlexanderTaeschner 79d9253
Renamed private method to prevent calling the wrong overload.
AlexanderTaeschner 39d4b3e
Typo correction.
AlexanderTaeschner adf5b4c
Inline CreateSqlite3Collation.
AlexanderTaeschner 4cb1e73
CreateCollation throws when connection is closed.
AlexanderTaeschner 3b58719
Allow null as comparison in CreateCollation.
AlexanderTaeschner 1fea83b
Validate name argument in CreateCollation.
AlexanderTaeschner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,6 +264,27 @@ protected override void Dispose(bool disposing) | |
protected override DbCommand CreateDbCommand() | ||
=> CreateCommand(); | ||
|
||
/// <summary> | ||
/// Create custom collation. | ||
/// </summary> | ||
/// <param name="name">Name of the collation.</param> | ||
/// <param name="comparison">Method that compares two strings.</param> | ||
public virtual void CreateCollation(string name, Comparison<string> comparison) | ||
=> CreateCollation<object>(name, null, (_, s1, s2) => comparison(s1, s2)); | ||
|
||
/// <summary> | ||
/// Create custom collation. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the state object.</typeparam> | ||
/// <param name="name">Name of the collation.</param> | ||
/// <param name="state">State object passed to each invokation of the collation.</param> | ||
/// <param name="comparison">Method that compares two strings, using additional state.</param> | ||
public virtual void CreateCollation<T>(string name, T state, Func<T, string, string, int> comparison) | ||
{ | ||
var rc = raw.sqlite3_create_collation(_db, name, state, (v, s1, s2) => comparison((T)v, s1, s2)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, we'll need to throw if the connection isn't open. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added check and test case. |
||
SqliteException.ThrowExceptionForRC(rc, _db); | ||
} | ||
|
||
/// <summary> | ||
/// Begins a transaction on the connection. | ||
/// </summary> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing a
null
comparison will currently result in aNullReferenceException
. We should either:ArgumentNullException
null
intosqlite3_create_collation
(which removes the collation)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably validate
name
too if the native API gives its "misuse" error fornull
or empty values.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opted for option 2 and added test.