From af1de5335263ed6fb6e78b1d1f4a942e838b2ccf Mon Sep 17 00:00:00 2001 From: danielmarbach Date: Fri, 8 Mar 2024 18:25:54 +0100 Subject: [PATCH] Read boolean as int if necessary --- src/SqlPersistence/Extensions.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/SqlPersistence/Extensions.cs b/src/SqlPersistence/Extensions.cs index 61cdcf9fb..7e0bdd98c 100644 --- a/src/SqlPersistence/Extensions.cs +++ b/src/SqlPersistence/Extensions.cs @@ -72,16 +72,21 @@ public static void AddParameter(this DbCommand command, string name, Version val public static async Task GetBoolAsync(this DbDataReader reader, int position, CancellationToken cancellationToken = default) { var type = reader.GetFieldType(position); - // MySql stores bools as ints + // MySql stores bools as longs (ulong) if (type == typeof(ulong)) { return Convert.ToBoolean(await reader.GetFieldValueAsync(position, cancellationToken).ConfigureAwait(false)); } - // In Oracle we store bools as NUMBER(1,0) (short). + // In Oracle default driver store bools as NUMBER(1,0) (short). if (type == typeof(short)) { return Convert.ToBoolean(await reader.GetFieldValueAsync(position, cancellationToken).ConfigureAwait(false)); } + // or it might be stored as ints. + if (type == typeof(int)) + { + return Convert.ToBoolean(await reader.GetFieldValueAsync(position, cancellationToken).ConfigureAwait(false)); + } return await reader.GetFieldValueAsync(position, cancellationToken).ConfigureAwait(false); }