Skip to content

Commit

Permalink
Read boolean as int if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmarbach committed Mar 12, 2024
1 parent ace4fbe commit af1de53
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/SqlPersistence/Extensions.cs
Expand Up @@ -72,16 +72,21 @@ public static void AddParameter(this DbCommand command, string name, Version val
public static async Task<bool> 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<ulong>(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<short>(position, cancellationToken).ConfigureAwait(false));
}
// or it might be stored as ints.
if (type == typeof(int))
{
return Convert.ToBoolean(await reader.GetFieldValueAsync<int>(position, cancellationToken).ConfigureAwait(false));
}
return await reader.GetFieldValueAsync<bool>(position, cancellationToken).ConfigureAwait(false);
}

Expand Down

0 comments on commit af1de53

Please sign in to comment.