
 //
 // ocipl-xml.cpp
 //
 // Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Martin Fuchs <martin-fuchs@gmx.net>
 // 
 // OCIPL Version 1.5
 //

 /// \file ocipl-xml.cpp
 /// implementation file of OCIPL's XML functions


/*

  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright
	notice, this list of conditions and the following disclaimer.
  * Redistributions in binary form must reproduce the above copyright
	notice, this list of conditions and the following disclaimer in
	the documentation and/or other materials provided with the
	distribution.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  POSSIBILITY OF SUCH DAMAGE.

*/

#ifndef OCIPL_NO_COMMENT
#define OCIPL_NO_COMMENT	// no #pragma comment(lib, ...) statements in .lib files
#endif
#ifndef XS_NO_COMMENT
#define XS_NO_COMMENT	// no pragma(lib) in xmlstorage.h
#endif

#include <xmlstorage.h>
using namespace XMLStorage;

#ifdef UNICODE
#define ANSI_STRING(s) XS_String(s)
#else
#define ANSI_STRING(s) s
#endif

#include <iostream>
using namespace std;

#include <time.h>

#include "ocipl.h"


namespace OCIPL {


void SqlStatement::dump_results(XMLPos& pos, const XS_String& element_name)
{
	if (!(_state & EXECUTED))
		execute();	// instead of first_bulk()

	for(ResultIterator it(*this); it.has_next(); ++it) {
		pos.create(element_name);

		_res->dump_values(pos, it);

		pos.back();
	}
}

void SqlStatement::dump_results(XMLWriter& writer, const XS_String& element_name)
{
	if (!(_state & EXECUTED))
		execute();

	for(ResultIterator it(*this); it.has_next(); ++it) {
		writer.create(element_name);

		_res->dump_values(writer, it);

		writer.back();
	}
}


void SqlRecord::dump_values(XMLPos& pos, int row)
{
	ColumnVector::const_iterator it_type = _values.begin();

	for(ColumnVector::const_iterator it=_values.begin(); it!=_values.end(); ++it,++it_type)
		pos[it->_type._name] = it->_pvar->str(row, _env._errh);
}

void SqlRecord::dump_values(XMLWriter& writer, int row)
{
	ColumnVector::const_iterator it_type = _values.begin();

	for(ColumnVector::const_iterator it=_values.begin(); it!=_values.end(); ++it,++it_type)
		writer[it->_type._name] = it->_pvar->str(row, _env._errh);
}


} // namespace OCIPL
