/* DBCOPY (STD) -- SQL Database Copy */ /* DBCOPY (STD) -- SQL-Datenbanken kopieren */ /* // Copyright (c) 1997-2012 Oliver Bartels F+E, Muenchen // Author: Roman Ludwig // Changes History: // rl (120427) RELEASED FOR BAE V7.8. // rl (101019) RELEASED FOR BAE V7.6. // rl (091020) RELEASED FOR BAE V7.4. // rl (081014) RELEASED FOR BAE V7.2. // rl (071029) RELEASED FOR BAE V7.0. // rl (060829) RELEASED FOR BAE V6.8. // rl (060427) ENHANCEMENT: // Optimized copy speed by delayed indexing. // rl (050906) RELEASED FOR BAE V6.6. // rl (040811) RELEASED FOR BAE V6.4. // rl (030904) RELEASED FOR BAE V6.2. // rl (021209) RELEASED FOR BAE V6.0. // rl (020618) RELEASED FOR BAE V5.4. // rl (011025) BUGFIX: // Fixed problem with non-empty date field transfer. // rl (010625) RELEASED FOR BAE V5.0. // rl (000509) RELEASED FOR BAE V4.6. // rl (990625) RELEASED FOR BAE V4.4. // rl (980910) RELEASED FOR BAE V4.2. // mb (980710) ENHANCEMENT: // Dynamic multi-language support introduced. // rl (971105) ORIGINAL CODING. // // DESCRIPTION // // The dbcopy User Language program copies SQL table structures and database // entries of selectable SQL database files. */ // Includes #include "mnu.ulh" // User Language menu utilities #include "sql.ulh" // User Language SQL utilities // Disable undo state request #pragma ULCALLERNOUNDO // Messages string UPRABORT = M_UPRABORT(); string REPNONE = M("Datei '%s' enthaelt keine SQL-Tabellen.", "No SQL table found in file '%s'."); string REPCOPY = M("Kopieren Daten...","Copying data..."); string UPRSSQLFILE = M("SQL-Datenbank Quelldateiname ? ", "SQL Database Source File Name ? "); string UPRDSQLFILE = M("SQL-Datenbank Zieldateiname ? ", "SQL Database Destination File Name ? "); string UPRSQLTAB = M("SQL Tabelle ? ","SQL Table ? "); string UPRSQLDTAB = M("SQL Ziel-Tabelle ? ","SQL Destination Table ? "); string UPRSELNAME0 = M("Gleicher Tabellenname","Same table name"); string UPRSELNAME1 = M("Anderer Tabellenname","Other table name"); string ERRNOTABF = M("Tabelle enthaelt keine Felder!", "Table contains no fields!"); string ERRDIFFTAB = M("Tabellen haben unterschiedliche Felder!", "Tables contain different fields!"); string ERRILLDATA = M("Unbekannter Datentyp in Tabelle!", "Table contains unknown data type!"); // SQL command definitions #define CMD_GETDATA "select from %s;" #define CMD_INSDATA "quickinsert into %s values(" #define CMD_IDXDATA "index table %s;" // Globals STRINGS INITSTRL = {""} /* String list initialyzer */; STRINGS tabl /* Table name list */; int tabn = 0 /* Table count */; sql_fields srcfl /* Source table field list */; int srcfn /* Source table field count */; sql_fields dstfl /* Destination table field list */; int dstfn /* Destination table field count */; string dsqlfname /* Destination database file name */; string curdtab /* Current destination table name */; STRINGS datal /* Data list string */; int datan /* Data list count */; string sqlicommand /* SQL insert command string */; // Main program void main() { string ssqlfname /* Source database file name */; STRINGS hl = INITSTRL /* Header list */; int hn = 2 /* Header count */; int mc = 0 /* Requested popup column count */; string curstab /* Current source table name */; string lasttab = "" /* Last table name */; int nmode /* Name mode */; int i /* Loop control variable */; // Select source database file name if ((ssqlfname=selectsqlfile(UPRSSQLFILE))=="") error_abort(); // Check if file readable i=bae_fopen(ssqlfname,0); fclose(i); // Get table names if ((tabn=sql_gettabs(ssqlfname,tabl))<=0) // No tables found errormsg(REPNONE,ssqlfname); // Build table popup menu header hl[0]=M_REPPOPDIRHD(DDBCLSQLT1,ssqlfname); hl[1]=""; // Get maximum line length for (i=hn-1;i>=0;i--) mc=maxint(mc,strlen(hl[i])+1); for (i=tabn-1;i>=0;i--) mc=maxint(mc,strlen(tabl[i])+1); // Activate the table popup menu bae_setintpar(16,5019); while ((curstab=popupmenu(4,UPRSQLTAB, hl,hn,tabl,tabn,UINPOPABORT,0,0,0,0,mc+3,0,""))!="" && curstab!=UINPOPABORT) { // Check if other than last table selected if (curstab!=lasttab) { // Get table fields if ((srcfn=sql_getfields(ssqlfname,curstab,srcfl))<0) sql_dberror(0); if (srcfn==0) error(ERRNOTABF); // Update the last table name lasttab=curstab; } // Select destination database file name if ((dsqlfname=selectsqlfile(UPRDSQLFILE))=="") error_abort(); if ((nmode=bae_askmenu(3, UPRSELNAME0,UPRSELNAME1,UPRABORT))<0 || nmode>=2) error_abort(); if (nmode) { // Get destination table name if ((curdtab=askstr(UPRSQLDTAB,MAXKEYLEN))=="" || curdtab==UINPOPABORT) error_abort(); } else // Use same table name curdtab=curstab; // Get table fields if ((dstfn=sql_getfields(dsqlfname,curdtab,dstfl))<=0) { // Create new table if (sql_createtab(dsqlfname,curdtab,srcfl)) sql_dberror(0); } // Compare with existing table else if (sql_cmptabs(srcfl,dstfl)) error(ERRDIFFTAB); // Copy the table data bae_prtdialog(REPCOPY); copytabledata(ssqlfname,curstab); } // Clear the dialog line bae_prtdialog(""); } // File management routines string selectsqlfile(string prompt) /* // Perform a DDB SQL file selection via popup menu // Parameters : // string prompt : Prompt string // Return value : // name of selected element or empty string on abort */ { STRINGS extl = {bae_swversion(3)} /* Extension list */; string fname /* File name buffer */; // Perform the file name selection fname=askfile(prompt,extl,DDBCLSQLFT); // Append DDB file extension if no extension catextadv(fname,DDBEXT,0); // Clear the dialog line bae_prtdialog(""); // Return the file name return(fname); } // SQL database access routines void copytabledata(string sqlfname,string tabname) /* // Copy SQL table data // Parameters : // string sqlfname : SQL source database file name // string tabname : SQL source table name */ { string sqlcommand /* SQL command string */; int i /* Loop control variable */; // Select data entries from database table sqlicommand=""; datan=0; sprintf(sqlcommand,CMD_GETDATA,tabname); sqlcmd(sqlfname,sqlcommand,copydatafunc); // Store the last table entry if (sqlicommand!="") { // Terminate old entry sqlicommand+=");"; datal[datan++]=sqlicommand; } // Insert data into table for (i=0;i