Making a copy of a database under program control.

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Making a copy of a database under program control.

Post by lohill » Fri Feb 22, 2013 7:36 pm

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

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

Post by Simon » Fri Feb 22, 2013 11:26 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

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

Post by lohill » Sat Feb 23, 2013 6:27 pm

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

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

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

Post by lohill » Sat Feb 23, 2013 6:59 pm

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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

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

Post by Klaus » Sun Feb 24, 2013 1:42 pm

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

Post Reply