New topic: 

Copy Database1 Table to Database2 Table Help Needed

<http://forums.realsoftware.com/viewtopic.php?t=46025>

         Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic          Author  
Message        jerryab          Post subject: Copy Database1 Table to Database2 
Table Help NeededPosted: Thu Nov 22, 2012 8:50 pm                         
Joined: Mon Dec 12, 2011 7:25 pm
Posts: 123
Location: Grand Rapids MI Area                I have a routine in my program 
that loads 2 different user selected databases
so the user can select only the records they want from one database and copy 
them to the other.

I am trying to copy a table from Database1 to Database2. Both of these databases
are already open and connected to. Both databases have the tables existing also.
Below is what I have been trying but no success.

if ckbCopyCampingFriendsList.Value Then
  // Copy table with all of the PersonalContacts information
  // copy all the records
  
  'tmpDatabase1 is the full path to the first database
  'tmpDatabase2 is the full path to the second database
  'tmpDB1 is a REALSQLDatabase, tmpDB2 is a REALSQLDatabase
  
  
  if not tmpDB1.attachDatabase( tmpDB2.databaseFile,"tmpDB2" ) then
  return// database could not be attached - add error checking
  end
  
  // copy the records
  tmpDB1.sqlExecute "begin transaction"
  tmpDB1.sqlExecute "insert into tmpDB2.PersonalContacts from select * from 
PersonalContacts"
  if tmpDB2.Error then
  App.DisplayDatabaseError true
  return
  end if
  tmpDB1.commit
  
  // detach the database
  tmpDB1.detachDatabase "tmpDB2"
end if
      
_________________
iMac 27" (2.8GHz Intel Core i5, 16GB RAM, 1TB Drive) OS X Lion 10.7.3 and 
Windows 7
Toshiba Laptop Running Windows 7 & WinXP SP3
REAL Studio Enterprise Edition 2012r1
http://www.theultimatecampgroundlog.com
Being rewritten for the Mac  
                             Top                DaveS          Post subject: 
Re: Copy Database1 Table to Database2 Table Help NeededPosted: Thu Nov 22, 2012 
10:58 pm                                 
Joined: Sun Aug 05, 2007 10:46 am
Posts: 4292
Location: San Diego, CA                that won't work because your reference 
to the databases is in scope to RealStudio.. but NOT in scope to the underlying 
Database engine.

Here is an idea.

dim rs1 as recordset
rs1=tmpDB1.SQLSelect('SELECT * from PersonalContacts")
while not rs1.eof
  tmpDB2.SQLExecute("INSERT into PersonalContact (list of fields) 
values("+rs1.field("x") etc)
  rs1.movenext
wend


I will leave it up to you to computer the INSERT INTO statement properly, and 
to add appropriate error checking



Note.... the Syntax in your statement is incorrect even if you could do it that 
way

at best it would be


Insert into tmpDB2.PersonalContacts select * from PersonalContacts      
_________________
Dave Sisemore
MacPro, OSX Lion 10.7.4 RB2012r1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to