Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Sqlite schema fix #122

Merged
merged 2 commits into from

2 participants

@nemesv

+Fix for the issue Sqlite Schema detection:
#86

+Basic support for CURRENT_(TIME|DATE|TIMESTAMP) Sqlite default value keywords.

@robconery robconery merged commit 6127a81 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 10, 2012
  1. @nemesv

    Fixed SQlite Schema discovery.

    nemesv authored
    Added basic SQlite  DefaultValue support.
Commits on Jan 11, 2012
  1. @nemesv
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 15 deletions.
  1. +28 −15 Massive.Sqlite.cs
View
43 Massive.Sqlite.cs
@@ -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;
}
}
Something went wrong with that request. Please try again.