Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What DBC is current DBF contained in ?
Message
De
05/09/2001 05:15:43
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
04/09/2001 12:32:50
Patrick O'Neil
American Specialty Information Services
Roanoke, Indiana, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00552066
Message ID:
00552381
Vues:
28
>>>if open a table that is contained in a database (but i do not know
>>>which one), is there a way to find out what the "containing database
>>>pointer" is ?
>>>
>>>is there a way to update that pointer ?
>>
>>This will do it:
>>if empty(dbf())
>>   return ""
>>endif
>>local lcDBC, lnRetVal, llFound, lcCurDBC, laDBCs[1]
>>lnRetVal = ADATABASES(laDBCs)
>>lcCurDBC = SET('database')
>>FOR EACH lcDBC IN laDBCs
>>   SET DATABASE TO (lcDBC)
>>   IF INDBC(JUSTSTEM(JUSTFNAME(DBF())), 'Table')
>>      llFound = .t.
>>      EXIT
>>   ENDIF
>>ENDFOR
>>SET DATABASE TO (lcCurDBC)
>>CLEAR
>>if not llFound
>>   lcDBC = ""
>>endif
>>RETURN lcDBC
>
>
>mark -
>
>thanks, that's what i need.
>
>in between the time i posted and the time i got your recommendation,
>i obtained ultra-edit and looked at the innards of a DBF. i could
>see the name of the DBC listed there. and that raises a couple questions.
>
>1) would you consider it bad form to use (for example) STRTOFILE / FILETOSTR
> to modify the DBC info in a DBF ?
>
>2) does the DBF have some kind of "checksum" value that i would need to
> re-calculate and update, IF i did do such an alteration ??
>
>3) is there already a utility to do that ? either from Microsoft or
> someone here UT ?
>
>i'm asking, because i do distributed systems and sometimes want to
>move DBC and/or DBF files either separately or to directories that have
>different names on the client than on the server. i don't want the users
>to see a prompt to select the correct DBC if i can update it myself.

Patrick,
For your original question you can get DBC this way too :
if !empty(cursorgetprop("Database",lcAlias)) && Not a free table
  if !dbc()=cursorgetprop("Database",lcAlias) && DBC is not the current one
	open database (cursorgetprop("Database",lcAlias)) && Open or Set current
  endif
*...
1) A DBC is already a DBF. It has 0x04 flag set at byte offset 28 (DBC indicator) and its backlink info is empty. You can use it and modify like any DBF. But don't tkae it as I'm suggesting to do it unless you know what you're doing. It's very easy to render it useless. Also note that it keeps many things in compiled form. You should be able to compile if you modify anything that requires it (ie:stored procs) or supply a precompiled form.

2) Not a checksum but a series of properties should exactly match including field ordinals.

3) There is one from Stonefield AFAIK. I did my own (fix and struct updater as 2 separate utils) that's gonna be part of FoxyClasses. They might differ in what they're doing and purposes greatly.

You can update silently. Keep in mind path info is held :
-in DBF at position after header record terminator (263 bytes). This is backlink info. This one is a relative pathing.
-and in database itself which is accessible via dbgetprop/dbsetprop.
* List paths of DBC tables
lnObjects = adbobjects(arrDBObjects,'TABLE')
for lnDbObject=1 to lnObjects
 ? upper(dbgetprop(arrDBObjects[lnDbObject],'TABLE','Path'))
endfor
Below simply demonstrates renaming a DBC (ie: 'testdata' to 'mydata'). (With the assumption DBC and its tables are in the same dir)
Function RenDbc
lparameters OldName, NewName
Open data (oldName)
lnTables=adbobject(arrTables,'TABLE')
For ix=1 to lnTables
  lcTable = arrTables[ix]+'.DBF'
  handle=fopen(lcTable,12)
  =fseek(handle,8,0)
  lnLowByte = asc(fread(handle,1))
  lnHighByte = asc(fread(handle,1))*256
  lnBackLinkstart = lnHighByte + lnLowByte - 263
  =fseek(handle,lnBackLinkstart,0)
  Fwrite(handle,forceext(newName,'dbc')+replicate(chr(0),263),263)
  =fclose(handle)
Endfor
Close data all
Rename (forceext(oldName,'dbc')) to (forceext(newName,'dbc'))
Rename (forceext(oldName,'dcx')) to (forceext(newName,'dcx'))
Rename (forceext(oldName,'dct')) to (forceext(newName,'dct'))
If you were just to move DBC and tables to different locations keeping their relative pathing to each other you don't need all these. Just move/copy. During dbc opening if dbc path is not hardcoded (as in forms with DE) or if it can't find in the hardcoded path then would use the one in its search path.

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform