Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Renaming tables which are part of database
Message
 
 
To
21/11/2002 18:19:53
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00724370
Message ID:
00725811
Views:
14
>>Copying files is a long process, if files are huge. I liked Franco's hacking idea. Besides, it seems to work well.
>
>Keep in mind there be dragons in the properties memo of dbc records - lots of kinky binaries. While you may be just lucky, it could happen that (depending on your settings) some CRs get replaced with CRLFs etc... so I'd rather go for StrTran(properties, lcOldTableName, lcNewTableName).

Hi Dragan,

My colleague wrote a program to made the changes. One catch here, is that first we have to change DBC name in the tables and only then we can use this new DBC and change properties (objName and properties fields) to new table references. This process would not work in the opposite order.

So, first she is doing ChangeDBCName, then rename DBC file, then use DBC file, scan and replace, then do actual tables renaming. Of course, firstly she copies files to Backup directory.

Here is a procedure to change dbc name, which I wrote using Sergey's program to get a DBC name.
********************************************************************
*  Description.......: ChangeDBCName - changes DBC Name using low-level functions
*  Calling Samples...:
*  Parameter List....: tcTableFullName, tcOldDBCName, tcNewDBCName
*  Created by........: Sergey Berezniker
*  Modified by.......: Nadya Nosonovsky 05/22/2002 09:35:06 AM
********************************************************************
lparameters tcTableFullName, tcOldDbcName, tcNewDBCName
if vartype(m.tcTableFullName)<>"C"
	tcTableFullName = getfile('DBF','Select','&Choose',0,'Select table to check database')
	if empty(m.tcTableFullName) && User pressed cancel
		return ''
	endif
endif
if vartype(m.tcOldDBCName)<>"C"
   tcOldDBCName = rbInputBox('Enter Old DBC with extension','Old DBC Name')
   if empty(m.tcOldDBCName)
       return .f.
   endif
endif       

if vartype(m.tcNewDBCName)<>"C"
   tcNewDBCName = rbInputBox('Enter New DBC with extension','New DBC Name')
   if empty(m.tcNewDBCName)
       return .f.
   endif
endif       

local lcDbcFullName, lcB1, lcB2, lnOffset, lcBuffer, lnFh1
lnFh1 = fopen(m.tcTableFullName,12) && To read-write
if m.lnFh1 > 0
* Make sure that's VFP table
	lcBuffer = fread(m.lnFh1,1) 
	if asc(m.lcBuffer) <> 0x30
* not VFP table
		lcDbcName = "***NOT VFP TABLE***"
		= messagebox(m.lcDbcName,48,'Error')
		return .f.
	else
* table in dbc
		lcDbcName = left(m.lcBuffer, at( chr(0), m.lcBuffer) - 1)
	endif
* Position of the first data record - 2 bytes
	= fseek(m.lnFh1, 8, 0)
	lcB1 = fread(m.lnFh1,1)
	lcB2 = fread(m.lnFh1,1)
* Offset to the beginning of the DBC name
	lnOffset = asc(m.lcB2) * 256 + asc(m.lcB1) - 263
	= fseek(m.lnFh1, m.lnOffset, 0)
* The DBC name or 0x00's if it's free table
	lcBuffer = fread(m.lnFh1, 263)
	if asc(m.lcBuffer) = 0
* free table
		lcDbcName = "***FREE TABLE***"
		= messagebox(m.lcDbcName,48,'Error')
	       return .f.
	else
* table in dbc
          if not lower(m.tcOldDBCName) $ m.lcBuffer
                  =messagebox ('The database '+ m.tcOldDBCName + ' is not the Database name for this table',48,'Different database')
                  return .f.
         endif
        lcBuffer = strtran(m.lcBuffer,m.tcOldDBCName,m.tcNewDBCName)
     	= fseek(m.lnFh1, m.lnOffset, 0) 
      	if fwrite(m.lnFh1, m.lcBuffer)=0
      	   = messagebox('New DBC name could not be written to the file!',48,'No change')
      	   return .f.
      	endif   
		lcDbcName = left(m.lcBuffer, at( chr(0), m.lcBuffer) - 1)
	endif
	= fclose(m.lnFh1)
else
	=messagebox('File '+m.tcTableFullName+' could not be opened',48,'Problem')
	return .f.
endif
return .t.&&m.lcDbcName
P.S. once again, it's good, that I published it, because I see, I need to modify comments, prompts, etc. a little bit.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform