| 付費才容量無上限?Yahoo!奇摩電子信箱2.0免費給你,信件永遠不必刪! - 馬上體驗! |
Lea.
Can you supply a bit more information, about the version of Jbase you are running and the computer’s operating system ?
The “record key” in PICK type databases is called the “Item ID”. It does not have to be a sequential number, assigned by the database.
Start-up a Jbase shell prompt.
COPY file-name item-name ( D )
> new-item-name
e.g.
COPY TOWNS-FILE MELBOURNE (D)
> GEELONG
The (D) option, means that the original Item is deleted.
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
:-)
Peter W. McBride - Analyst / Programmer ( Jbase/Pick/Unix -
25 yrs )
Business Name:
MO-Soft (
ABN: 95 937 375 489 )
Smail: Peter McBride, P.O.
Box 1152, Geelong,
3220
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ :-#)
Lea
The COPY command, when used at the jShell prompt, allows for multiple items to be listed. I find it gets a bit unpractical, after typing a dozen Item ID’s ; and you are normally limited to an input buffer of 256 chars.
e.g. “Rename” 5 records, by using the (D) for delete option.
COPY File-name REC001 REC002 REC003 REC004 REC005 (D)
> RECORD001 RECORD002 RECORD003 RECORD004 RECORD005
In the case of several hundred records, to be renamed, I suggest writing a DataBasic program, with a bit of pattern recognition. Inside the Basic program, you would SELECT the original file ( or hand the basic program a list of records ) ; processing each record, one by one.
e.g. READ the entire record. If the Item-ID started with “RECxxx”, create your new Item-ID with “RECORDxxx”. WRITE the new record to the file, using the new Item-ID. DELETE the old record from the file, using the original Item-ID.
Sorry, if my explanation is a bit long winded. Hopefully another Jbaser from our forum will have a simpler / quicker idea.
From:
jB...@googlegroups.com [mailto:jB...@googlegroups.com] On Behalf Of Teresa Lea
Sent: Wednesday, 18 June 2008
16:08
To: jb...@googlegroups.com
Subject: Re: how to rename record
names/keys
Hi Peter,
I'm in jBASE4, windows xp professional.
I've tried it, it works all right. Thanks Peter.
Any idea how can I rename more than one record name with the same specific condition, e.g. : I want to rename all record names that begins with "REC", replace with "RECORD" ?
Peter McBride wrote:
Just one interesting point about writing a jbase program to do this.
The temptation is perhaps to write code like:
001 OPEN ‘FILE’ TO MyFile ELSE STOP 201,’FILE’
002 SELECT MyFile TO MySelectList
003 LOOP WHILE READNEXT Id FROM MySelectList DO
004 IF Id[1,3]=’REC’ THEN
005 READU Item FROM MyFile,Id ELSE Item=’’
006 NewId=’RECORD’:Id[4,999]
007 READU Junk FROM MyFile,NewId ELSE Junk=’’ ; *** I’m ignoring the possibility that the new record may already exist
008 WRITE Item ON MyFile,NewId
009 DELETE MyFile,Id
010 REPEAT
This will potentially end up with the unforeseen problem of REC1 being renamed RECORDORD1
This is due to the way the SELECT statement at line 2 works, in that in rolls through the file in realtime. As you are creating new records in the file, there is the possibility that the new record will be later in the file than the original, and will be picked up later by the READNEXT and get processed again!!
To ensure that this doesn’t happen, you need to replace the SELECT with something like :
002 EXECUTE ‘SELECT FILE’ RETURNING MySelectList
Or for those that prefer the syntax (I’m one of them):
002 EXECUTE ‘SELECT FILE’
003 IF SYSTEM(11) THEN SELECT TO MySelectList ELSE STOP
Just an aside, but it’s caught me out on many occasion!
Simon
Lea
The COPY command, when used at the jShell prompt, allows for multiple items to be listed. I find it gets a bit unpractical, after typing a dozen Item ID’s ; and you are normally limited to an input buffer of 256 chars.
Or for those that prefer the syntax (I’m one of them):
002 EXECUTE ‘SELECT FILE’
003 IF SYSTEM(11) THEN SELECT TO MySelectList ELSE STOP
Just one interesting point about writing a jbase program to do this.
The temptation is perhaps to write code like:
001 OPEN ‘FILE’ TO MyFile ELSE STOP 201,’FILE’
002 SELECT MyFile TO MySelectList
003 LOOP WHILE READNEXT Id FROM MySelectList DO
004 IF Id[1,3]=’REC’ THEN
005 READU Item FROM MyFile,Id ELSE Item=’’
006 NewId=’RECORD’:Id[4,999]
007 READU Junk FROM MyFile,NewId ELSE Junk=’’ ; *** I’m ignoring the possibility that the new record may already exist
008 WRITE Item ON MyFile,NewId
009 DELETE MyFile,Id
010 REPEAT
This will potentially end up with the unforeseen problem of REC1 being renamed RECORDORD1
This is due to the way the SELECT statement at line 2 works, in that in rolls through the file in realtime. As you are creating new records in the file, there is the possibility that the new record will be later in the file than the original, and will be picked up later by the READNEXT and get processed again!!
To ensure that this doesn’t happen, you need to replace the SELECT with something like :
002 EXECUTE ‘SELECT FILE’ RETURNING MySelectList
Or for those that prefer the syntax (I’m one of them):
002 EXECUTE ‘SELECT FILE’
003 IF SYSTEM(11) THEN SELECT TO MySelectList ELSE STOP
Just an aside, but it’s caught me out on many occasion!
Simon
From: jB...@googlegroups.com [mailto:jB...@googlegroups.com] On Behalf Of Peter McBride
Sent: 18 June 2008 07:31
To: jB...@googlegroups.com
Subject: RE: how to rename record names/keys
Lea
The COPY command, when used at the jShell prompt, allows for multiple items to be listed. I find it gets a bit unpractical, after typing a dozen Item ID’s ; and you are normally limited to an input buffer of 256 chars.
e.g. “Rename” 5 records, by using the (D) for delete option.
On Wed, 2008-06-18 at 07:47 +0100, Simon Verona wrote:
Or for those that prefer the syntax (I’m one of them):
002 EXECUTE ‘SELECT FILE’
003 IF SYSTEM(11) THEN SELECT TO MySelectList ELSE STOP
It is much more efficient to code:
EXECUTE "SELECT FILE" RTNLIST MySelectList
IF SYSTEM(11) THEN
....
END
and the 4.1 JQLCOMPILE() etc is even more efficient.
Jim