myShellScript

Pagination + Informix

INFORMIXDIR=/usr/informix
rowCount="your saved row count"
# safe the row count in a temp txt file
(
$INFORMIXDIR/bin/isql -s ??<<!EOF
set isolation to dirty read;
unload to '${rowCount}' 
select count(*) from ?? where dt between date('08/08/2008') and date('08/08/2008');
!EOF
)
COUNTER=0
#row count
for tmp in `awk '{print $1}' ${rowCount}`
do 
   COUNTER=`echo $tmp|cut -d "." -f1`
done

pageSize=100
offset=1
lastPageOffset=0

until [ offset -gt $COUNTER ]
do	
## start SQL
echo $offset
(
$INFORMIXDIR/bin/isql -s ??<<!EOF
set isolation to dirty read;       
unload to  '/${ENV}/??/lib/download/??/??.csv' DELIMITER ','   
select SKIP ${offset} FIRST ${pageSize} * from ??
where dt between date('08/08/2008') and date('08/08/2008')
;
!EOF
)
## end SQL
   	offset=`expr $offset + $pageSize`
   	if [ $offset -gt $COUNTER ] 
   	then
   		lastPageOffset=`expr $offset - $pageSize`
   		break
   	fi
done
## handle last page
if [ $lastPageOffset -gt 0 ]
then
	echo "this is last page"
	echo $lastPageOffset
## s
	(
$INFORMIXDIR/bin/isql -s ??<<!EOF
set isolation to dirty read;       
unload to  '/${ENV}/??/lib/download/??/??.csv' DELIMITER ','   
select SKIP ${offset} FIRST ${pageSize} * from ??
where dt between date('08/08/2008') and date('08/08/2008')
;
!EOF
)
fi

你可能感兴趣的:(myShellScript)