示例#1
0
pgsOperand pgsGenReference::eval(pgsVarMap &vars) const
{
	// Evaluate parameters
	pgsOperand table(m_table->eval(vars));
	pgsOperand column(m_column->eval(vars));
	pgsOperand sequence(m_sequence->eval(vars));
	pgsOperand seed(m_seed->eval(vars));

	// Check parameters and create the generator
	if (table->is_string() && !table->value().IsEmpty() && column->is_string()
	        && !column->value().IsEmpty() && sequence->is_integer()
	        && seed->is_integer())
	{
		// Check wheter the table and the column do exist
		pgsOperand result = pgsExecute(wxString() << wxT("SELECT 1 FROM ")
		                               << table->value() << wxT(" WHERE ") << column->value()
		                               << wxT(" = ") << column->value(), 0, m_app).eval(vars);
		if (result->pgs_is_true())
		{
			long aux_sequence, aux_seed;
			sequence->value().ToLong(&aux_sequence);
			seed->value().ToLong(&aux_seed);
			return pnew pgsGenerator(pgsVariable::pgsTString,
			                         pnew pgsReferenceGen(m_app, table->value(),
			                                 column->value(), aux_sequence != 0, aux_seed));
		}
		else
		{
			throw pgsParameterException(wxString() << value()
			                            << wxT(":\ntable/column does not exist"));
		}
	}
	else
	{
		// Deal with errors
		if (!table->is_string() || table->value().IsEmpty())
		{
			throw pgsParameterException(wxString() << value()
			                            << wxT(":\ntable should be a non-empty string"));
		}
		else if (!column->is_string() || column->value().IsEmpty())
		{
			throw pgsParameterException(wxString() << value()
			                            << wxT(":\ncolumn should be a non-empty string"));
		}
		else if (!sequence->is_integer())
		{
			throw pgsParameterException(wxString() << value()
			                            << wxT(":\nsequence should be an integer"));
		}
		else
		{
			throw pgsParameterException(wxString() << value()
			                            << wxT(":\nseed should be an integer"));
		}
	}
}
示例#2
0
pgsReferenceGen * pgsReferenceGen::clone()
{
	return pnew pgsReferenceGen(*this);
}