Main | License | Installation | FAQ | Screenshots | Contact | Links | Sf.net | Freshmeat.net | KDE-Apps.org
Requirements | Design | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

XSU Class Reference
[Compilers]

#include <xsu.hpp>

Inheritance diagram for XSU:

Inheritance graph
[legend]

Public Member Functions

 XSU (DatabasePtr _database)
virtual void translate (std::istream &inputStream, std::ostream &outputStream) const throw (Error)

Protected Attributes

DatabasePtr database
 Pointer to database.

Detailed Description

Implementation of a tool similar to Oracle's XML SQL Utility. Using a connection to a database, the XML SQL Utility takes SQL scripts as input and produces XML as output. For example the following input
    # OPEN test;
    SELECT 1;
    # CLOSE test;
would result in the following output:
    <?xml version='1.0' encoding='UTF-8'?>
    <data>
      <test>
        <table>
          <meta>
            <column><![CDATA[1]]></column>
          </meta>
          <row>
            <column><![CDATA[1]]></column>
          </row>
        </table>
      </test>
    </data>

Note, that the text after the '# OPEN'-comment is being used as a tag-name for the data.

Date:
Thu Mar 28 2005
Author:
Jan Wedekind (wedesoft@users.sourceforge.net)

Definition at line 57 of file xsu.hpp.


Constructor & Destructor Documentation

XSU::XSU ( DatabasePtr  _database  )  [inline]

Constructor. The constructor takes a reference to a database as argument.

Parameters:
_database Database to pass SQL-queries to.

Definition at line 63 of file xsu.hpp.

00063 : database( _database ) {}


Member Function Documentation

void XSU::translate ( std::istream &  inputStream,
std::ostream &  outputStream 
) const throw (Error) [virtual]

Do SQL-queries.

Parameters:
inputStream Input containing sequence of SQL-queries.
outputStream Stream to write XML-output to.

Implements Compiler.

Definition at line 24 of file xsu.cpp.

References ERRORMACRO, and xmlText().

00027 {
00028 
00029   outputStream << "<?xml version='1.0' encoding='"SQLENCODING"'?>" << endl
00030                << "<data>" << endl;
00031 
00032   stack< string > tagName;
00033 
00034   while ( inputStream ) {
00035 
00036     string line;
00037     getline( inputStream, line );
00038 
00039     if ( line[0] == '#' ) {
00040 
00041       // Encountering comment. Check for possible "# OPEN tagname;" hook.
00042       if ( line.compare( 1, 5, " OPEN" ) == 0 ) {
00043         tagName.push( line.substr( 7, line.size() - 8 ) );
00044         // The error-handling for proper tag-names has to be done by the
00045         // Xalan-library at the moment.
00046         outputStream << "<" << tagName.top() << '>' << endl;
00047       } else if ( line.compare( 1, 6, " CLOSE" ) == 0 ) {
00048         string closingTagName = line.substr( 8, line.size() - 9 );
00049         ERRORMACRO( !tagName.empty(), Error, ,
00050                     "Cannot close tag \"" << closingTagName << "\", because "
00051                     "all tags have been closed already." );
00052         ERRORMACRO( tagName.top() == closingTagName, Error, ,
00053                     "Encountered closing of tag \"" << closingTagName
00054                     << "\", but was expecting closing of tag with name \""
00055                     << tagName.top() << "\"." );
00056         outputStream << "</" << closingTagName << '>' << endl;
00057         tagName.pop();
00058       };
00059 
00060     } else {
00061 
00062       // Pass on content to unixODBC/ODBC interface.
00063       StatementPtr statement = database->execQuery( line );
00064 
00065       if ( !tagName.empty() && statement->getNumCols() > 0 ) {
00066 
00067         // Extract meta-data.
00068         outputStream << "    <table>" << endl
00069                      << "      <meta>" << endl;
00070         for ( int i=0; i<statement->getNumCols(); i++ )
00071           outputStream << "        <column>"
00072                        << xmlText( statement->getColAttr( i ) )
00073                        << "</column>" << endl;
00074         outputStream << "      </meta>" << endl;
00075 
00076         // Extract data.
00077         ResultRowPtr row;
00078         while ( row = statement->fetchRow() ) {
00079           outputStream << "      <row>" << endl;
00080           for ( int i=0; i<statement->getNumCols(); i++ )
00081             outputStream << "        <column>" << xmlText( (*row)[i] )
00082                          << "</column>" << endl;
00083           outputStream << "      </row>" << endl;
00084           // Release object accessing results.
00085           row.reset();
00086         };
00087         outputStream << "    </table>" << endl;
00088 
00089       };
00090     };
00091   };
00092 
00093   ERRORMACRO( tagName.empty(), Error, ,
00094               "Expected closing of tag \"" << tagName.top() << "\"." );
00095 
00096   outputStream << "</data>" << endl;
00097 }


Field Documentation

DatabasePtr XSU::database [protected]

Pointer to database.

Definition at line 72 of file xsu.hpp.


The documentation for this class was generated from the following files:

anymeal 0.30 - recipe management software - Make the most of your food! - © Jan Wedekind Sun Sep 14 16:01:30 2008 - GNU Free Documentation License