<建立表> CREATE TABLE (ctablename) ( curl M , ctext M , ldowned I , threadNum I )
&&建立一个表ctablename.dbf,含有地址、文本内容、已经尝试下载次数、
线程标志(初值为-1,线程标志是从0开始的整数)四个字段 <提取Url地址> cfullname = (ctablename) + '.dbf'&&为表添加扩展名 USE (cfullname) GO TOP LOCATE FOR (EMPTY( ALLTRIM( ctext ) ) AND ldowned < 2 AND
( threadNum = thisNum OR threadNum = - 1) )
&&查找尚未下载成功且应下载的属于本线程权限的Url地址,thisNum是当前线程的编号,
可以通过参数传递得到 gotUrl = curl recNum = RECNO() IF recNum <= RECCOUNT() THEN &&如果在列表中找到这样的Url地址 UPDATE (cfullname) SET ldowned = ( ldowned + 1 ) , threadNum =
thisNum WHERE RECNO() = recNum &&更新表,将此记录更新为已申请,即下载次数加1,
线程标志列设为本线程的编号。
<下载内容> cfulltablename = (ctablename) + '.dbf' USE (cfulltablename) SET EXACT ON LOCATE FOR curl = (csiteurl) && csiteurl是参数,为下载到的内容所对应的Url地址 recNumNow = RECNO()&&得到含有此地址的记录号 UPDATE (cfulltablename) SET ctext = (ccontent) WHERE RECNO() =
recNumNow &&插入对应地址的对应内容
<插入新地址> ctablename = (ctablename) + '.dbf' USE (ctablename) GO TOP SET EXACT ON LOCATE FOR curl = (cnewurl) &&查找有无此地址 IF RECNO() > RECCOUNT() THEN &&如果尚无此地址 SET CARRY OFF INSERT INTO (ctablename) ( curl , ctext , ldowned , threadNum )