#include <xsu.hpp>

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. | |
# OPEN test; SELECT 1; # CLOSE test;
<?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.
Definition at line 57 of file xsu.hpp.
| XSU::XSU | ( | DatabasePtr | _database | ) | [inline] |
| void XSU::translate | ( | std::istream & | inputStream, | |
| std::ostream & | outputStream | |||
| ) | const throw (Error) [virtual] |
Do SQL-queries.
| 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 }
DatabasePtr XSU::database [protected] |