Skip to content

Commit 40368ad

Browse files
committed
Fixed SQlite Schema discovery.
Added basic SQlite DefaultValue support.
1 parent 2f48d1c commit 40368ad

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

Massive.Sqlite.cs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,18 @@ public dynamic DefaultValue(dynamic column)
167167
if (String.IsNullOrEmpty(def))
168168
{
169169
result = null;
170-
}
171-
else if (def == "getdate()" || def == "(getdate())")
172-
{
173-
result = DateTime.Now.ToShortDateString();
174-
}
175-
else if (def == "newid()")
176-
{
177-
result = Guid.NewGuid().ToString();
178-
}
179-
else
180-
{
181-
result = def.Replace("(", "").Replace(")", "");
170+
}
171+
else if (def == "CURRENT_TIME")
172+
{
173+
result = DateTime.UtcNow.ToString("HH:mm:ss");
174+
}
175+
else if (def == "CURRENT_DATE")
176+
{
177+
result = DateTime.UtcNow.ToString("yyyy-MM-dd");
178+
}
179+
else if (def == "CURRENT_TIMESTAMP")
180+
{
181+
result = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
182182
}
183183
return result;
184184
}
@@ -207,9 +207,22 @@ public dynamic Prototype
207207
public IEnumerable<dynamic> Schema
208208
{
209209
get
210-
{
211-
if (_schema == null)
212-
_schema = Query("SELECT * FROM sqlite_master WHERE type = 'table' and name = @0", TableName);
210+
{
211+
if (_schema == null)
212+
{
213+
var rows = new List<dynamic>();
214+
foreach (var row in Query("PRAGMA table_info('" + TableName + "')"))
215+
{
216+
rows.Add(new
217+
{
218+
COLUMN_NAME = (row as IDictionary<string, object>)["name"].ToString(),
219+
DATA_TYPE = (row as IDictionary<string, object>)["type"].ToString(),
220+
IS_NULLABLE = (row as IDictionary<string, object>)["notnull"].ToString() == "0" ? "NO" : "YES",
221+
COLUMN_DEFAULT = (row as IDictionary<string, object>)["dflt_value"] ?? "",
222+
});
223+
}
224+
_schema = rows;
225+
}
213226
return _schema;
214227
}
215228
}

0 commit comments

Comments
 (0)