Permalink
Browse files

Fixed SQlite Schema discovery.

Added basic SQlite  DefaultValue support.
  • Loading branch information...
1 parent 2f48d1c commit 40368ad6ebbf5ef87cdb83a13fe7456c9747a5e5 @nemesv nemesv committed Jan 10, 2012
Showing with 28 additions and 15 deletions.
  1. +28 −15 Massive.Sqlite.cs
View
@@ -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;
}
@@ -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;
}
}

0 comments on commit 40368ad

Please sign in to comment.