how to rename record names/keys

186 views
Skip to first unread message

Teresa Lea

unread,
Jun 17, 2008, 9:49:24 PM6/17/08
to jb...@googlegroups.com
is there any way to rename record names or record keys in jBASE files ?

thanks.
Lea

付費才容量無上限?Yahoo!奇摩電子信箱2.0免費給你,信件永遠不必刪! - 馬上體驗

Peter McBride

unread,
Jun 18, 2008, 1:12:24 AM6/18/08
to jB...@googlegroups.com

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  1152Geelong, 3220
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ :-#)


Teresa Lea

unread,
Jun 18, 2008, 2:08:02 AM6/18/08
to jb...@googlegroups.com
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 rmore 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" ?

REC001   ------>     RECORD01

REC002   ------>     RECORD02

REC003   ------>     RECORD03

OTHER1  ------->    OTHER1  

should I run that command for every single record one by one ?

Regards,
Lea

Peter McBride

unread,
Jun 18, 2008, 2:31:25 AM6/18/08
to jB...@googlegroups.com

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:

Simon Verona

unread,
Jun 18, 2008, 2:47:12 AM6/18/08
to jB...@googlegroups.com

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

 

Simon Verona.vcf

Teresa Lea

unread,
Jun 18, 2008, 2:51:20 AM6/18/08
to jb...@googlegroups.com
Got it Peter, I was wondering if jBASE could accept string manipulation syntax like REPLACE REC* --> RECORD*, but it's clear now.
Thanks peter, your suggestion helps me alot.

Regards,
Lea

Jim Idle

unread,
Jun 18, 2008, 11:12:00 AM6/18/08
to jB...@googlegroups.com
On Wed, 2008-06-18 at 16:31 +1000, Peter McBride wrote:
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.

Yep - however this is a good opportunity to point out that the 4.1 jBC compiler has constructs in BASIC for executing a jQL command (which on 4.1 is nearly as fast as hand coding it, and is faster than some hand coding I have seen ;-), and iterating the result sets. As we can see from the huge number of query statements embedded in jBC/BASIC programs, this seems to be easier than coding the same thing in jBC for many programmers (you can see why really).

For details, see the manual at:

http://www.jbase.com/support/41docs/jBASE%20Query%20Language.pdf

And look at the section:

BASIC Statements for use with jQL. This manual is in PDF format only unfortunately, which means it is terrible to search and so on. However it becomes manageable if you use the free version of FoxIt PDF reader rather than the abysmal adobe one (which will ask you to install an update every time you start it ;-).

Using this interface, you can also write your own verb, say RENAME, that is more generic in nature.

Jim

Jim Idle

unread,
Jun 18, 2008, 11:14:19 AM6/18/08
to jB...@googlegroups.com
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

Teresa Lea

unread,
Jun 18, 2008, 9:28:16 PM6/18/08
to jb...@googlegroups.com
yeah you are right, the coding for bulk renaming process can be a "looping forever" process if we never trap the processed ones.

Thanks Simon.

Regards,
Lea

Simon Verona 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

 

 

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.

Teresa Lea

unread,
Jun 18, 2008, 9:51:57 PM6/18/08
to jb...@googlegroups.com
Thanks Jim.
I will download the manual, it's a quite interesting one if it's more efficient than infobasic coding as you said.

And it's a good thing also that I'm using FoxitPDF, not the other one .. :-)

Regards,
Lea

Jim Idle wrote:
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

Reply all
Reply to author
Forward
0 new messages