Groups > Superbase > Superbase 2 programming > Re: update syntax




update syntax

update syntax
Mon, 23 Jan 2006 10:36:51 -050
I have a text field that refers to an externalfile photo on drive D:. An 
example would be D:\lr\chair.jpg. I recently got a new pc and only have 
opne drive C:. What would be the update command to change the date in 
all records so that the first 2  letters of the data would be C: instead 
of D: ? Tnanks.
Post Reply
Re: update syntax
Mon, 23 Jan 2006 15:26:27 -050
Something like:

  UPDATE extfield.MYFILE = "C" + MID$(extfield.MYFILE,2)
   WHERE LEFT$(extfield.MYFILE,1) LIKE "d"
   END UPDATE

Experiment in the Code Editor (<alt+F2>) by trying this sort of code:

cls
a$ = "D:\lr\chair.jpg"
? "C" + MID$(a$,2)

Wen you run it, you should see

C:\lr\chair.jpg

Peter


On Mon, 23 Jan 2006 10:36:51 -0500, rmalvin <rmalvin2@hotmail.com> wrote:

> I have a text field that refers to an externalfile photo on drive D:. An
> example would be D:\lr\chair.jpg. I recently got a new pc and only have
> opne drive C:. What would be the update command to change the date in
> all records so that the first 2  letters of the data would be C: instead
> of D: ? Tnanks.
> RMalvin
>



-- 
Post Reply
Re: update syntax
Tue, 24 Jan 2006 17:58:39 -050
How about:
   UPDATE extfield.MYFILE = "C" + MID$(extfield.MYFILE,2)
    END UPDATE


On Tue, 24 Jan 2006 15:36:36 -0500, Neil Robinson <neilr@superbase.co.uk>
wrote:

> Peter Barus wrote:
>> Something like:
>>
>>  UPDATE extfield.MYFILE = "C" + MID$(extfield.MYFILE,2)
>>   WHERE LEFT$(extfield.MYFILE,1) LIKE "d"
>>   END UPDATE
>>
>> Experiment in the Code Editor (<alt+F2>) by trying this sort of
code:
>>
>> cls
>> a$ = "D:\lr\chair.jpg"
>> ? "C" + MID$(a$,2)
>>
>> Wen you run it, you should see
>>
>> C:\lr\chair.jpg
>
> Actually, this is a nasty kind of trap. In a SQL database that would be
> correct, but not always in a file and record database. The reason is
> that you are changing the record from D to C but your filter is also
> selecting next from the current record. Once you change the value from D
> to C, the record moves position. In this case, the approach you showed
> him will work, but only because C is smaller than D. If you tried it the
> other way, it wouldn't work properly because you would keep changing the
> order of the data (or it might be slow, or it might get every second
> record, etc.). Always be cautious when using UPDATE if the thing you are
> going to change is also in the filter. The safe route for this would be
> to do this for v3:
>
> DIM s as Set
>
> SELECT RecKey.MYFILE WHERE LEFT$(extfield.MYFILE,2) LIKE "d:" TO
SET s
> END SELECT
>
> SET QUERY OFF
> UPDATE extfield.MYFILE = "C" + MID$(extfield.MYFILE,2)
>    WHERE s.GetCount(RecKey.MYFILE) > 0
> END UPDATE
>
> And this for v2:
> SELECT RecKey.MYFILE
>    WHERE LEFT$(extfield.MYFILE,2) LIKE "d:"
>    TO FILE "TEMP"
> END SELECT
>
> SET QUERY OFF
> UPDATE extfield.MYFILE = "C" + MID$(extfield.MYFILE,2)
>    WHERE EXISTS(RecKey.MYFILE, RecKey.TEMP)
> END UPDATE
>
> REMOVE "TEMP"
>
> Ciao, Neil
>



-- 
Post Reply
Re: update syntax
Tue, 24 Jan 2006 20:36:36 +000
Peter Barus wrote:
> Something like:
> 
>  UPDATE extfield.MYFILE = "C" + MID$(extfield.MYFILE,2)
>   WHERE LEFT$(extfield.MYFILE,1) LIKE "d"
>   END UPDATE
> 
> Experiment in the Code Editor (<alt+F2>) by trying this sort of
code:
> 
> cls
> a$ = "D:\lr\chair.jpg"
> ? "C" + MID$(a$,2)
> 
> Wen you run it, you should see
> 
> C:\lr\chair.jpg

Actually, this is a nasty kind of trap. In a SQL database that would be 
correct, but not always in a file and record database. The reason is 
that you are changing the record from D to C but your filter is also 
selecting next from the current record. Once you change the value from D 
to C, the record moves position. In this case, the approach you showed 
him will work, but only because C is smaller than D. If you tried it the 
other way, it wouldn't work properly because you would keep changing the 
order of the data (or it might be slow, or it might get every second 
record, etc.). Always be cautious when using UPDATE if the thing you are 
going to change is also in the filter. The safe route for this would be 
to do this for v3:

DIM s as Set

SELECT RecKey.MYFILE WHERE LEFT$(extfield.MYFILE,2) LIKE "d:" TO SET
s
END SELECT

SET QUERY OFF
UPDATE extfield.MYFILE = "C" + MID$(extfield.MYFILE,2)
   WHERE s.GetCount(RecKey.MYFILE) > 0
END UPDATE

And this for v2:
SELECT RecKey.MYFILE
   WHERE LEFT$(extfield.MYFILE,2) LIKE "d:"
   TO FILE "TEMP"
END SELECT

SET QUERY OFF
UPDATE extfield.MYFILE = "C" + MID$(extfield.MYFILE,2)
   WHERE EXISTS(RecKey.MYFILE, RecKey.TEMP)
END UPDATE

REMOVE "TEMP"

Post Reply
Re: update syntax
Wed, 25 Jan 2006 09:05:57 -050
I could have saved a lot of time if I hadn't been trying to save time. :D



On Wed, 25 Jan 2006 08:46:22 -0500, Neil Robinson <neilr@superbase.co.uk>
wrote:

> Peter Barus wrote:
>> How about:
>>   UPDATE extfield.MYFILE = "C" + MID$(extfield.MYFILE,2)
>>    END UPDATE
>
> Sure, since there is no filter, every record will be changed.
>
> Ciao, Neil
>



-- 
Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact