00001 //============================================================================= 00002 // 00003 // XDFLengine library 00004 // 00005 //----------------------------------------------------------------------------- 00006 // SQLDBVALUER.CPP 00007 //----------------------------------------------------------------------------- 00013 //_____________________________________________________________________________ 00014 // 00015 // Copyright (C) 2003 Guillaume Baurand. All Rights Reserved. 00016 // 00017 // This file is part of the XDFLengine project. 00018 // 00019 // The XDFLengine is free software; you can redistribute it and/or modify 00020 // it under the terms of the GNU General Public License as published by 00021 // the Free Software Foundation; either version 2 of the License, or 00022 // (at your option) any later version. 00023 // 00024 // This program is distributed in the hope that it will be useful, 00025 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00026 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00027 // GNU General Public License for more details. 00028 // 00029 // You should have received a copy of the GNU General Public License 00030 // along with this program; if not, write to the Free Software 00031 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00032 // USA. 00033 // 00034 // For more information, 00035 // contact : guillaume@baurand.net 00036 // or visit : http://xdflengine.sourceforge.net 00037 // 00038 //============================================================================= 00039 00040 # include "sqldbvaluer.hpp" 00041 00042 BEGIN_XDFLENGINE_NS 00043 00044 //============================================================================= 00045 // CLASS SQLDBVALUER 00046 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00047 00048 //_________________________________________________________________________ 00049 // SQLDBVALUER 00050 //------------------------------------------------------------------------- 00051 SQLDBValuer::SQLDBValuer() 00052 { 00053 m_pConnection=0; 00054 DEBUG_CREATE(SQLDBValuer) 00055 } 00056 00057 //_________________________________________________________________________ 00058 // ~SQLDBVALUER 00059 //------------------------------------------------------------------------- 00060 SQLDBValuer::~SQLDBValuer() 00061 { 00062 DEBUG_DEL(SQLDBValuer) 00063 } 00064 00065 //_________________________________________________________________________ 00066 // SETCONNECTION 00067 //------------------------------------------------------------------------- 00068 void SQLDBValuer::setConnection(otl_connect* p_pConnection) 00069 { 00070 m_pConnection=p_pConnection; 00071 } 00072 00073 //_________________________________________________________________________ 00074 // CALCULATEEXPRESSION 00075 //------------------------------------------------------------------------- 00076 char* SQLDBValuer::calculateExpression(const char* p_pszExpression) 00077 { 00078 //--------------------------------------------------------------------- 00079 otl_stream* l_prsData; 00080 char* l_pszValue=0; 00081 int l_iSize=0; 00082 XMLFlowException* l_pXMLFlowException; 00083 //--------------------------------------------------------------------- 00084 00085 DEBUG_FUNC(SQLDBValuer::calculateExpression) 00086 00087 if( m_pConnection) 00088 { 00089 00090 try 00091 { 00092 //execute SQL 00093 l_prsData=new otl_stream(); 00094 l_prsData->set_all_column_types(otl_all_num2str | otl_all_date2str); // set all columns to strings 00095 l_prsData->open( SQLVALUER_OTL_BUFFER, p_pszExpression, (*m_pConnection) ); 00096 l_prsData->flush(); // force execution 00097 00098 DEBUG_ECHO << "ok\n"; 00099 } 00100 catch(otl_exception& p) 00101 { // intercept OTL exceptions 00102 m_pConnection->rollback(); 00103 l_pXMLFlowException = new XMLFlowException( ERRCODE_LOC_SQLDBVALUER + ERRCODE_CAUSE_DATAACCESS , "Error while opening data stream.", (char*)(&(p.msg)), "SQLDBValuer::calculateExpression", "", false); 00104 p.~otl_tmpl_exception(); 00105 throw l_pXMLFlowException; 00106 } 00107 00108 l_iSize = l_prsData->describe_next_out_var()->elem_size; 00109 l_pszValue = allocCharBuffer(l_iSize+1); 00110 (*l_prsData) >> l_pszValue; 00111 00112 //l_rsData->clean(); 00113 l_prsData->close(); 00114 delete(l_prsData); 00115 00116 return l_pszValue; 00117 } 00118 else return 0; 00119 } 00120 00121 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00122 //============================================================================= 00123 00124 END_XDFLENGINE_NS