分类:
2009-11-26 15:39:17
kind_pro
DELIMITER $$
DROP PROCEDURE IF EXISTS `studb`.`kind_pro` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `kind_pro`(in kindtype varchar(10))
BEGIN
select kind_id,kind_name from kind where kind_type = kindtype;
END $$
DELIMITER ;
GetRecordCount
DELIMITER $$
DROP PROCEDURE IF EXISTS `studb`.`GetRecordCount` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `GetRecordCount`(in tbName varchar(800),in strWhere varchar(500))
BEGIN
set @strSQL=concat('select count(*) as countStr from ',tbName,strWhere);
prepare sqlstmt from @strSQL;
execute sqlstmt;
deallocate prepare sqlstmt;
END $$
DELIMITER ;
GetRecordAsPage
DELIMITER $$
DROP PROCEDURE IF EXISTS `studb`.`GetRecordAsPage` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `GetRecordAsPage`(in tbName varchar(800),in fldName varchar(1000),
in strWhere varchar(500),in pageIndex int,in pageSize int,in orderType int,in sortName varchar(50))
BEGIN
declare startRow int;
declare sqlStr varchar(1000);
declare limitTemp varchar(1000);
declare orderTemp varchar(1000);
set startRow = (pageIndex-1)*pageSize;
set sqlStr = CONCAT('SELECT ',fldName,' from ',tbName);
set limitTemp = CONCAT(' limit ',startRow,',',pageSize);
set orderTemp = CONCAT(' order by ',sortName);
if orderType = 0 then
set orderTemp = CONCAT(orderTemp,' ASC ');
else
set orderTemp = CONCAT(orderTemp,' DESC ');
end if;
set @sqlString = CONCAT(sqlStr,' ',strWhere,orderTemp,limitTemp);
prepare sqlstmt from @sqlString;
execute sqlstmt;
deallocate prepare sqlstmt;
END $$
DELIMITER ;