2021-06-24 09:43:57 -06:00
|
|
|
using System;
|
2019-12-12 12:55:17 +01:00
|
|
|
using System.Collections.Generic;
|
2018-06-29 19:52:40 +02:00
|
|
|
using System.Data;
|
|
|
|
|
using System.Data.Common;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2020-09-16 13:08:27 +02:00
|
|
|
using Microsoft.Extensions.Logging;
|
2018-06-29 19:52:40 +02:00
|
|
|
using NPoco;
|
|
|
|
|
using StackExchange.Profiling;
|
2021-02-12 12:40:08 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.Migrations.Install;
|
2021-02-12 13:36:50 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.Persistence.FaultHandling;
|
|
|
|
|
using Umbraco.Extensions;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2021-02-12 13:36:50 +01:00
|
|
|
namespace Umbraco.Cms.Infrastructure.Persistence
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2020-07-06 16:25:15 +10:00
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Extends NPoco Database for Umbraco.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// <para>Is used everywhere in place of the original NPoco Database object, and provides additional features
|
|
|
|
|
/// such as profiling, retry policies, logging, etc.</para>
|
|
|
|
|
/// <para>Is never created directly but obtained from the <see cref="UmbracoDatabaseFactory"/>.</para>
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public class UmbracoDatabase : Database, IUmbracoDatabase
|
|
|
|
|
{
|
2020-09-16 13:08:27 +02:00
|
|
|
private readonly ILogger<UmbracoDatabase> _logger;
|
2022-02-24 09:24:56 +01:00
|
|
|
private readonly IBulkSqlInsertProvider? _bulkSqlInsertProvider;
|
|
|
|
|
private readonly DatabaseSchemaCreatorFactory? _databaseSchemaCreatorFactory;
|
2022-02-22 13:35:32 +01:00
|
|
|
private readonly IEnumerable<IMapper>? _mapperCollection;
|
2018-06-29 19:52:40 +02:00
|
|
|
private readonly Guid _instanceGuid = Guid.NewGuid();
|
2022-02-24 09:24:56 +01:00
|
|
|
private List<CommandInfo>? _commands;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
|
|
|
#region Ctor
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="UmbracoDatabase"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// <para>Used by UmbracoDatabaseFactory to create databases.</para>
|
|
|
|
|
/// <para>Also used by DatabaseBuilder for creating databases and installing/upgrading.</para>
|
|
|
|
|
/// </remarks>
|
2021-06-24 09:43:57 -06:00
|
|
|
public UmbracoDatabase(
|
|
|
|
|
string connectionString,
|
|
|
|
|
ISqlContext sqlContext,
|
|
|
|
|
DbProviderFactory provider,
|
|
|
|
|
ILogger<UmbracoDatabase> logger,
|
2022-02-24 09:24:56 +01:00
|
|
|
IBulkSqlInsertProvider? bulkSqlInsertProvider,
|
2021-06-24 09:43:57 -06:00
|
|
|
DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory,
|
2022-02-22 13:35:32 +01:00
|
|
|
IEnumerable<IMapper>? mapperCollection = null)
|
2019-10-15 00:04:41 +11:00
|
|
|
: base(connectionString, sqlContext.DatabaseType, provider, sqlContext.SqlSyntax.DefaultIsolationLevel)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
|
|
|
|
SqlContext = sqlContext;
|
|
|
|
|
_logger = logger;
|
2019-12-12 12:55:17 +01:00
|
|
|
_bulkSqlInsertProvider = bulkSqlInsertProvider;
|
2021-01-18 15:40:22 +01:00
|
|
|
_databaseSchemaCreatorFactory = databaseSchemaCreatorFactory;
|
2021-07-05 08:24:44 +02:00
|
|
|
_mapperCollection = mapperCollection;
|
2021-09-17 12:52:23 +02:00
|
|
|
|
2021-06-24 09:43:57 -06:00
|
|
|
Init();
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="UmbracoDatabase"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>Internal for unit tests only.</remarks>
|
2021-06-24 09:43:57 -06:00
|
|
|
internal UmbracoDatabase(
|
|
|
|
|
DbConnection connection,
|
|
|
|
|
ISqlContext sqlContext,
|
|
|
|
|
ILogger<UmbracoDatabase> logger,
|
|
|
|
|
IBulkSqlInsertProvider bulkSqlInsertProvider)
|
2019-10-15 00:04:41 +11:00
|
|
|
: base(connection, sqlContext.DatabaseType, sqlContext.SqlSyntax.DefaultIsolationLevel)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
|
|
|
|
SqlContext = sqlContext;
|
|
|
|
|
_logger = logger;
|
2019-12-12 12:55:17 +01:00
|
|
|
_bulkSqlInsertProvider = bulkSqlInsertProvider;
|
2021-09-17 12:52:23 +02:00
|
|
|
|
2021-06-24 09:43:57 -06:00
|
|
|
Init();
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2021-06-24 09:43:57 -06:00
|
|
|
private void Init()
|
|
|
|
|
{
|
2018-06-29 19:52:40 +02:00
|
|
|
EnableSqlTrace = EnableSqlTraceDefault;
|
2019-11-20 12:15:27 +11:00
|
|
|
NPocoDatabaseExtensions.ConfigureNPocoBulkExtensions();
|
2021-09-17 12:52:23 +02:00
|
|
|
|
2021-07-05 08:24:44 +02:00
|
|
|
if (_mapperCollection != null)
|
|
|
|
|
{
|
|
|
|
|
Mappers.AddRange(_mapperCollection);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ISqlContext SqlContext { get; }
|
|
|
|
|
|
|
|
|
|
#region Testing, Debugging and Troubleshooting
|
|
|
|
|
|
|
|
|
|
private bool _enableCount;
|
|
|
|
|
|
|
|
|
|
#if DEBUG_DATABASES
|
|
|
|
|
private int _spid = -1;
|
|
|
|
|
private const bool EnableSqlTraceDefault = true;
|
|
|
|
|
#else
|
2022-02-24 09:24:56 +01:00
|
|
|
private string? _instanceId;
|
2018-06-29 19:52:40 +02:00
|
|
|
private const bool EnableSqlTraceDefault = false;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2021-09-17 12:52:23 +02:00
|
|
|
public string InstanceId =>
|
2018-06-29 19:52:40 +02:00
|
|
|
#if DEBUG_DATABASES
|
2021-09-17 12:52:23 +02:00
|
|
|
_instanceGuid.ToString("N").Substring(0, 8) + ':' + _spid;
|
2018-06-29 19:52:40 +02:00
|
|
|
#else
|
2021-09-17 12:52:23 +02:00
|
|
|
_instanceId ??= _instanceGuid.ToString("N").Substring(0, 8);
|
2018-06-29 19:52:40 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public bool InTransaction { get; private set; }
|
|
|
|
|
|
|
|
|
|
protected override void OnBeginTransaction()
|
|
|
|
|
{
|
|
|
|
|
base.OnBeginTransaction();
|
|
|
|
|
InTransaction = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnAbortTransaction()
|
|
|
|
|
{
|
|
|
|
|
InTransaction = false;
|
|
|
|
|
base.OnAbortTransaction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnCompleteTransaction()
|
|
|
|
|
{
|
|
|
|
|
InTransaction = false;
|
|
|
|
|
base.OnCompleteTransaction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets a value indicating whether to log all executed Sql statements.
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal bool EnableSqlTrace { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets a value indicating whether to count all executed Sql statements.
|
|
|
|
|
/// </summary>
|
2019-12-12 12:55:17 +01:00
|
|
|
public bool EnableSqlCount
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
|
|
|
|
get => _enableCount;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_enableCount = value;
|
2021-09-17 12:52:23 +02:00
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
if (_enableCount == false)
|
2021-09-17 12:52:23 +02:00
|
|
|
{
|
2018-06-29 19:52:40 +02:00
|
|
|
SqlCount = 0;
|
2021-09-17 12:52:23 +02:00
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the count of all executed Sql statements.
|
|
|
|
|
/// </summary>
|
2019-12-12 12:55:17 +01:00
|
|
|
public int SqlCount { get; private set; }
|
|
|
|
|
|
2020-03-30 17:25:29 +11:00
|
|
|
internal bool LogCommands
|
|
|
|
|
{
|
|
|
|
|
get => _commands != null;
|
|
|
|
|
set => _commands = value ? new List<CommandInfo>() : null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-24 09:24:56 +01:00
|
|
|
internal IEnumerable<CommandInfo>? Commands => _commands;
|
2020-03-30 17:25:29 +11:00
|
|
|
|
2022-02-24 09:24:56 +01:00
|
|
|
public int BulkInsertRecords<T>(IEnumerable<T> records) => _bulkSqlInsertProvider?.BulkInsertRecords(this, records) ?? 0;
|
2019-12-12 12:55:17 +01:00
|
|
|
|
2021-01-18 15:40:22 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the <see cref="DatabaseSchemaResult"/> for the database
|
|
|
|
|
/// </summary>
|
|
|
|
|
public DatabaseSchemaResult ValidateSchema()
|
|
|
|
|
{
|
2022-02-24 09:24:56 +01:00
|
|
|
var dbSchema = _databaseSchemaCreatorFactory?.Create(this);
|
|
|
|
|
var databaseSchemaValidationResult = dbSchema?.ValidateSchema();
|
2021-09-17 12:52:23 +02:00
|
|
|
|
2022-02-24 09:24:56 +01:00
|
|
|
return databaseSchemaValidationResult ?? new DatabaseSchemaResult();
|
2021-01-18 15:40:22 +01:00
|
|
|
}
|
2019-12-12 12:55:17 +01:00
|
|
|
|
2021-01-18 15:40:22 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Returns true if Umbraco database tables are detected to be installed
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsUmbracoInstalled() => ValidateSchema().DetermineHasInstalledVersion();
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region OnSomething
|
|
|
|
|
|
|
|
|
|
protected override DbConnection OnConnectionOpened(DbConnection connection)
|
|
|
|
|
{
|
v10 SQLite support + distributed locking abstractions (#11922)
* Created Persistence.SQLite project skeleton.
* SQLite database initialization
* Various changes and hacks to make things work.
* WIP integration tests
* Fix thread safety tests
* Fix tests that relied on tie breaker sorting.
Spent a fair amount of time looking for a less lazy fix but gave up.
* Convert right join to left join ContentTypeRepository.PerformGetByQuery
SQLite doesn't support right join
* Fix test Can_Generate_Delete_SubQuery_Statement
Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override
EscapeSqlIdentifier so NPoco will escape with [].
SQLite docs say > "A keyword enclosed in square brackets is an identifier.
This is not standard SQL.
This quoting mechanism is used by MS Access and SQL Server and is
included in SQLite for compatibility."
Also could have updated SqliteSyntaxProvider to match npoco but
decided against it.
* Fixes for paginated custom order by
* Fix tests broken by lack of unique indexes.
* Fix SqlServerTableByTableTest tests.
These tests didn't actually do anything as the tables already exist so schema creator just returned.
Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation.
* Fix ValidateLoginSession - SelectTop must come later
* dry up database cleanup
* Fix up db migration tests.
We can't drop pk in sqlite without recreating table.
Test looks to be testing that add column works as intended which we can test.
* Prevent schema creation errors.
* SQLite ignore lock tests, WAL back on.
* Fix package schema tests
* Fix NPocoFetchTests - case sensitivity not under test
* Fix AdvancedMigrationTests (where possible)
Migrations probably need a good look later.
Maybe nuke old migrations and only support moving to v10 from v9.
If we do that can do some cleanup.
* Cleanup test database configuration
* Run integration tests against SQLite on build agent.
* Drop MS.Data.SQLite
System.Data.SQLite was quicker to roll out due to more CLR type mapping
* YAML
* Skip Umbraco.Tests.Integration.SqlCe
* Drop SqlServerTableByTable tests.
Until this week they did nothing anyway as they with NewSchemaPerTest
so the tests all passed as CreateTable was no op (already exists).
Also all of the tables are created in an empty database by SchemaValidationTest.cs
DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors
* Might aswell run against macOS also.
* Copy azure pipelines task header layout
* Delete SQLCe projects
* Remove SQL CE specific code.
* Remove SQL CE NuSpec, template params, build script setup
* Delete umbraco-netcore-only.sln
* Add SkipTests solution configuration and use for codeql
* Remove reference to deleted nuspec file.
* Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName.
At this point you can try out SQLite support by setting the following
in appsettings.json and then completing the install process.
"ConnectionStrings": {
"umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite",
"umbracoDbDSN_ProviderName": "System.Data.SQLite"
},
Not currently possible via installer UI without provider name pre-set in
configuration.
* Switch to Microsoft.Data.Sqlite
Some gross hacks but will be good to find out if this works
with apple silicon.
* Enable selection of SQLite via installer UI (also quick install)
* Remove SqlServerDbProviderFactoryCreator to cleanup a TODO
* Move SQL Server support to its own class library
* Add persistence dependencies to Umbraco.CMS metapackage
* Bugfix packages delete query
Created invalid query for SQLite.
* Try out cypress tests Linux + SQLite
* Prevent cypress test artifact upload failure on attempt 2+
* LocalDb bugfixes
* Drop redundant enum
* Move SqlClient constant
* Misc whitespace
* Remove IsSqlCe extension (TODO: drop non 9->10 migrations later).
* Umbraco.Persistence.* -> Umbraco.Cms.Persistence.*
* Display quick install defaults and per provider default database name.
* Misc remove old comment
* little re-arrange
* Remove almost all usages of IsSqlite extension.
* visual adjustments
* Custom Database Configuration is last step and should then say Install.
* use text instead of disabled inputs
* move legend, rename to Install
* Update SqlMainDomLock to work without distributed locks.
* Added IDistributedLockingMechanism interface and in memory impl.
* Drop locking from ISqlSyntaxProvider & wire up scope to abstraction.
* Added SqlServerDistributedLockingMechanism
* Move distributed locking interfaces and exceptions to Core + xmldocs.
* Fix tests, Misc cleanup, Add SQL distributed locking integration tests
* Provide mechanism to specify DistributedLockingMechanism in config
(even if added by composer)
* Nomplementation -> NoImplementation
* Fix misleading comment
* Integration tests use SqlServerDistributedLockingMechanism when possible
* Handle up-gradable locks SqlServerDistributedLockingMechanism.
TODO: InMemoryDistributedLockingMechanism.
Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep
at night.
Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests
* Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky.
* Tweak constraints on WithCollectionBuilder so i can drop bad constructor
* Added SqliteDistributedLockingMechanism
* Dropped InMemoryDistributedMechanism + magic
InMemoryDistributedMechanism was pretty rubbish and now we have
a decent implementation for SQLite as we no longer block readers
see 8d1f42b.
Also drop the CollectionBuilder setup, instead do the same as we do
for syntax providers etc, it's more automagical so we never require an
explicit selection although we are allowing for it.
However keeping the optional IUmbracoBuilder constructor param for
CollectionBuilders as it's extremely useful.
* Fix quick install "" database name.
* Hide Database Configuration section when a connection string is pre-set.
Doesn't seem worth it to extract db name from connection string.
* Ensure wal test 2+
* Fix logging inconsistencies.
* Ensure in transaction when obtaining locks + no-op the SQLite read lock.
There's no point in running the query just to make a single test pass.
* Fix installer database display names
* Allow SQLite shared cache without losing deferred transactions
* Opt into shared cache for new SQLite databases + fix filename
* Fix misc inconsistency in .gitignore
* Prefer our interceptor interface
* Restore DEBUG_DATABASES code OnConnectionOpened in case it's used.
* Back to private cache.
* Added retry strategy for SQLite + refactor out SQL server specific stuff
* Fix SQL server tests.
* Misc - Orphaned comment, incorrect casing.
* InMemory SQLite test database & turn shared cache back on everywhere.
Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
|
|
|
if (connection == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(connection));
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
v10 SQLite support + distributed locking abstractions (#11922)
* Created Persistence.SQLite project skeleton.
* SQLite database initialization
* Various changes and hacks to make things work.
* WIP integration tests
* Fix thread safety tests
* Fix tests that relied on tie breaker sorting.
Spent a fair amount of time looking for a less lazy fix but gave up.
* Convert right join to left join ContentTypeRepository.PerformGetByQuery
SQLite doesn't support right join
* Fix test Can_Generate_Delete_SubQuery_Statement
Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override
EscapeSqlIdentifier so NPoco will escape with [].
SQLite docs say > "A keyword enclosed in square brackets is an identifier.
This is not standard SQL.
This quoting mechanism is used by MS Access and SQL Server and is
included in SQLite for compatibility."
Also could have updated SqliteSyntaxProvider to match npoco but
decided against it.
* Fixes for paginated custom order by
* Fix tests broken by lack of unique indexes.
* Fix SqlServerTableByTableTest tests.
These tests didn't actually do anything as the tables already exist so schema creator just returned.
Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation.
* Fix ValidateLoginSession - SelectTop must come later
* dry up database cleanup
* Fix up db migration tests.
We can't drop pk in sqlite without recreating table.
Test looks to be testing that add column works as intended which we can test.
* Prevent schema creation errors.
* SQLite ignore lock tests, WAL back on.
* Fix package schema tests
* Fix NPocoFetchTests - case sensitivity not under test
* Fix AdvancedMigrationTests (where possible)
Migrations probably need a good look later.
Maybe nuke old migrations and only support moving to v10 from v9.
If we do that can do some cleanup.
* Cleanup test database configuration
* Run integration tests against SQLite on build agent.
* Drop MS.Data.SQLite
System.Data.SQLite was quicker to roll out due to more CLR type mapping
* YAML
* Skip Umbraco.Tests.Integration.SqlCe
* Drop SqlServerTableByTable tests.
Until this week they did nothing anyway as they with NewSchemaPerTest
so the tests all passed as CreateTable was no op (already exists).
Also all of the tables are created in an empty database by SchemaValidationTest.cs
DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors
* Might aswell run against macOS also.
* Copy azure pipelines task header layout
* Delete SQLCe projects
* Remove SQL CE specific code.
* Remove SQL CE NuSpec, template params, build script setup
* Delete umbraco-netcore-only.sln
* Add SkipTests solution configuration and use for codeql
* Remove reference to deleted nuspec file.
* Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName.
At this point you can try out SQLite support by setting the following
in appsettings.json and then completing the install process.
"ConnectionStrings": {
"umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite",
"umbracoDbDSN_ProviderName": "System.Data.SQLite"
},
Not currently possible via installer UI without provider name pre-set in
configuration.
* Switch to Microsoft.Data.Sqlite
Some gross hacks but will be good to find out if this works
with apple silicon.
* Enable selection of SQLite via installer UI (also quick install)
* Remove SqlServerDbProviderFactoryCreator to cleanup a TODO
* Move SQL Server support to its own class library
* Add persistence dependencies to Umbraco.CMS metapackage
* Bugfix packages delete query
Created invalid query for SQLite.
* Try out cypress tests Linux + SQLite
* Prevent cypress test artifact upload failure on attempt 2+
* LocalDb bugfixes
* Drop redundant enum
* Move SqlClient constant
* Misc whitespace
* Remove IsSqlCe extension (TODO: drop non 9->10 migrations later).
* Umbraco.Persistence.* -> Umbraco.Cms.Persistence.*
* Display quick install defaults and per provider default database name.
* Misc remove old comment
* little re-arrange
* Remove almost all usages of IsSqlite extension.
* visual adjustments
* Custom Database Configuration is last step and should then say Install.
* use text instead of disabled inputs
* move legend, rename to Install
* Update SqlMainDomLock to work without distributed locks.
* Added IDistributedLockingMechanism interface and in memory impl.
* Drop locking from ISqlSyntaxProvider & wire up scope to abstraction.
* Added SqlServerDistributedLockingMechanism
* Move distributed locking interfaces and exceptions to Core + xmldocs.
* Fix tests, Misc cleanup, Add SQL distributed locking integration tests
* Provide mechanism to specify DistributedLockingMechanism in config
(even if added by composer)
* Nomplementation -> NoImplementation
* Fix misleading comment
* Integration tests use SqlServerDistributedLockingMechanism when possible
* Handle up-gradable locks SqlServerDistributedLockingMechanism.
TODO: InMemoryDistributedLockingMechanism.
Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep
at night.
Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests
* Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky.
* Tweak constraints on WithCollectionBuilder so i can drop bad constructor
* Added SqliteDistributedLockingMechanism
* Dropped InMemoryDistributedMechanism + magic
InMemoryDistributedMechanism was pretty rubbish and now we have
a decent implementation for SQLite as we no longer block readers
see 8d1f42b.
Also drop the CollectionBuilder setup, instead do the same as we do
for syntax providers etc, it's more automagical so we never require an
explicit selection although we are allowing for it.
However keeping the optional IUmbracoBuilder constructor param for
CollectionBuilders as it's extremely useful.
* Fix quick install "" database name.
* Hide Database Configuration section when a connection string is pre-set.
Doesn't seem worth it to extract db name from connection string.
* Ensure wal test 2+
* Fix logging inconsistencies.
* Ensure in transaction when obtaining locks + no-op the SQLite read lock.
There's no point in running the query just to make a single test pass.
* Fix installer database display names
* Allow SQLite shared cache without losing deferred transactions
* Opt into shared cache for new SQLite databases + fix filename
* Fix misc inconsistency in .gitignore
* Prefer our interceptor interface
* Restore DEBUG_DATABASES code OnConnectionOpened in case it's used.
* Back to private cache.
* Added retry strategy for SQLite + refactor out SQL server specific stuff
* Fix SQL server tests.
* Misc - Orphaned comment, incorrect casing.
* InMemory SQLite test database & turn shared cache back on everywhere.
Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
|
|
|
// TODO: this should probably move to a SQL Server ProviderSpecificInterceptor.
|
2018-06-29 19:52:40 +02:00
|
|
|
#if DEBUG_DATABASES
|
|
|
|
|
// determines the database connection SPID for debugging
|
2019-01-17 12:07:31 +01:00
|
|
|
if (DatabaseType.IsSqlServer())
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
|
|
|
|
using (var command = connection.CreateCommand())
|
|
|
|
|
{
|
|
|
|
|
command.CommandText = "SELECT @@SPID";
|
|
|
|
|
_spid = Convert.ToInt32(command.ExecuteScalar());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// includes SqlCE
|
|
|
|
|
_spid = 0;
|
|
|
|
|
}
|
|
|
|
|
|
v10 SQLite support + distributed locking abstractions (#11922)
* Created Persistence.SQLite project skeleton.
* SQLite database initialization
* Various changes and hacks to make things work.
* WIP integration tests
* Fix thread safety tests
* Fix tests that relied on tie breaker sorting.
Spent a fair amount of time looking for a less lazy fix but gave up.
* Convert right join to left join ContentTypeRepository.PerformGetByQuery
SQLite doesn't support right join
* Fix test Can_Generate_Delete_SubQuery_Statement
Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override
EscapeSqlIdentifier so NPoco will escape with [].
SQLite docs say > "A keyword enclosed in square brackets is an identifier.
This is not standard SQL.
This quoting mechanism is used by MS Access and SQL Server and is
included in SQLite for compatibility."
Also could have updated SqliteSyntaxProvider to match npoco but
decided against it.
* Fixes for paginated custom order by
* Fix tests broken by lack of unique indexes.
* Fix SqlServerTableByTableTest tests.
These tests didn't actually do anything as the tables already exist so schema creator just returned.
Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation.
* Fix ValidateLoginSession - SelectTop must come later
* dry up database cleanup
* Fix up db migration tests.
We can't drop pk in sqlite without recreating table.
Test looks to be testing that add column works as intended which we can test.
* Prevent schema creation errors.
* SQLite ignore lock tests, WAL back on.
* Fix package schema tests
* Fix NPocoFetchTests - case sensitivity not under test
* Fix AdvancedMigrationTests (where possible)
Migrations probably need a good look later.
Maybe nuke old migrations and only support moving to v10 from v9.
If we do that can do some cleanup.
* Cleanup test database configuration
* Run integration tests against SQLite on build agent.
* Drop MS.Data.SQLite
System.Data.SQLite was quicker to roll out due to more CLR type mapping
* YAML
* Skip Umbraco.Tests.Integration.SqlCe
* Drop SqlServerTableByTable tests.
Until this week they did nothing anyway as they with NewSchemaPerTest
so the tests all passed as CreateTable was no op (already exists).
Also all of the tables are created in an empty database by SchemaValidationTest.cs
DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors
* Might aswell run against macOS also.
* Copy azure pipelines task header layout
* Delete SQLCe projects
* Remove SQL CE specific code.
* Remove SQL CE NuSpec, template params, build script setup
* Delete umbraco-netcore-only.sln
* Add SkipTests solution configuration and use for codeql
* Remove reference to deleted nuspec file.
* Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName.
At this point you can try out SQLite support by setting the following
in appsettings.json and then completing the install process.
"ConnectionStrings": {
"umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite",
"umbracoDbDSN_ProviderName": "System.Data.SQLite"
},
Not currently possible via installer UI without provider name pre-set in
configuration.
* Switch to Microsoft.Data.Sqlite
Some gross hacks but will be good to find out if this works
with apple silicon.
* Enable selection of SQLite via installer UI (also quick install)
* Remove SqlServerDbProviderFactoryCreator to cleanup a TODO
* Move SQL Server support to its own class library
* Add persistence dependencies to Umbraco.CMS metapackage
* Bugfix packages delete query
Created invalid query for SQLite.
* Try out cypress tests Linux + SQLite
* Prevent cypress test artifact upload failure on attempt 2+
* LocalDb bugfixes
* Drop redundant enum
* Move SqlClient constant
* Misc whitespace
* Remove IsSqlCe extension (TODO: drop non 9->10 migrations later).
* Umbraco.Persistence.* -> Umbraco.Cms.Persistence.*
* Display quick install defaults and per provider default database name.
* Misc remove old comment
* little re-arrange
* Remove almost all usages of IsSqlite extension.
* visual adjustments
* Custom Database Configuration is last step and should then say Install.
* use text instead of disabled inputs
* move legend, rename to Install
* Update SqlMainDomLock to work without distributed locks.
* Added IDistributedLockingMechanism interface and in memory impl.
* Drop locking from ISqlSyntaxProvider & wire up scope to abstraction.
* Added SqlServerDistributedLockingMechanism
* Move distributed locking interfaces and exceptions to Core + xmldocs.
* Fix tests, Misc cleanup, Add SQL distributed locking integration tests
* Provide mechanism to specify DistributedLockingMechanism in config
(even if added by composer)
* Nomplementation -> NoImplementation
* Fix misleading comment
* Integration tests use SqlServerDistributedLockingMechanism when possible
* Handle up-gradable locks SqlServerDistributedLockingMechanism.
TODO: InMemoryDistributedLockingMechanism.
Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep
at night.
Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests
* Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky.
* Tweak constraints on WithCollectionBuilder so i can drop bad constructor
* Added SqliteDistributedLockingMechanism
* Dropped InMemoryDistributedMechanism + magic
InMemoryDistributedMechanism was pretty rubbish and now we have
a decent implementation for SQLite as we no longer block readers
see 8d1f42b.
Also drop the CollectionBuilder setup, instead do the same as we do
for syntax providers etc, it's more automagical so we never require an
explicit selection although we are allowing for it.
However keeping the optional IUmbracoBuilder constructor param for
CollectionBuilders as it's extremely useful.
* Fix quick install "" database name.
* Hide Database Configuration section when a connection string is pre-set.
Doesn't seem worth it to extract db name from connection string.
* Ensure wal test 2+
* Fix logging inconsistencies.
* Ensure in transaction when obtaining locks + no-op the SQLite read lock.
There's no point in running the query just to make a single test pass.
* Fix installer database display names
* Allow SQLite shared cache without losing deferred transactions
* Opt into shared cache for new SQLite databases + fix filename
* Fix misc inconsistency in .gitignore
* Prefer our interceptor interface
* Restore DEBUG_DATABASES code OnConnectionOpened in case it's used.
* Back to private cache.
* Added retry strategy for SQLite + refactor out SQL server specific stuff
* Fix SQL server tests.
* Misc - Orphaned comment, incorrect casing.
* InMemory SQLite test database & turn shared cache back on everywhere.
Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
|
|
|
#endif
|
2018-06-29 19:52:40 +02:00
|
|
|
return connection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if DEBUG_DATABASES
|
|
|
|
|
protected override void OnConnectionClosing(DbConnection conn)
|
|
|
|
|
{
|
|
|
|
|
_spid = -1;
|
|
|
|
|
base.OnConnectionClosing(conn);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-08-16 12:00:12 +01:00
|
|
|
protected override void OnException(Exception ex)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2020-09-16 09:40:49 +02:00
|
|
|
_logger.LogError(ex, "Exception ({InstanceId}).", InstanceId);
|
2020-09-16 10:24:05 +02:00
|
|
|
_logger.LogDebug("At:\r\n{StackTrace}", Environment.StackTrace);
|
2021-09-17 12:52:23 +02:00
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
if (EnableSqlTrace == false)
|
2020-09-16 10:24:05 +02:00
|
|
|
_logger.LogDebug("Sql:\r\n{Sql}", CommandToString(LastSQL, LastArgs));
|
2021-09-17 12:52:23 +02:00
|
|
|
|
2018-08-16 12:00:12 +01:00
|
|
|
base.OnException(ex);
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-24 09:24:56 +01:00
|
|
|
private DbCommand? _cmd;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
|
|
|
protected override void OnExecutingCommand(DbCommand cmd)
|
|
|
|
|
{
|
|
|
|
|
// if no timeout is specified, and the connection has a longer timeout, use it
|
2022-02-24 09:24:56 +01:00
|
|
|
if (OneTimeCommandTimeout == 0 && CommandTimeout == 0 && cmd.Connection?.ConnectionTimeout > 30)
|
2018-06-29 19:52:40 +02:00
|
|
|
cmd.CommandTimeout = cmd.Connection.ConnectionTimeout;
|
|
|
|
|
|
|
|
|
|
if (EnableSqlTrace)
|
2020-09-16 10:24:05 +02:00
|
|
|
_logger.LogDebug("SQL Trace:\r\n{Sql}", CommandToString(cmd).Replace("{", "{{").Replace("}", "}}")); // TODO: these escapes should be builtin
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
|
|
|
#if DEBUG_DATABASES
|
|
|
|
|
// detects whether the command is already in use (eg still has an open reader...)
|
|
|
|
|
DatabaseDebugHelper.SetCommand(cmd, InstanceId + " [T" + System.Threading.Thread.CurrentThread.ManagedThreadId + "]");
|
|
|
|
|
var refsobj = DatabaseDebugHelper.GetReferencedObjects(cmd.Connection);
|
2020-09-16 10:24:05 +02:00
|
|
|
if (refsobj != null) _logger.LogDebug("Oops!" + Environment.NewLine + refsobj);
|
2018-06-29 19:52:40 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
_cmd = cmd;
|
2021-09-17 12:52:23 +02:00
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
base.OnExecutingCommand(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-24 09:24:56 +01:00
|
|
|
private string CommandToString(DbCommand cmd) => CommandToString(cmd.CommandText, cmd.Parameters.Cast<DbParameter>().Select(x => x.Value).WhereNotNull().ToArray());
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-02-24 09:24:56 +01:00
|
|
|
private string CommandToString(string? sql, object[]? args)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2018-07-04 14:48:44 +02:00
|
|
|
var text = new StringBuilder();
|
2018-06-29 19:52:40 +02:00
|
|
|
#if DEBUG_DATABASES
|
2021-09-17 12:52:23 +02:00
|
|
|
text.Append(InstanceId);
|
|
|
|
|
text.Append(": ");
|
2018-06-29 19:52:40 +02:00
|
|
|
#endif
|
2021-09-17 12:52:23 +02:00
|
|
|
|
2018-07-04 14:48:44 +02:00
|
|
|
NPocoSqlExtensions.ToText(sql, args, text);
|
2021-09-17 12:52:23 +02:00
|
|
|
|
2018-07-04 14:48:44 +02:00
|
|
|
return text.ToString();
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnExecutedCommand(DbCommand cmd)
|
|
|
|
|
{
|
|
|
|
|
if (_enableCount)
|
|
|
|
|
SqlCount++;
|
|
|
|
|
|
2020-03-30 17:25:29 +11:00
|
|
|
_commands?.Add(new CommandInfo(cmd));
|
|
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
base.OnExecutedCommand(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2020-03-30 17:25:29 +11:00
|
|
|
|
|
|
|
|
// used for tracking commands
|
|
|
|
|
public class CommandInfo
|
|
|
|
|
{
|
|
|
|
|
public CommandInfo(IDbCommand cmd)
|
|
|
|
|
{
|
|
|
|
|
Text = cmd.CommandText;
|
|
|
|
|
var parameters = new List<ParameterInfo>();
|
2021-09-17 12:52:23 +02:00
|
|
|
foreach (IDbDataParameter parameter in cmd.Parameters)
|
|
|
|
|
parameters.Add(new ParameterInfo(parameter));
|
|
|
|
|
|
2020-03-30 17:25:29 +11:00
|
|
|
Parameters = parameters.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Text { get; }
|
2021-09-17 12:52:23 +02:00
|
|
|
|
2020-03-30 17:25:29 +11:00
|
|
|
public ParameterInfo[] Parameters { get; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// used for tracking commands
|
|
|
|
|
public class ParameterInfo
|
|
|
|
|
{
|
|
|
|
|
public ParameterInfo(IDbDataParameter parameter)
|
|
|
|
|
{
|
|
|
|
|
Name = parameter.ParameterName;
|
|
|
|
|
Value = parameter.Value;
|
|
|
|
|
DbType = parameter.DbType;
|
|
|
|
|
Size = parameter.Size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name { get; }
|
2022-02-24 09:24:56 +01:00
|
|
|
public object? Value { get; }
|
2020-03-30 17:25:29 +11:00
|
|
|
public DbType DbType { get; }
|
|
|
|
|
public int Size { get; }
|
|
|
|
|
}
|
v10 SQLite support + distributed locking abstractions (#11922)
* Created Persistence.SQLite project skeleton.
* SQLite database initialization
* Various changes and hacks to make things work.
* WIP integration tests
* Fix thread safety tests
* Fix tests that relied on tie breaker sorting.
Spent a fair amount of time looking for a less lazy fix but gave up.
* Convert right join to left join ContentTypeRepository.PerformGetByQuery
SQLite doesn't support right join
* Fix test Can_Generate_Delete_SubQuery_Statement
Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override
EscapeSqlIdentifier so NPoco will escape with [].
SQLite docs say > "A keyword enclosed in square brackets is an identifier.
This is not standard SQL.
This quoting mechanism is used by MS Access and SQL Server and is
included in SQLite for compatibility."
Also could have updated SqliteSyntaxProvider to match npoco but
decided against it.
* Fixes for paginated custom order by
* Fix tests broken by lack of unique indexes.
* Fix SqlServerTableByTableTest tests.
These tests didn't actually do anything as the tables already exist so schema creator just returned.
Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation.
* Fix ValidateLoginSession - SelectTop must come later
* dry up database cleanup
* Fix up db migration tests.
We can't drop pk in sqlite without recreating table.
Test looks to be testing that add column works as intended which we can test.
* Prevent schema creation errors.
* SQLite ignore lock tests, WAL back on.
* Fix package schema tests
* Fix NPocoFetchTests - case sensitivity not under test
* Fix AdvancedMigrationTests (where possible)
Migrations probably need a good look later.
Maybe nuke old migrations and only support moving to v10 from v9.
If we do that can do some cleanup.
* Cleanup test database configuration
* Run integration tests against SQLite on build agent.
* Drop MS.Data.SQLite
System.Data.SQLite was quicker to roll out due to more CLR type mapping
* YAML
* Skip Umbraco.Tests.Integration.SqlCe
* Drop SqlServerTableByTable tests.
Until this week they did nothing anyway as they with NewSchemaPerTest
so the tests all passed as CreateTable was no op (already exists).
Also all of the tables are created in an empty database by SchemaValidationTest.cs
DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors
* Might aswell run against macOS also.
* Copy azure pipelines task header layout
* Delete SQLCe projects
* Remove SQL CE specific code.
* Remove SQL CE NuSpec, template params, build script setup
* Delete umbraco-netcore-only.sln
* Add SkipTests solution configuration and use for codeql
* Remove reference to deleted nuspec file.
* Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName.
At this point you can try out SQLite support by setting the following
in appsettings.json and then completing the install process.
"ConnectionStrings": {
"umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite",
"umbracoDbDSN_ProviderName": "System.Data.SQLite"
},
Not currently possible via installer UI without provider name pre-set in
configuration.
* Switch to Microsoft.Data.Sqlite
Some gross hacks but will be good to find out if this works
with apple silicon.
* Enable selection of SQLite via installer UI (also quick install)
* Remove SqlServerDbProviderFactoryCreator to cleanup a TODO
* Move SQL Server support to its own class library
* Add persistence dependencies to Umbraco.CMS metapackage
* Bugfix packages delete query
Created invalid query for SQLite.
* Try out cypress tests Linux + SQLite
* Prevent cypress test artifact upload failure on attempt 2+
* LocalDb bugfixes
* Drop redundant enum
* Move SqlClient constant
* Misc whitespace
* Remove IsSqlCe extension (TODO: drop non 9->10 migrations later).
* Umbraco.Persistence.* -> Umbraco.Cms.Persistence.*
* Display quick install defaults and per provider default database name.
* Misc remove old comment
* little re-arrange
* Remove almost all usages of IsSqlite extension.
* visual adjustments
* Custom Database Configuration is last step and should then say Install.
* use text instead of disabled inputs
* move legend, rename to Install
* Update SqlMainDomLock to work without distributed locks.
* Added IDistributedLockingMechanism interface and in memory impl.
* Drop locking from ISqlSyntaxProvider & wire up scope to abstraction.
* Added SqlServerDistributedLockingMechanism
* Move distributed locking interfaces and exceptions to Core + xmldocs.
* Fix tests, Misc cleanup, Add SQL distributed locking integration tests
* Provide mechanism to specify DistributedLockingMechanism in config
(even if added by composer)
* Nomplementation -> NoImplementation
* Fix misleading comment
* Integration tests use SqlServerDistributedLockingMechanism when possible
* Handle up-gradable locks SqlServerDistributedLockingMechanism.
TODO: InMemoryDistributedLockingMechanism.
Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep
at night.
Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests
* Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky.
* Tweak constraints on WithCollectionBuilder so i can drop bad constructor
* Added SqliteDistributedLockingMechanism
* Dropped InMemoryDistributedMechanism + magic
InMemoryDistributedMechanism was pretty rubbish and now we have
a decent implementation for SQLite as we no longer block readers
see 8d1f42b.
Also drop the CollectionBuilder setup, instead do the same as we do
for syntax providers etc, it's more automagical so we never require an
explicit selection although we are allowing for it.
However keeping the optional IUmbracoBuilder constructor param for
CollectionBuilders as it's extremely useful.
* Fix quick install "" database name.
* Hide Database Configuration section when a connection string is pre-set.
Doesn't seem worth it to extract db name from connection string.
* Ensure wal test 2+
* Fix logging inconsistencies.
* Ensure in transaction when obtaining locks + no-op the SQLite read lock.
There's no point in running the query just to make a single test pass.
* Fix installer database display names
* Allow SQLite shared cache without losing deferred transactions
* Opt into shared cache for new SQLite databases + fix filename
* Fix misc inconsistency in .gitignore
* Prefer our interceptor interface
* Restore DEBUG_DATABASES code OnConnectionOpened in case it's used.
* Back to private cache.
* Added retry strategy for SQLite + refactor out SQL server specific stuff
* Fix SQL server tests.
* Misc - Orphaned comment, incorrect casing.
* InMemory SQLite test database & turn shared cache back on everywhere.
Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
|
|
|
|
|
|
|
|
/// <inheritdoc cref="Database.ExecuteScalar{T}(string,object[])"/>
|
|
|
|
|
public new T ExecuteScalar<T>(string sql, params object[] args)
|
|
|
|
|
=> ExecuteScalar<T>(new Sql(sql, args));
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc cref="Database.ExecuteScalar{T}(sql)"/>
|
|
|
|
|
public new T ExecuteScalar<T>(Sql sql)
|
|
|
|
|
=> ExecuteScalar<T>(sql.SQL, CommandType.Text, sql.Arguments);
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc cref="Database.ExecuteScalar{T}(string,CommandType,object[])"/>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Be nice if handled upstream <a href="https://github.com/schotime/NPoco/issues/653">GH issue</a>
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public new T ExecuteScalar<T>(string sql, CommandType commandType, params object[] args)
|
|
|
|
|
{
|
|
|
|
|
if (SqlContext.SqlSyntax.ScalarMappers == null)
|
|
|
|
|
{
|
|
|
|
|
return base.ExecuteScalar<T>(sql, commandType, args);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-17 09:14:12 +01:00
|
|
|
if (!SqlContext.SqlSyntax.ScalarMappers.TryGetValue(typeof(T), out IScalarMapper? mapper))
|
v10 SQLite support + distributed locking abstractions (#11922)
* Created Persistence.SQLite project skeleton.
* SQLite database initialization
* Various changes and hacks to make things work.
* WIP integration tests
* Fix thread safety tests
* Fix tests that relied on tie breaker sorting.
Spent a fair amount of time looking for a less lazy fix but gave up.
* Convert right join to left join ContentTypeRepository.PerformGetByQuery
SQLite doesn't support right join
* Fix test Can_Generate_Delete_SubQuery_Statement
Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override
EscapeSqlIdentifier so NPoco will escape with [].
SQLite docs say > "A keyword enclosed in square brackets is an identifier.
This is not standard SQL.
This quoting mechanism is used by MS Access and SQL Server and is
included in SQLite for compatibility."
Also could have updated SqliteSyntaxProvider to match npoco but
decided against it.
* Fixes for paginated custom order by
* Fix tests broken by lack of unique indexes.
* Fix SqlServerTableByTableTest tests.
These tests didn't actually do anything as the tables already exist so schema creator just returned.
Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation.
* Fix ValidateLoginSession - SelectTop must come later
* dry up database cleanup
* Fix up db migration tests.
We can't drop pk in sqlite without recreating table.
Test looks to be testing that add column works as intended which we can test.
* Prevent schema creation errors.
* SQLite ignore lock tests, WAL back on.
* Fix package schema tests
* Fix NPocoFetchTests - case sensitivity not under test
* Fix AdvancedMigrationTests (where possible)
Migrations probably need a good look later.
Maybe nuke old migrations and only support moving to v10 from v9.
If we do that can do some cleanup.
* Cleanup test database configuration
* Run integration tests against SQLite on build agent.
* Drop MS.Data.SQLite
System.Data.SQLite was quicker to roll out due to more CLR type mapping
* YAML
* Skip Umbraco.Tests.Integration.SqlCe
* Drop SqlServerTableByTable tests.
Until this week they did nothing anyway as they with NewSchemaPerTest
so the tests all passed as CreateTable was no op (already exists).
Also all of the tables are created in an empty database by SchemaValidationTest.cs
DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors
* Might aswell run against macOS also.
* Copy azure pipelines task header layout
* Delete SQLCe projects
* Remove SQL CE specific code.
* Remove SQL CE NuSpec, template params, build script setup
* Delete umbraco-netcore-only.sln
* Add SkipTests solution configuration and use for codeql
* Remove reference to deleted nuspec file.
* Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName.
At this point you can try out SQLite support by setting the following
in appsettings.json and then completing the install process.
"ConnectionStrings": {
"umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite",
"umbracoDbDSN_ProviderName": "System.Data.SQLite"
},
Not currently possible via installer UI without provider name pre-set in
configuration.
* Switch to Microsoft.Data.Sqlite
Some gross hacks but will be good to find out if this works
with apple silicon.
* Enable selection of SQLite via installer UI (also quick install)
* Remove SqlServerDbProviderFactoryCreator to cleanup a TODO
* Move SQL Server support to its own class library
* Add persistence dependencies to Umbraco.CMS metapackage
* Bugfix packages delete query
Created invalid query for SQLite.
* Try out cypress tests Linux + SQLite
* Prevent cypress test artifact upload failure on attempt 2+
* LocalDb bugfixes
* Drop redundant enum
* Move SqlClient constant
* Misc whitespace
* Remove IsSqlCe extension (TODO: drop non 9->10 migrations later).
* Umbraco.Persistence.* -> Umbraco.Cms.Persistence.*
* Display quick install defaults and per provider default database name.
* Misc remove old comment
* little re-arrange
* Remove almost all usages of IsSqlite extension.
* visual adjustments
* Custom Database Configuration is last step and should then say Install.
* use text instead of disabled inputs
* move legend, rename to Install
* Update SqlMainDomLock to work without distributed locks.
* Added IDistributedLockingMechanism interface and in memory impl.
* Drop locking from ISqlSyntaxProvider & wire up scope to abstraction.
* Added SqlServerDistributedLockingMechanism
* Move distributed locking interfaces and exceptions to Core + xmldocs.
* Fix tests, Misc cleanup, Add SQL distributed locking integration tests
* Provide mechanism to specify DistributedLockingMechanism in config
(even if added by composer)
* Nomplementation -> NoImplementation
* Fix misleading comment
* Integration tests use SqlServerDistributedLockingMechanism when possible
* Handle up-gradable locks SqlServerDistributedLockingMechanism.
TODO: InMemoryDistributedLockingMechanism.
Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep
at night.
Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests
* Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky.
* Tweak constraints on WithCollectionBuilder so i can drop bad constructor
* Added SqliteDistributedLockingMechanism
* Dropped InMemoryDistributedMechanism + magic
InMemoryDistributedMechanism was pretty rubbish and now we have
a decent implementation for SQLite as we no longer block readers
see 8d1f42b.
Also drop the CollectionBuilder setup, instead do the same as we do
for syntax providers etc, it's more automagical so we never require an
explicit selection although we are allowing for it.
However keeping the optional IUmbracoBuilder constructor param for
CollectionBuilders as it's extremely useful.
* Fix quick install "" database name.
* Hide Database Configuration section when a connection string is pre-set.
Doesn't seem worth it to extract db name from connection string.
* Ensure wal test 2+
* Fix logging inconsistencies.
* Ensure in transaction when obtaining locks + no-op the SQLite read lock.
There's no point in running the query just to make a single test pass.
* Fix installer database display names
* Allow SQLite shared cache without losing deferred transactions
* Opt into shared cache for new SQLite databases + fix filename
* Fix misc inconsistency in .gitignore
* Prefer our interceptor interface
* Restore DEBUG_DATABASES code OnConnectionOpened in case it's used.
* Back to private cache.
* Added retry strategy for SQLite + refactor out SQL server specific stuff
* Fix SQL server tests.
* Misc - Orphaned comment, incorrect casing.
* InMemory SQLite test database & turn shared cache back on everywhere.
Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
|
|
|
{
|
|
|
|
|
return base.ExecuteScalar<T>(sql, commandType, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = base.ExecuteScalar<object>(sql, commandType, args);
|
|
|
|
|
return (T)mapper.Map(result);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
}
|