public static IEnumerable <object> Query(this Database db, Type type, NPoco.Sql query) { var method = typeof(Database).GetGenericMethod("Query", new[] { type }, new[] { typeof(NPoco.Sql) }); var generic = method.MakeGenericMethod(type); return((IEnumerable <object>)generic.Invoke(db, new object[] { query })); }
public string remoteCheck(CheckExits model) { Sql sql = new NPoco.Sql(string.Format("select count(1) from {0} where {1}='{2}'", model.TableName, model.ValidField, model.ValidValue)); if (!string.IsNullOrEmpty(model.DataID)) { sql.Append(string.Format(" and {0}<>'{1}' ", model.KeyField, model.DataID)); } if (model.Filter != null) { sql.Append(ConditionParser.Serialize(model.Filter)); } if (this.Db.Single <long>(sql) > 0) { return(string.Format("{0}的值已存在", model.Label)); } return(""); // }
public string remoteCheck(CheckExits model, string frmID, string dataModelID) { Sql sql = new NPoco.Sql(string.Format("select count(1) from {0} where {1}='{2}'", model.TableName, model.ValidField, model.ValidValue)); if (!string.IsNullOrEmpty(model.DataID)) { sql.Append(string.Format(" and {0}<>'{1}' ", model.KeyField, model.DataID)); } if (model.Filter != null) { sql.Append(ConditionParser.Serialize(model.Filter)); } var ds = DataModelCom.getDataSource(dataModelID, this.Db); Database ywdb = DataBaseManger.GetDB(ds); if (ywdb.Single <long>(sql) > 0) { return(string.Format("{0}的值已存在", model.Label)); } return(""); }
public Sql Append(Sql sql) { if (_sqlFinal != null) _sqlFinal = null; if (_rhs != null) { _rhs.Append(sql); } else if (_sql != null) { _rhs = sql; } else { _sql = sql._sql; _args = sql._args; _rhs = sql._rhs; } return this; }
public static Page <object> Page(this Database db, Type type, long page, long itemsPerPage, NPoco.Sql query) { var method = typeof(Database).GetGenericMethod("Page", new[] { type }, new[] { typeof(long), typeof(long), typeof(NPoco.Sql) }); var generic = method.MakeGenericMethod(type); var result = generic.Invoke(db, new object[] { page, itemsPerPage, query }); return(new Page <object> { CurrentPage = page, ItemsPerPage = itemsPerPage, TotalItems = (long)result.GetPropertyValue("TotalItems"), TotalPages = (long)result.GetPropertyValue("TotalPages"), Items = ((IList)result.GetPropertyValue("Items")).Cast <object>().ToList() }); }
public SqlJoinClause(Sql sql) { _sql = sql; }
private void Build(StringBuilder sb, List<object> args, Sql lhs) { if (!String.IsNullOrEmpty(_sql)) { // Add SQL to the string if (sb.Length > 0) { sb.Append("\n"); } var sql = ParameterHelper.ProcessParams(_sql, _args, args); if (Is(lhs, "WHERE ") && Is(this, "WHERE ")) sql = "AND " + sql.Substring(6); if (Is(lhs, "ORDER BY ") && Is(this, "ORDER BY ")) sql = ", " + sql.Substring(9); sb.Append(sql); } // Now do rhs if (_rhs != null) _rhs.Build(sb, args, this); }
static bool Is(Sql sql, string sqltype) { return sql != null && sql._sql != null && sql._sql.StartsWith(sqltype, StringComparison.InvariantCultureIgnoreCase); }
static bool Is(Sql sql, string sqltype) { return sql != null && sql._sql != null && sql._sql.StartsWith(sqltype, StringComparison.OrdinalIgnoreCase); }