本文整理汇总了C#中ScrewTurn.Wiki.Plugins.SqlCommon.QueryBuilder.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# QueryBuilder.OrderBy方法的具体用法?C# QueryBuilder.OrderBy怎么用?C# QueryBuilder.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScrewTurn.Wiki.Plugins.SqlCommon.QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder.OrderBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNamespaces
/// <summary>
/// Gets all the sub-namespaces.
/// </summary>
/// <returns>The sub-namespaces, sorted by name.</returns>
public NamespaceInfo[] GetNamespaces()
{
ICommandBuilder builder = GetCommandBuilder();
QueryBuilder queryBuilder = new QueryBuilder(builder);
// select ... from Namespace left join Page on Namespace.DefaultPage = Page.Name where Namespace.Name <> '' and (Namespace.DefaultPage is null or Page.Namespace <> '')
string query = queryBuilder.SelectFrom("Namespace", "Page", "DefaultPage", "Name", Join.LeftJoin, new string[] { "Name", "DefaultPage" }, new string[] { "CreationDateTime" });
query = queryBuilder.Where(query, "Namespace", "Name", WhereOperator.NotEquals, "Empty1");
query = queryBuilder.AndWhere(query, "Namespace", "DefaultPage", WhereOperator.IsNull, null, true, false);
query = queryBuilder.OrWhere(query, "Page", "Namespace", WhereOperator.NotEquals, "Empty2", false, true);
query = queryBuilder.OrderBy(query, new[] { "Namespace_Name" }, new[] { Ordering.Asc });
List<Parameter> parameters = new List<Parameter>(2);
parameters.Add(new Parameter(ParameterType.String, "Empty1", ""));
parameters.Add(new Parameter(ParameterType.String, "Empty2", ""));
DbCommand command = builder.GetCommand(connString, query, parameters);
DbDataReader reader = ExecuteReader(command);
if(reader != null) {
List<NamespaceInfo> result = new List<NamespaceInfo>(10);
while(reader.Read()) {
string realName = reader["Namespace_Name"] as string;
string page = GetNullableColumn<string>(reader, "Namespace_DefaultPage", null);
PageInfo defaultPage = string.IsNullOrEmpty(page) ? null :
new PageInfo(NameTools.GetFullName(realName, page), this, (DateTime)reader["Page_CreationDateTime"]);
// The query returns duplicate entries if the main page of two or more namespaces have the same name
if(result.Find(n => { return n.Name.Equals(realName); }) == null) {
result.Add(new NamespaceInfo(realName, this, defaultPage));
}
}
CloseReader(command, reader);
return result.ToArray();
}
else return null;
}
示例2: GetNavigationPaths
/// <summary>
/// Gets all the Navigation Paths in a Namespace.
/// </summary>
/// <param name="nspace">The Namespace.</param>
/// <returns>All the Navigation Paths, sorted by name.</returns>
public NavigationPath[] GetNavigationPaths(NamespaceInfo nspace)
{
string nspaceName = nspace != null ? nspace.Name : "";
ICommandBuilder builder = GetCommandBuilder();
QueryBuilder queryBuilder = new QueryBuilder(builder);
string query = queryBuilder.SelectFrom("NavigationPath", new string[] { "Name", "Namespace", "Page" });
query = queryBuilder.Where(query, "Namespace", WhereOperator.Equals, "Namespace");
query = queryBuilder.OrderBy(query, new string[] { "Namespace", "Name", "Number" }, new Ordering[] { Ordering.Asc, Ordering.Asc, Ordering.Asc });
List<Parameter> parameters = new List<Parameter>(1);
parameters.Add(new Parameter(ParameterType.String, "Namespace", nspaceName));
DbCommand command = builder.GetCommand(connString, query, parameters);
DbDataReader reader = ExecuteReader(command);
if(reader != null) {
List<NavigationPath> result = new List<NavigationPath>(10);
string prevName = "|||";
string name;
string actualNamespace = "";
List<string> pages = new List<string>(10);
while(reader.Read()) {
name = reader["Name"] as string;
if(name != prevName) {
actualNamespace = reader["Namespace"] as string;
if(prevName != "|||") {
result[result.Count - 1].Pages = pages.ToArray();
pages.Clear();
}
result.Add(new NavigationPath(NameTools.GetFullName(actualNamespace, name), this));
}
prevName = name;
pages.Add(NameTools.GetFullName(actualNamespace, reader["Page"] as string));
}
if(result.Count > 0) {
result[result.Count - 1].Pages = pages.ToArray();
}
CloseReader(command, reader);
return result.ToArray();
}
else return null;
}
示例3: GetPages
/// <summary>
/// Gets all the Pages in a namespace.
/// </summary>
/// <param name="connection">A database connection.</param>
/// <param name="nspace">The namespace (<c>null</c> for the root).</param>
/// <returns>All the Pages in the namespace. The array is not sorted.</returns>
private PageInfo[] GetPages(DbConnection connection, NamespaceInfo nspace)
{
string nspaceName = nspace != null ? nspace.Name : "";
ICommandBuilder builder = GetCommandBuilder();
QueryBuilder queryBuilder = new QueryBuilder(builder);
string query = queryBuilder.SelectFrom("Page");
query = queryBuilder.Where(query, "Namespace", WhereOperator.Equals, "Namespace");
List<Parameter> parameters = new List<Parameter>(1);
parameters.Add(new Parameter(ParameterType.String, "Namespace", nspaceName));
query = queryBuilder.OrderBy(query, new[] { "Name" }, new[] { Ordering.Asc });
DbCommand command = builder.GetCommand(connection, query, parameters);
DbDataReader reader = ExecuteReader(command);
if(reader != null) {
List<PageInfo> result = new List<PageInfo>(100);
while(reader.Read()) {
result.Add(new PageInfo(NameTools.GetFullName(reader["Namespace"] as string, reader["Name"] as string),
this, (DateTime)reader["CreationDateTime"]));
}
CloseReader(reader);
return result.ToArray();
}
else return null;
}
示例4: GetCategoriesForPage
/// <summary>
/// Gets all the categories of a page.
/// </summary>
/// <param name="page">The page.</param>
/// <returns>The categories, sorted by name.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="page"/> is <c>null</c>.</exception>
public CategoryInfo[] GetCategoriesForPage(PageInfo page)
{
if(page == null) throw new ArgumentNullException("page");
ICommandBuilder builder = GetCommandBuilder();
QueryBuilder queryBuilder = new QueryBuilder(builder);
string nspace, pageName;
NameTools.ExpandFullName(page.FullName, out nspace, out pageName);
if(nspace == null) nspace = "";
string query = queryBuilder.SelectFrom("Category", "CategoryBinding", new string[] { "Name", "Namespace" }, new string[] { "Category", "Namespace" }, Join.LeftJoin,
new string[] { "Name", "Namespace" }, new string[] { "Page" });
query = queryBuilder.Where(query, "CategoryBinding", "Namespace", WhereOperator.Equals, "Namespace");
query = queryBuilder.AndWhere(query, "CategoryBinding", "Page", WhereOperator.Equals, "Page");
query = queryBuilder.OrderBy(query, new[] { "Category_Name" }, new[] { Ordering.Asc });
List<Parameter> parameters = new List<Parameter>(2);
parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));
parameters.Add(new Parameter(ParameterType.String, "Page", pageName));
DbCommand command = builder.GetCommand(connString, query, parameters);
DbDataReader reader = ExecuteReader(command);
if(reader != null) {
List<CategoryInfo> result = new List<CategoryInfo>(20);
List<string> pages = new List<string>(50);
string prevName = "|||";
string name = null;
while(reader.Read()) {
name = reader["Category_Name"] as string;
if(name != prevName) {
if(prevName != "|||") {
result[result.Count - 1].Pages = pages.ToArray();
pages.Clear();
}
result.Add(new CategoryInfo(NameTools.GetFullName(reader["Category_Namespace"] as string, name), this));
}
prevName = name;
if(!IsDBNull(reader, "CategoryBinding_Page")) {
pages.Add(NameTools.GetFullName(reader["Category_Namespace"] as string, reader["CategoryBinding_Page"] as string));
}
}
CloseReader(command, reader);
if(result.Count > 0) result[result.Count - 1].Pages = pages.ToArray();
return result.ToArray();
}
else return null;
}
示例5: GetUserGroups
/// <summary>
/// Gets the user groups of a user.
/// </summary>
/// <param name="transaction">A database transaction.</param>
/// <param name="username">The username.</param>
/// <returns>The groups.</returns>
private string[] GetUserGroups(DbTransaction transaction, string username)
{
ICommandBuilder builder = GetCommandBuilder();
QueryBuilder queryBuilder = new QueryBuilder(builder);
string query = queryBuilder.SelectFrom("UserGroupMembership", new string[] { "UserGroup" });
query = queryBuilder.Where(query, "User", WhereOperator.Equals, "Username");
queryBuilder.OrderBy(query, new[] { "UserGroup_Name" }, new[] { Ordering.Asc });
List<Parameter> parameters = new List<Parameter>(1);
parameters.Add(new Parameter(ParameterType.String, "Username", username));
DbCommand command = builder.GetCommand(transaction, query, parameters);
DbDataReader reader = ExecuteReader(command);
if(reader != null) {
List<string> result = new List<string>(5);
while(reader.Read()) {
result.Add(reader["UserGroup"] as string);
}
CloseReader(reader);
return result.ToArray();
}
else return null;
}
示例6: GetMessages
/// <summary>
/// Gets the Page Messages.
/// </summary>
/// <param name="connection">A database connection.</param>
/// <param name="page">The Page.</param>
/// <returns>The list of the <b>first-level</b> Messages, containing the replies properly nested, sorted by date/time.</returns>
private Message[] GetMessages(DbConnection connection, PageInfo page)
{
if(GetPage(connection, page.FullName) == null) return null;
// 1. Load all messages in memory in a dictionary id->message
// 2. Build tree using ParentID
string nspace, name;
NameTools.ExpandFullName(page.FullName, out nspace, out name);
if(nspace == null) nspace = "";
ICommandBuilder builder = GetCommandBuilder();
QueryBuilder queryBuilder = new QueryBuilder(builder);
string query = queryBuilder.SelectFrom("Message", new string[] { "Id", "Parent", "Username", "Subject", "DateTime", "Body" });
query = queryBuilder.Where(query, "Page", WhereOperator.Equals, "Page");
query = queryBuilder.AndWhere(query, "Namespace", WhereOperator.Equals, "Namespace");
query = queryBuilder.OrderBy(query, new string[] { "DateTime", "Id" }, new Ordering[] { Ordering.Asc, Ordering.Asc });
List<Parameter> parameters = new List<Parameter>(2);
parameters.Add(new Parameter(ParameterType.String, "Page", name));
parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));
DbCommand command = builder.GetCommand(connection, query, parameters);
DbDataReader reader = ExecuteReader(command);
if(reader != null) {
Dictionary<short, Message> allMessages = new Dictionary<short, Message>(50);
List<short> ids = new List<short>(50);
List<short?> parents = new List<short?>(50);
while(reader.Read()) {
Message msg = new Message((short)reader["Id"], reader["Username"] as string, reader["Subject"] as string,
(DateTime)reader["DateTime"], reader["Body"] as string);
ids.Add((short)msg.ID);
// Import from V2: parent = -1, otherwise null
if(!IsDBNull(reader, "Parent")) {
short par = (short)reader["Parent"];
if(par >= 0) parents.Add(par);
else parents.Add(null);
}
else parents.Add(null);
allMessages.Add((short)msg.ID, msg);
}
CloseReader(reader);
// Add messages to their parents and build the top-level messages list
List<Message> result = new List<Message>(20);
for(int i = 0; i < ids.Count; i++) {
short? currentParent = parents[i];
short currentId = ids[i];
if(currentParent.HasValue) {
List<Message> replies = new List<Message>(allMessages[currentParent.Value].Replies);
replies.Add(allMessages[currentId]);
allMessages[currentParent.Value].Replies = replies.ToArray();
}
else result.Add(allMessages[currentId]);
}
return result.ToArray();
}
else return null;
}
示例7: GetBackups
/// <summary>
/// Gets the Backup/Revision numbers of a Page.
/// </summary>
/// <param name="connection">A database connection.</param>
/// <param name="page">The Page to get the Backups of.</param>
/// <returns>The Backup/Revision numbers.</returns>
private int[] GetBackups(DbConnection connection, PageInfo page)
{
if(GetPage(connection, page.FullName) == null) {
return null;
}
string name, nspace;
NameTools.ExpandFullName(page.FullName, out nspace, out name);
if(nspace == null) nspace = "";
ICommandBuilder builder = GetCommandBuilder();
QueryBuilder queryBuilder = new QueryBuilder(builder);
string query = queryBuilder.SelectFrom("PageContent", new string[] { "Revision" });
query = queryBuilder.Where(query, "Page", WhereOperator.Equals, "Page");
query = queryBuilder.AndWhere(query, "Namespace", WhereOperator.Equals, "Namespace");
query = queryBuilder.AndWhere(query, "Revision", WhereOperator.GreaterThanOrEqualTo, "Revision");
query = queryBuilder.OrderBy(query, new[] { "Revision" }, new[] { Ordering.Asc });
List<Parameter> parameters = new List<Parameter>(3);
parameters.Add(new Parameter(ParameterType.String, "Page", name));
parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));
parameters.Add(new Parameter(ParameterType.Int16, "Revision", FirstRevision));
DbCommand command = builder.GetCommand(connection, query, parameters);
DbDataReader reader = ExecuteReader(command);
if(reader != null) {
List<int> result = new List<int>(100);
while(reader.Read()) {
result.Add((short)reader["Revision"]);
}
CloseReader(reader);
return result.ToArray();
}
else return null;
}
示例8: GetPagesWithAttachments
/// <summary>
/// The the names of the pages with attachments.
/// </summary>
/// <returns>The names of the pages with attachments.</returns>
public string[] GetPagesWithAttachments()
{
ICommandBuilder builder = GetCommandBuilder();
QueryBuilder queryBuilder = new QueryBuilder(builder);
string query = queryBuilder.SelectFrom("Attachment", new string[] { "Page" });
query = queryBuilder.GroupBy(query, new[] { "Page" });
query = queryBuilder.OrderBy(query, new[] { "Page" }, new[] { Ordering.Asc });
DbCommand command = builder.GetCommand(connString, query, new List<Parameter>());
DbDataReader reader = ExecuteReader(command);
if(reader != null) {
List<string> result = new List<string>(100);
while(reader.Read()) {
result.Add(reader["Page"] as string);
}
CloseReader(command, reader);
return result.ToArray();
}
else return null;
}
示例9: GetRecentChanges
/// <summary>
/// Gets the recent changes of the Wiki.
/// </summary>
/// <returns>The recent Changes, oldest to newest.</returns>
public RecentChange[] GetRecentChanges()
{
ICommandBuilder builder = GetCommandBuilder();
QueryBuilder queryBuilder = new QueryBuilder(builder);
string query = queryBuilder.SelectFrom("RecentChange", new string[] { "Page", "Title", "MessageSubject", "DateTime", "User", "Change", "Description" });
query = queryBuilder.OrderBy(query, new string[] { "DateTime" }, new Ordering[] { Ordering.Asc });
DbCommand command = builder.GetCommand(connString, query, new List<Parameter>());
DbDataReader reader = ExecuteReader(command);
if(reader != null) {
List<RecentChange> result = new List<RecentChange>(100);
while(reader.Read()) {
result.Add(new RecentChange(reader["Page"] as string, reader["Title"] as string,
GetNullableColumn<string>(reader, "MessageSubject", ""),
(DateTime)reader["DateTime"], reader["User"] as string, RecentChangeFromChar(((string)reader["Change"])[0]),
GetNullableColumn<string>(reader, "Description", "")));
}
CloseReader(command, reader);
return result.ToArray();
}
else return null;
}
示例10: AddMessage
/// <summary>
/// Adds a new Message to a Page.
/// </summary>
/// <param name="page">The Page.</param>
/// <param name="username">The Username.</param>
/// <param name="subject">The Subject.</param>
/// <param name="dateTime">The Date/Time.</param>
/// <param name="body">The Body.</param>
/// <param name="parent">The Parent Message ID, or -1.</param>
/// <returns>True if the Message is added successfully.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="page"/>, <paramref name="username"/>, <paramref name="subject"/> or <paramref name="body"/> are <c>null</c>.</exception>
/// <exception cref="ArgumentException">If <paramref name="username"/> or <paramref name="subject"/> are empty.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="parent"/> is less than -1.</exception>
public bool AddMessage(PageInfo page, string username, string subject, DateTime dateTime, string body, int parent)
{
if(page == null) throw new ArgumentNullException("page");
if(username == null) throw new ArgumentNullException("username");
if(username.Length == 0) throw new ArgumentException("Username cannot be empty", "username");
if(subject == null) throw new ArgumentNullException("subject");
if(subject.Length == 0) throw new ArgumentException("Subject cannot be empty", "subject");
if(body == null) throw new ArgumentNullException("body"); // body can be empty
if(parent < -1) throw new ArgumentOutOfRangeException("parent", "Invalid Parent Message ID");
string nspace, name;
NameTools.ExpandFullName(page.FullName, out nspace, out name);
if(nspace == null) nspace = "";
ICommandBuilder builder = GetCommandBuilder();
DbConnection connection = builder.GetConnection(connString);
DbTransaction transaction = BeginTransaction(connection);
if(parent != -1 && FindMessage(GetMessages(transaction, page), parent) == null) {
RollbackTransaction(transaction);
return false;
}
QueryBuilder queryBuilder = new QueryBuilder(builder);
short freeId = -1;
string query = queryBuilder.SelectFrom("Message", new string[] { "Id" });
query = queryBuilder.Where(query, "Page", WhereOperator.Equals, "Page");
query = queryBuilder.AndWhere(query, "Namespace", WhereOperator.Equals, "Namespace");
query = queryBuilder.OrderBy(query, new string[] { "Id" }, new Ordering[] { Ordering.Desc });
List<Parameter> parameters = new List<Parameter>(2);
parameters.Add(new Parameter(ParameterType.String, "Page", name));
parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));
DbCommand command = builder.GetCommand(transaction, query, parameters);
freeId = ExecuteScalar<short>(command, -1, false);
if(freeId == -1) freeId = 0;
else freeId++;
query = queryBuilder.InsertInto("Message", new string[] { "Page", "Namespace", "Id", "Parent", "Username", "Subject", "DateTime", "Body" },
new string[] { "Page", "Namespace", "Id", "Parent", "Username", "Subject", "DateTime", "Body" });
parameters = new List<Parameter>(8);
parameters.Add(new Parameter(ParameterType.String, "Page", name));
parameters.Add(new Parameter(ParameterType.String, "Namespace", nspace));
parameters.Add(new Parameter(ParameterType.Int16, "Id", freeId));
if(parent != -1) parameters.Add(new Parameter(ParameterType.Int16, "Parent", parent));
else parameters.Add(new Parameter(ParameterType.Int16, "Parent", DBNull.Value));
parameters.Add(new Parameter(ParameterType.String, "Username", username));
parameters.Add(new Parameter(ParameterType.String, "Subject", subject));
parameters.Add(new Parameter(ParameterType.DateTime, "DateTime", dateTime));
parameters.Add(new Parameter(ParameterType.String, "Body", body));
command = builder.GetCommand(transaction, query, parameters);
int rows = ExecuteNonQuery(command, false);
if(rows == 1) {
IndexMessage(page, freeId, subject, dateTime, body, transaction);
CommitTransaction(transaction);
return true;
}
else {
RollbackTransaction(transaction);
return false;
}
}
示例11: GetOutgoingLinks
/// <summary>
/// Gets the outgoing links of a page.
/// </summary>
/// <param name="page">The full name of the page.</param>
/// <returns>The outgoing links.</returns>
/// <exception cref="ArgumentNullException">If <b>page</b> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">If <b>page</b> is empty.</exception>
public string[] GetOutgoingLinks(string page)
{
if(page == null) throw new ArgumentNullException("page");
if(page.Length == 0) throw new ArgumentException("Page cannot be empty", "page");
ICommandBuilder builder = GetCommandBuilder();
QueryBuilder queryBuilder = new QueryBuilder(builder);
string query = queryBuilder.SelectFrom("OutgoingLink", new string[] { "Destination" });
query = queryBuilder.Where(query, "Source", WhereOperator.Equals, "Source");
query = queryBuilder.OrderBy(query, new[] { "Destination" }, new[] { Ordering.Asc });
List<Parameter> parameters = new List<Parameter>(1);
parameters.Add(new Parameter(ParameterType.String, "Source", page));
DbCommand command = builder.GetCommand(connString, query, parameters);
DbDataReader reader = ExecuteReader(command);
if(reader != null) {
List<string> result = new List<string>(20);
while(reader.Read()) {
result.Add(reader["Destination"] as string);
}
CloseReader(command, reader);
return result.ToArray();
}
else return null;
}
示例12: GetLogEntries
/// <summary>
/// Gets all the Log Entries, sorted by date/time (oldest to newest).
/// </summary>
/// <returns>The Log Entries.</returns>
public LogEntry[] GetLogEntries()
{
ICommandBuilder builder = GetCommandBuilder();
QueryBuilder queryBuilder = new QueryBuilder(builder);
string query = queryBuilder.SelectFrom("Log", new string[] { "DateTime", "EntryType", "User", "Message" });
query = queryBuilder.OrderBy(query, new string[] { "DateTime" }, new Ordering[] { Ordering.Asc });
DbCommand command = builder.GetCommand(connString, query, new List<Parameter>());
DbDataReader reader = ExecuteReader(command);
if(reader != null) {
List<LogEntry> result = new List<LogEntry>(100);
while(reader.Read()) {
result.Add(new LogEntry(EntryTypeFromChar((reader["EntryType"] as string)[0]),
(DateTime)reader["DateTime"], reader["Message"] as string, reader["User"] as string));
}
CloseReader(command, reader);
return result.ToArray();
}
else return null;
}
示例13: CutRecentChangesIfNecessary
/// <summary>
/// Cuts the recent changes if necessary.
/// </summary>
private void CutRecentChangesIfNecessary()
{
ICommandBuilder builder = GetCommandBuilder();
DbConnection connection = builder.GetConnection(connString);
DbTransaction transaction = BeginTransaction(connection);
QueryBuilder queryBuilder = new QueryBuilder(builder);
string query = queryBuilder.SelectCountFrom("RecentChange");
DbCommand command = builder.GetCommand(transaction, query, new List<Parameter>());
int rows = ExecuteScalar<int>(command, -1, false);
int maxChanges = int.Parse(host.GetSettingValue(SettingName.MaxRecentChanges));
if(rows > maxChanges) {
// Remove 10% of old changes to avoid 1-by-1 deletion every time a change is made
int entriesToDelete = maxChanges / 10;
if(entriesToDelete > rows) entriesToDelete = rows;
//entriesToDelete += entriesToDelete / 10;
// This code is not optimized, but it surely works in most DBMS
query = queryBuilder.SelectFrom("RecentChange", new string[] { "Id" });
query = queryBuilder.OrderBy(query, new string[] { "Id" }, new Ordering[] { Ordering.Asc });
command = builder.GetCommand(transaction, query, new List<Parameter>());
DbDataReader reader = ExecuteReader(command);
List<int> ids = new List<int>(entriesToDelete);
if(reader != null) {
while(reader.Read() && ids.Count < entriesToDelete) {
ids.Add((int)reader["Id"]);
}
CloseReader(reader);
}
if(ids.Count > 0) {
// Given that the IDs to delete can be many, the query is split in many chunks, each one deleting 50 items
// This works-around the problem of too many parameters in a RPC call of SQL Server
// See also CutLog
for(int chunk = 0; chunk <= ids.Count / MaxParametersInQuery; chunk++) {
query = queryBuilder.DeleteFrom("RecentChange");
List<string> parms = new List<string>(MaxParametersInQuery);
List<Parameter> parameters = new List<Parameter>(MaxParametersInQuery);
for(int i = chunk * MaxParametersInQuery; i < Math.Min(ids.Count, (chunk + 1) * MaxParametersInQuery); i++) {
parms.Add("P" + i.ToString());
parameters.Add(new Parameter(ParameterType.Int32, parms[parms.Count - 1], ids[i]));
}
query = queryBuilder.WhereIn(query, "Id", parms.ToArray());
command = builder.GetCommand(transaction, query, parameters);
if(ExecuteNonQuery(command, false) < 0) {
RollbackTransaction(transaction);
return;
}
}
}
}
CommitTransaction(transaction);
}
示例14: ListDirectories
/// <summary>
/// Lists the Directories in the specified directory.
/// </summary>
/// <param name="transaction">A database transaction.</param>
/// <param name="directory">The full directory name, for example "/my/directory". Null, empty or "/" for the root directory.</param>
/// <returns>The list of Directories in the Directory.</returns>
private string[] ListDirectories(DbTransaction transaction, string directory)
{
directory = PrepareDirectory(directory);
ICommandBuilder builder = GetCommandBuilder();
if(!DirectoryExists(transaction, directory)) {
RollbackTransaction(transaction);
throw new ArgumentException("Directory does not exist", "directory");
}
QueryBuilder queryBuilder = new QueryBuilder(builder);
string query = queryBuilder.SelectFrom("Directory", new string[] { "FullPath" });
query = queryBuilder.Where(query, "Parent", WhereOperator.Equals, "Parent");
List<Parameter> parameters = new List<Parameter>(1);
parameters.Add(new Parameter(ParameterType.String, "Parent", directory));
query = queryBuilder.OrderBy(query, new[] { "FullPath" }, new[] { Ordering.Asc });
DbCommand command = builder.GetCommand(transaction, query, parameters);
DbDataReader reader = ExecuteReader(command);
if(reader != null) {
List<string> result = new List<string>(20);
while(reader.Read()) {
result.Add(reader["FullPath"] as string);
}
CloseReader(reader);
return result.ToArray();
}
else return null;
}
示例15: GetCategories
/// <summary>
/// Gets all the Categories in a namespace.
/// </summary>
/// <param name="connection">A database connection.</param>
/// <param name="nspace">The namespace.</param>
/// <returns>All the Categories in the namespace. The array is not sorted.</returns>
private CategoryInfo[] GetCategories(DbConnection connection, NamespaceInfo nspace)
{
string nspaceName = nspace != null ? nspace.Name : "";
ICommandBuilder builder = GetCommandBuilder();
QueryBuilder queryBuilder = new QueryBuilder(builder);
string query = queryBuilder.SelectFrom("Category", "CategoryBinding", new string[] { "Name", "Namespace" }, new string[] { "Category", "Namespace" }, Join.LeftJoin,
new string[] { "Name", "Namespace" }, new string[] { "Page" });
query = queryBuilder.Where(query, "Category", "Namespace", WhereOperator.Equals, "Namespace");
query = queryBuilder.OrderBy(query, new string[] { "Category_Name", "CategoryBinding_Page" }, new Ordering[] { Ordering.Asc, Ordering.Asc });
List<Parameter> parameters = new List<Parameter>(1);
parameters.Add(new Parameter(ParameterType.String, "Namespace", nspaceName));
DbCommand command = builder.GetCommand(connection, query, parameters);
DbDataReader reader = ExecuteReader(command);
if(reader != null) {
List<CategoryInfo> result = new List<CategoryInfo>(20);
List<string> pages = new List<string>(50);
string prevName = "|||";
string name = null;
while(reader.Read()) {
name = reader["Category_Name"] as string;
if(name != prevName) {
if(prevName != "|||") {
result[result.Count - 1].Pages = pages.ToArray();
pages.Clear();
}
result.Add(new CategoryInfo(NameTools.GetFullName(reader["Category_Namespace"] as string, name), this));
}
prevName = name;
if(!IsDBNull(reader, "CategoryBinding_Page")) {
pages.Add(NameTools.GetFullName(reader["Category_Namespace"] as string, reader["CategoryBinding_Page"] as string));
}
}
CloseReader(reader);
if(result.Count > 0) result[result.Count - 1].Pages = pages.ToArray();
return result.ToArray();
}
else return null;
}