Example #1
0
 public static void AppendWhereByEnsuredKey(Command cmd, Where where, string keyFieldName, IDbAdapter adapter)
 {
     if (where == null)
         return;
     switch (where.Type)
     {
         case WhereType.Key:
             cmd.AppendFormat(" where {0}=@0WhereKey", keyFieldName);
             cmd.AddParameter("@0WhereKey", where.SingleObject);
             break;
         case WhereType.Custom:
             if (!string.IsNullOrEmpty(where.QueryString))
             {
                 cmd.AppendFormat(" where {0}", where.QueryString);
                 for (int i = 0; i < where.Parameters.Count; i++)
                     cmd.AddParameter("@" + i, where.Parameters[i]);
             }
             break;
     }
     AppendOrders(cmd, where.Orders, adapter);
 }
Example #2
0
 public virtual void AppendPage(Command cmd, string keyFieldName, string tableName, Page page, Where where)
 {
     cmd.Append(" limit @0PageStartIndex, @0PageCount");
     cmd.AddParameter("@0PageStartIndex", page.StartPos);
     cmd.AddParameter("@0PageCount", page.Count);
 }
Example #3
0
 public static void AppendPage(Command cmd, string keyFieldName, string tableName, Page page, Where where, IDbAdapter adapter)
 {
     if (page == null)
         return;
     adapter.AppendPage(cmd, keyFieldName, tableName, page, where);
 }
Example #4
0
 public static void AppendWhere(Command cmd, Where where, string keyFieldName, IDbAdapter adapter)
 {
     AppendWhereByEnsuredKey(cmd, where, adapter.EnsureIdentifier(keyFieldName), adapter);
 }
Example #5
0
        public virtual void AppendPage(Command cmd, string keyFieldName, string tableName, Page page, Where where)
        {
            if (page == null)
                return;

            string ori = cmd.QueryString;
            if (ori.Substring(0, 7).ToLower() != "select ")
                return;
            string oriselect = ori.Substring(7, ori.IndexOf(" from ", StringComparison.CurrentCultureIgnoreCase) - 7);

            int where_index = ori.LastIndexOf(" where ", StringComparison.CurrentCultureIgnoreCase);
            if (where_index != -1)
                ori = ori.Substring(where_index + 7);

            cmd.QueryString = string.Format(
                "select top {0} {1} from [{2}] where {6}([{3}] not in (select top {4} [{3}] from [{2}]{5}))",
                page.Count, oriselect, tableName, keyFieldName, page.StartPos,
                where_index == -1 ? string.Empty : " where " + ori,
                where_index == -1 ? string.Empty : ori + " and "
            );

            if (where != null)
                Builder.AppendOrders(cmd, where.Orders, this);
        }