Index: /branches/rel_ag_9_4_0_493_tw/ui/localcmd/ui_localdb.c
===================================================================
--- /branches/rel_ag_9_4_0_493_tw/ui/localcmd/ui_localdb.c	(revision 20236)
+++ /branches/rel_ag_9_4_0_493_tw/ui/localcmd/ui_localdb.c	(working copy)
@@ -3568,6 +3568,8 @@
 	};
 	ldb_conn_t *conn;
 	ldb_result_t *result = NULL;
+        // JasonChou add string strnum
+        char *strnum;
 	int i,j,k, columncount = 1, haveforce = -1, havemanual = -1, firstcount = 0, group_acc_count = 0,nowcount = 1, col_pos[12] = {0};
 	char *stmp, sql[3072] = "", strcol[64] = "", upcolumn[16] = "";
 	char limitstr[64] = "", new_username[USERNAME_LEN*5] = "", new_groupname[GROUPNAME_LEN*3] = "";
@@ -3813,17 +3815,47 @@
 	    return -1;
 	}
 	if (start > 1) {
-		sprintf(sql,"SELECT count(distinct a.user_name) from %s as a  %s %s ;", LDB_VIEW_AUTH_USER, groupstr, condition);
-		group_acc_count = get_sql_res_num(sql, conn, iswebui, username);
+		sprintf(sql,"SELECT count(distinct a.user_name) from %s as a %s %s ;", LDB_VIEW_AUTH_USER, groupstr, condition);
+                // JasonChou replace function group_acc_count by ldbq_exec_one_no_escape
+		//group_acc_count = get_sql_res_num(sql, conn, iswebui, username);
+                ldbq_exec_one_no_escape(conn, "%s", createfunction);
+                result = ldbq_exec_one_no_escape(conn, "%s", sql);
+                ldbq_exec_one_no_escape(conn, "%s", dropaggregate);
+                if (result == NULL) {
+	            ldb_englog(__FUNCTION__, "Fail to execute selete command: result is null.");
+	            ui_fail(ERR_LOCALDB_FAIL_EXEC, ERR_LOCALDB_FAIL_EXEC_INFO);
+	            ldbq_close_conn(conn);
+	            return -1;
+                } else if (result->status != LDB_RES_SUCCESS) {
+	            ldb_englog(__FUNCTION__, "Fail to execute selete command.");
+	            ui_fail(ERR_LOCALDB_FAIL_EXEC, ERR_LOCALDB_FAIL_EXEC_INFO);
+	            ldbq_clear_res(result);
+	            ldbq_close_conn(conn);
+	            return -1;
+	        } else if (result->size == 0 && username && *username != '\0') {
+		    ldb_englog(__FUNCTION__, "Fail to find given account %s.", username);
+		    ui_fail(ERR_LOCALDB_USER_NOT_FOUND, ERR_LOCALDB_USER_NOT_FOUND_INFO, username);
+		    ldbq_clear_res(result);
+		    ldbq_close_conn(conn);
+		    return -1;
+	        }
+                strnum = ldbq_get_value(result, 0, 0);
+	        ldbq_clear_res(result);
+	        if(strnum && *strnum != '\0' ) {
+		    group_acc_count = atoi(strnum);
+	        }
+                else {
+                    return -1;
+                } 
 		if(group_acc_count  < 0) {
-			return -1;
+		    return -1;
 		}
 		if(group_acc_count < start) {
-			if(!iswebui) {
-				ldbq_close_conn(conn);
-				return -1;
-			}
-			jumpfirst = 1;
+		    if(!iswebui) {
+			ldbq_close_conn(conn);
+			return -1;
+		}
+		    jumpfirst = 1;
 		} 
 		stmp = limitstr + strlen(limitstr);
 		sprintf(stmp, " offset %d", start - 1);
