Permalink
Browse files

Merge pull request #122 from nemesv/Sqlite_Schema_fix

Sqlite schema fix
  • Loading branch information...
2 parents 23d7616 + 77f9e7f commit 6127a810774280a199ddad96685b02487ab5a9cb @robconery robconery committed Feb 22, 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.ToUpper() == "CURRENT_TIME")
+ {
+ result = DateTime.UtcNow.ToString("HH:mm:ss");
+ }
+ else if (def.ToUpper() == "CURRENT_DATE")
+ {
+ result = DateTime.UtcNow.ToString("yyyy-MM-dd");
+ }
+ else if (def.ToUpper() == "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 6127a81

Please sign in to comment.