plz help understand this query

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
8/20/2007 5:00:30 PM
Gravatar
Total Posts 22

plz help understand this query

the first parameter in the array is PageNumber, but it is not used in the query... am I missing something?

btw, what is the method for?

thank you
Federico

--
from trunk\mojoPortal.Data.MySql\dbPortal.cs: 

public static IDataReader SiteUser_GetUserListPage(
int siteID,
int pageNumber,
int pageSize,
string userNameBeginsWith)
{
StringBuilder sqlCommand = new StringBuilder();
int pageLowerBound = (pageSize * pageNumber) - pageSize;
int totalRows
= SiteUser_Count(siteID, userNameBeginsWith);

sqlCommand.Append("SET @TotalRows = "
+ totalRows.ToString(CultureInfo.InvariantCulture) + ";");
sqlCommand.Append("SET @TotalPages = CEILING(@TotalRows / ?PageSize) ;");

sqlCommand.Append("SELECT u.*, ");
sqlCommand.Append("@TotalPages As TotalPages ");
sqlCommand.Append("FROM mp_Users u ");

sqlCommand.Append("WHERE u.ProfileApproved = 1 ");
sqlCommand.Append("AND u.SiteID = ?SiteID = 1 ");

if (userNameBeginsWith.Length > 0)
{
sqlCommand.Append(" AND u.Name LIKE ?UserNameBeginsWith ");
}

sqlCommand.Append(" ORDER BY u.Name ");
sqlCommand.Append("LIMIT " + pageLowerBound.ToString(CultureInfo.InvariantCulture) + ", ?PageSize ; ");

MySqlParameter[] arParams = new MySqlParameter[4];

arParams[0] = new MySqlParameter("?PageNumber", MySqlDbType.Int32);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = pageNumber;

arParams[1] = new MySqlParameter("?PageSize", MySqlDbType.Int32);
arParams[1].Direction = ParameterDirection.Input;
arParams[1].Value = pageSize;

arParams[2] = new MySqlParameter("?UserNameBeginsWith", MySqlDbType.VarChar, 50);
arParams[2].Direction = ParameterDirection.Input;
arParams[2].Value = userNameBeginsWith + "%";

arParams[3] = new MySqlParameter("?SiteID", MySqlDbType.Int32);
arParams[3].Direction = ParameterDirection.Input;
arParams[3].Value = siteID;

return MySqlHelper.ExecuteReader(
GetConnectionString(),
sqlCommand.ToString(),
arParams);

}

 

8/20/2007 5:23:15 PM
Gravatar
Total Posts 18439

Re: plz help understand this query

Well it may not be the most elegant code, but it selects a page of users and is used on the memberlist.aspx page.

Although pagenumber is not used in the query, it is used to calculate pageLowerBounds variable which is used as the OFFSET in the LIMIT clause.

You are right that PageNumber is being passed as a param but not used. I need to clean that up, it was used in a previous implementation.

Joe

You must sign in to post in the forums. This thread is closed to new posts.