Skip to content

Commit b693821

Browse files
JaBistDuNarrischJaBistDuNarrisch
authored andcommitted
SQLite does not support default BLOB values => throw
1 parent d7ac6ec commit b693821

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/Migrator/Providers/Dialect.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,13 @@ public virtual string Default(object defaultValue)
349349

350350
return guidValue;
351351
}
352-
else if (defaultValue is DateTime)
352+
else if (defaultValue is DateTime dateTime)
353353
{
354+
if (dateTime.Kind != DateTimeKind.Utc)
355+
{
356+
throw new Exception("Use DateTimeKind.Utc for default date time values.");
357+
}
358+
354359
return string.Format("DEFAULT '{0}'", ((DateTime)defaultValue).ToString("yyyy-MM-dd HH:mm:ss"));
355360
}
356361
else if (defaultValue is string)

src/Migrator/Providers/Impl/Oracle/OracleDialect.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public override string Default(object defaultValue)
160160
}
161161
else if (defaultValue is DateTime dateTime)
162162
{
163+
// We use 4 because we have no access data type and therefore no access to the real n in TIMESTAMP(n) in this method. Needs refactoring.
163164
var dateTimeString = dateTime.ToString("yyyy-MM-dd HH:mm:ss.ffff");
164165
return $"DEFAULT TO_TIMESTAMP('{dateTimeString}', 'YYYY-MM-DD HH24:MI:SS.FF4')";
165166
}

src/Migrator/Providers/Impl/SQLite/SQLiteTransformationProvider.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ public override Column[] GetColumns(string tableName)
966966
dt = defVal.Substring(1, defVal.Length - 2);
967967
}
968968

969-
var d = DateTime.ParseExact(dt, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
969+
var d = DateTime.ParseExact(dt, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);
970970
column.DefaultValue = d;
971971
}
972972
}
@@ -985,6 +985,10 @@ public override Column[] GetColumns(string tableName)
985985
column.DefaultValue = d;
986986
}
987987
}
988+
else if (column.Type == DbType.Boolean)
989+
{
990+
throw new NotSupportedException("SQLite does not support default values for BLOB columns.");
991+
}
988992
}
989993

990994
if (pragmaTableInfoItem.Pk > 0)

0 commit comments

Comments
 (0)