Skip to content

Commit

Permalink
Fixed SQlite Schema discovery.
Browse files Browse the repository at this point in the history
Added basic SQlite  DefaultValue support.
  • Loading branch information
nemesv committed Jan 10, 2012
1 parent 2f48d1c commit 40368ad
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions Massive.Sqlite.cs
Expand Up @@ -167,18 +167,18 @@ public dynamic DefaultValue(dynamic column)
if (String.IsNullOrEmpty(def))
{
result = null;
}
else if (def == "getdate()" || def == "(getdate())")
{
result = DateTime.Now.ToShortDateString();
}
else if (def == "newid()")
{
result = Guid.NewGuid().ToString();
}
else
{
result = def.Replace("(", "").Replace(")", "");
}
else if (def == "CURRENT_TIME")
{
result = DateTime.UtcNow.ToString("HH:mm:ss");
}
else if (def == "CURRENT_DATE")
{
result = DateTime.UtcNow.ToString("yyyy-MM-dd");
}
else if (def == "CURRENT_TIMESTAMP")
{
result = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
}
return result;
}
Expand Down Expand Up @@ -207,9 +207,22 @@ public dynamic Prototype
public IEnumerable<dynamic> Schema
{
get
{
if (_schema == null)
_schema = Query("SELECT * FROM sqlite_master WHERE type = 'table' and name = @0", TableName);
{
if (_schema == null)
{
var rows = new List<dynamic>();
foreach (var row in Query("PRAGMA table_info('" + TableName + "')"))
{
rows.Add(new
{
COLUMN_NAME = (row as IDictionary<string, object>)["name"].ToString(),
DATA_TYPE = (row as IDictionary<string, object>)["type"].ToString(),
IS_NULLABLE = (row as IDictionary<string, object>)["notnull"].ToString() == "0" ? "NO" : "YES",
COLUMN_DEFAULT = (row as IDictionary<string, object>)["dflt_value"] ?? "",
});
}
_schema = rows;
}
return _schema;
}
}
Expand Down

0 comments on commit 40368ad

Please sign in to comment.