Page 1 of 1

Making a copy of a database under program control.

Posted: Fri Feb 22, 2013 7:36 pm
by lohill
The following code allows me to 'clone' the SQLite database I am currently using and then switch me to that database. It works on my Mac where I developed it but does not work on my PC. Any suggestions?

Code: Select all

on cloneDatabase
   global gConIDRadi
   put the field "Database Name" into tCurrentDB
   replace "_GR.db" with "" in tCurrentDB
   put tCurrentDB into tOldDB
   put  "_Clone" after tCurrentDB
   ask question  "What would you like to name this 'cloned' database?" with tCurrentDB titled "Clone Database"
   put it into tCurrentDB
   If tCurrentDB is not empty then
      if tCurrentDB = tOldDB then
         answer Warning "Duplicate name not allowed." titled "Clone Database"
         exit cloneDatabase
      end if
      put "_GR.db" after tOldDB
      put "_GR.db" after tCurrentDB
      put the directory into tPath
      put slash after tPath
      put "binfile:" & tPath & tOldDb into tOldFile
      put "binfile:" & tPath & tCurrentDB into tNewFile
      put URL(tOldFile) into URL(tNewFile)
      put the result into tResult
      If tResult is empty then
         put tCurrentDB  into field "Database Name"
         refreshMenu
      end if
   end if
end cloneDatabase
Thanks in advance,
Larry

Re: Making a copy of a database under program control.

Posted: Fri Feb 22, 2013 11:26 pm
by Simon
Hi Larry,
I doubled check your code and it looks right.
Is the db open when you try to copy? Microsoft’s Volume Shadow may not be enabled and so not allow the copy of an open db. The quick test I guess would be just to open the db and then from Win Explorer try a manual copy.
What does the tResult say?

Simon

Re: Making a copy of a database under program control.

Posted: Sat Feb 23, 2013 6:27 pm
by lohill
Thanks for the reply Simon,

The database is open when I try to do the copy. I did try your quick test and it did allow me to make a copy while the database was open. Could it make any difference that my Windows 7 is running in a Parallels virtual machine on my Mac? I don't suspect that because I have had no other problems with that environment. Is it worth trying to close the database before trying the copy and the connecting to it again? Any other ideas?

Larry

Re: Making a copy of a database under program control.

Posted: Sat Feb 23, 2013 6:59 pm
by lohill
The following change seems to work on the PC side. Now I'll go back to the Mac and see what happens

Code: Select all

      put tPath & "/" & tOldDB into tOldFile
      put tPath & "/" & tCurrentDb into tNewFile
      revCopyFile tOldfile, tNewFile
      put the result into tResult
  
Larry

Re: Making a copy of a database under program control.

Posted: Sun Feb 24, 2013 1:42 pm
by Klaus
Hi Larry,

I NEVER EVER rely on "the defaultfolder"!
It is a snap to create the correct absolute path from the current stacks filename, so we should do this!

When you open a standalone (Mac or Win) "the defaultfolder" is the folder where the EXE or APP (and here NOT inside of the app bundle!) resides.

Where exactly is your database file located?
This info is missing in your postings but neccessary to solve eventual pathproblems :D

Best

Klaus