/* DBREPORT (STD) -- SQL Database Report */ /* DBREPORT (STD) -- SQL-Datenbank-Report */ /* // Copyright (c) 1994-2012 Oliver Bartels F+E, Muenchen // Author: Manfred Baumeister // 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 (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 (010625) RELEASED FOR BAE V5.0. // rl (000508) 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 (970929) RELEASED FOR BAE V4.0. // mb (961101) ENHANCEMENT: // List all data entries of selected table. // mb (960919) RELEASED FOR BAE V3.4. // mb (95) RELEASED FOR BAE V3.2. // mb (941208) ENHANCEMENT: // Introduced table data entry reports for selectable fields. // mb (94) RELEASED FOR BAE V3.0. // mb (94) NEW: // SQL utility for extracting DB table structure info // from selectable SQL/DB file. // mb (95) RELEASED FOR BAE V3.2. // mb (94) RELEASED FOR BAE V3.0. // mb (94) ORIGINAL CODING. // // DESCRIPTION // // The dbreport User Language program provides utilities // for displaying 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 REPNONE = M("Datei '%s' enthaelt keine SQL-Tabellen.", "No SQL table found in file '%s'."); string REPTABHD = M("Datei '%s' / SQL Tabelle '%s' :", "File '%s' / SQL Table '%s' :"); string UPRSQLFILE = M("SQL-Datenbank Dateiname ? ", "SQL Database File Name ? "); string UPRSQLTAB = M("SQL Tabelle ? ","SQL Table ? "); #define ITM40EQ "========================================" #define ITMULINE ITM40EQ+ITM40EQ // Globals STRINGS tabl /* Table name list */; int tabn = 0 /* Table count */; sql_fields fieldl /* Table field list */; int fieldn /* Table field count */; STRINGS datal /* Table data list */; int datan /* Table data count */; STRTAB el /* Table entry string table */; int en /* Table entry count */; // Main program void main() { string sqlfname /* Database file name */; STRINGS hl = INITSTRL() /* Header list */; int hn = 2 /* Header count */; int mc = 0 /* Requested popup column count */; string curtab /* Current table name */; string lasttab = "" /* Last table name */; int i /* Loop control variable */; // Select database file name if ((sqlfname=selectsqlfile())=="") error_abort(); // Check if file readable i=bae_fopen(sqlfname,0); fclose(i); // Get table names if ((tabn=sql_gettabs(sqlfname,tabl))<=0) // No tables found errormsg(REPNONE,sqlfname); // Build table popup menu header hl[0]=M_REPPOPDIRHD(DDBCLSQLT1,sqlfname); 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 ((curtab=popupmenu(4,UPRSQLTAB, hl,hn,tabl,tabn,UINPOPABORT,0,0,0,0,mc+3,0,""))!="" && curtab!=UINPOPABORT) { // Check if other than last table selected if (curtab!=lasttab) { // Get the table data gettabledata(sqlfname,curtab); // Update the last table name lasttab=curtab; } // Activate the table data popup menu bae_setintpar(16,5020); mnu_poptext(datal,1,1,-1,0,1); } } // File management routines string selectsqlfile() /* // Perform a DDB SQL file selection via popup menu // 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(UPRSQLFILE,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 gettabledata(string sqlfname,string tabname) /* // Get SQL table data // Parameters : // string sqlfname : SQL database file name // string tabname : SQL table name */ { STRINGS curentries /* Current entry string list */; string curdata /* Entry data buffer */; string strbuf /* String buffer */; int ml /* Max. field length buffer */; int i,j /* Loop control variable */; // Get table fields if ((fieldn=sql_getfields(sqlfname,tabname,fieldl))<0) sql_dberror(0); if (fieldn==0) ; // Init the max. field lengths for (i=fieldn-1;i>=0;i--) fieldl[i].ml= maxint(strlen(fieldl[i].fname), strlen(sql_dtyp2str(fieldl[i].fdtyp))); // Get the table data en=sql_getdata(sqlfname,tabname,el); // Set the max. field lengths for (i=fieldn-1;i>=0;i--) { for (ml=fieldl[i].ml,j=en-1;j>=0;j--) ml=maxint(ml,strlen(el[j][i])); fieldl[i].ml=ml; } // Init the table data list datal=INITSTRL(); sprintf(datal[0],REPTABHD,sqlfname,tabname); datal[1]=""; datan=2; // Store the field name list for (curdata="",i=0;i