bool TransactionExecStatemachine_sqlite3::bind( std::size_t idx, const types::VariantConst& value)
{
	if (value.defined())
	{
		LOG_TRACE << "[sqlite3 statement] CALL bind( " << idx << ", '" << value << "', " << value.typeName( ) << " )";
	}
	else
	{
		LOG_TRACE << "[sqlite3 statement] CALL bind( " << idx << ", NULL)";
	}
	if (m_state != CommandReady && m_state != Executed)
	{
		return errorStatus( std::string( "call of bind not allowed in state '") + stateName(m_state) + "'");
	}

	try {
		m_statement->bind( idx, value );
		int rc = static_cast<SQLiteStatement *>( m_statement )->getLastStatus( );
		return status( rc, CommandReady );
	} catch( const std::runtime_error &e ) {
		return errorStatus( e.what( ) );
	}
	return true;
}
Esempio n. 2
0
bool ToStringFilter::print( ElementType type, const types::VariantConst& element)
{
	if (m_taglevel < 0)
	{
		throw std::runtime_error("illegal print operation in tostring filter (print atfter final close)");
	}
	switch (type)
	{
		case OpenTag:
			++m_taglevel;
			m_content.append( m_indent);
			m_content.append( element.tostring());
			if (m_indentstr.size())
			{
				m_content.append( " {\n");
				m_indent.append( m_indentstr);
			}
			else
			{
				m_content.append( " { ");
			}
			m_lasttype = type;
		return true;
		case CloseTag:
			--m_taglevel;
			if (m_taglevel < 0)
			{
				return true;
			}
			if (m_indentstr.size())
			{
				if (m_indent.size() >= m_indentstr.size())
				{
					m_indent.resize( m_indent.size() - m_indentstr.size());
				}
				if (m_lasttype != CloseTag)
				{
					m_content.push_back( '\n');
				}
				m_content.append( m_indent);
				m_content.append( "}\n");
			}
			else
			{
				m_content.append( "} ");
			}
			m_lasttype = type;
		return true;
		case Attribute:
			m_content.append( m_indent);
			m_lasttype = type;
			m_content.append( element.tostring());
		return true;
		case Value:
			if (m_lasttype == Attribute)
			{
				m_content.append( "='");
				m_content.append( substquot( element.tostring()));
				m_content.append( "' ");
				m_lasttype = OpenTag;
			}
			else
			{
				m_content.append( m_indent);
				m_content.append( "'");
				m_content.append( substquot( element.tostring()));
				m_content.append( "' ");
				m_lasttype = type;
			}
		return true;
	}
	throw std::runtime_error( "illegal type printed");
}
bool TdlTransactionFunctionClosure::InputStructure::print( ElementType type, const types::VariantConst& element)
{
	LOG_DATA << "[transaction input] push element " << langbind::InputFilter::elementTypeName( type) << " '" << utils::getLogString( element) << "'' :" << element.typeName( element.type());
	switch (type)
	{
		case langbind::TypedInputFilter::OpenTag:
			m_structure->openTag( element);
		break;
		case langbind::TypedInputFilter::CloseTag:
			m_structure->closeTag();
		break;
		case langbind::TypedInputFilter::Attribute:
			m_structure->openTag( element);
		break;
		case langbind::TypedInputFilter::Value:
			m_structure->pushValue( element);
			if (m_lasttype == langbind::TypedInputFilter::Attribute)
			{
				m_structure->closeTag();
			}
		break;
	}
	m_lasttype = type;
	return true;
}