*!* create a directory c:\testcopydata\copyofdatabase\ *!* copy your database to c:\testcopydata\copyofdatabase\ with all tables with indexes *!* create an ODBC connection to your source database *!* define m._odbcdatasource = a valid ODBC Source name *!* define m._odbcuserid = valid ODBC userID *!* Define m._odbcpassword = valid ODBC password for Source *!* change the name to the correct dbc name. m._odbcdatasource = "testcopydata" m._odbcuserid = "" m._odbcpassword = "" m.lcDatabaseCopyLocation = "c:\testcopydata\copyofdatabase\" m.lcDBCNAME = "FELDAR32" =messagebox("This copies the database using SQL Pass Through to get the source data and append to the copy tables") close data all *!* check for existence of copyifdatabase folder and create it if needed if !directory(m.lcDatabaseCopyLocation) or !file(m.lcDatabaseCopyLocation+m.lcDBCNAME+".DBC") *** could not find or create data directory =messagebox(getapplicationtext("Error locating the folder specified for the copy of your database.")) return .f. endif m.lcCDBSetSafety = set("safety") set safety off on error *!* get a list of tables in the database to update select objectname distinct from (m.lcDatabaseCopyLocation+m.lcDBCNAME+".dbc") ; into array laTablelist where objecttype = "Table" close data all if _tally > 0 and type("laTablelist[1]") = "C" for m.ln_xy = 1 to alen(laTablelist) m.lcTablename = trim(laTablelist[m.ln_xy]) m.lcCursorname = "c_"+m.lcTablename close data all wait window "Copying Table "+m.lcTablename+" Please wait..." nowait *!* execute Select * from each table into a cursor using SQLEXEC() if executeSQLcommand("Select * from "+m.lcTablename,m.lcCursorname) ; and used(m.lcCursorname) select 0 use (m.lcDatabaseCopyLocation+m.lcDBCNAME+"!"+m.lcTablename) alias (m.lcTablename) exclusive =cursorsetprop("buffering",1,m.lcTablename) select (m.lcTablename) zap if reccount(m.lcCursorname) > 0 select (m.lcTablename) *!* this is where it will fail if any duplicate records in the cursor append from (dbf(m.lcCursorname)) endif if reccount(m.lcCursorname) <> reccount(m.lcTablename) =messagebox("Error copying "+m.lcTablename) endif endif next wait clear close data all set safety &lcCDBSetSafety endif ************************************* function executeSQLcommand parameters m.lSqlCommand2exec,m.lcSqlResultcursor *!* this is a wrapper for SQLEXEC function *!* parameter 1 = SQL command to execute via SQL Pass Through *!* parameter 2 = Name of cursor to create for the result set local m.lcSetnotify,m.lcSetEscape,m.lnConnHandle if type("m.lSqlCommand2exec") <> "C" .or. empty(lSqlCommand2exec) return .f. endif m.lnSqlEXEResult = 0 m.lcSetnotify = set("notify") m.lcSetEscape = set("escape") set notify off set escape off m.lnConnHandle = SQLCONNECT(trim(m._odbcdatasource), trim(m._odbcuserid),trim(m._odbcpassword)) if type("m.lnConnHandle") = "N" .and. m.lnConnHandle > 0 =SQLSETPROP(m.lnConnHandle, "Asynchronous",.f.) =SQLSETPROP(m.lnConnHandle, "BatchMode",.t.) if type("m.lcSqlResultcursor") = "C" .and. !empty(m.lcSqlResultcursor) m.lnSqlEXEResult = SQLEXEC(m.lnConnHandle, m.lSqlCommand2exec,m.lcSqlResultcursor) else m.lnSqlEXEResult = SQLEXEC(m.lnConnHandle, m.lSqlCommand2exec) endif =SQLDISCONNECT(m.lnConnHandle) endif && type("m.nConnHandle") = "N" .and. m.nConnHandle > 0 set notify &lcSetnotify set escape &lcSetEscape return iif(type("m.lnSqlEXEResult") = "N" and m.lnSqlEXEResult > 0,.t.,.f.)