コード例 #1
0
ファイル: pgsReferenceGen.cpp プロジェクト: lhcezar/pgadmin3
pgsReferenceGen::pgsReferenceGen(pgsThread * app, const wxString & table,
		const wxString & column, const bool & sequence, const long & seed) :
	pgsObjectGen(seed), m_app(app), m_table(table), m_column(column),
			m_sequence(sequence)
{
	// We need an empty symbol table for calling pgsExecute.eval(...)
	pgsVarMap vars;
	
	// Count the number of lines in the table
	pgsOperand result = pgsExecute(wxString() << wxT("SELECT count(*) FROM ")
			<< m_table, 0, m_app).eval(vars);
	wxASSERT(result->is_record());
	wxString value = result->value();
	if (!value.IsEmpty())
	{
		m_nb_rows = pgsMapm::pgs_str_mapm(result->number().value());
	}
	else
	{
		m_nb_rows = 0;
	}
	wxLogScriptVerbose(wxT("REFGEN: Number of rows in %s: %s"), m_table.c_str(),
			pgsMapm::pgs_mapm_str(m_nb_rows).c_str());
	
	// Create an integer generator with that number of lines
	m_randomizer = pgsRandomizer(pnew pgsIntegerGen(0, m_nb_rows - 1,
			is_sequence(), m_seed));
}
コード例 #2
0
ファイル: pgsRegexGen.cpp プロジェクト: Joe-xXx/pgadmin3
pgsRegexGen::pgsRegexGen(const wxString &regex, const long &seed) :
	pgsObjectGen(seed), m_regex(regex), m_valid(true), m_string_gens(pgsVectorStringGen())
{
	wxLogScriptVerbose(wxT("REGEXGEN: %s"), m_regex.c_str());

	// Transform regular expression into XML structure
	bool escape = false, first_regex = true, list = false;
	wxString result = wxT("<regexpressions>\n");
	size_t i = 0;
	while (i < m_regex.Length())
	{
		if (escape)
		{
			if (list == true)
			{
				result.Append(espace_xml_char(m_regex[i]));
			}
			else
			{
				if (!first_regex)
					result.Append(wxT(" </regex>\n"));
				else
					first_regex = false;
				result.Append(wxT(" <regex>\n  <characters>"));
				result.Append(espace_xml_char(m_regex[i]));
				result.Append(wxT("</characters>\n"));
			}
			escape = false;
		}
		else if (list == true && m_regex[i] == wxT('-'))
		{
			if ((i + 1) < m_regex.Length())
			{
				result.Append(char_range(m_regex[i - 1], m_regex[i + 1]));
			}
		}
		else if (m_regex[i] == wxT('['))
		{
			if (!first_regex)
				result.Append(wxT(" </regex>\n"));
			else
				first_regex = false;
			result.Append(wxT(" <regex>\n  <characters>"));
			list = true;
		}
		else if (m_regex[i] == wxT(']'))
		{
			result.Append(wxT("</characters>\n"));
			list = false;
		}
		else if (m_regex[i] == wxT('{'))
		{
			result.Append(wxT("  <range>"));
			list = true;
		}
		else if (m_regex[i] == wxT('}'))
		{
			result.Append(wxT("</range>\n"));
			list = false;
		}
		else if (m_regex[i] == wxT('\\'))
		{
			escape = true;
		}
		else
		{
			if (list == true)
			{
				result.Append(espace_xml_char(m_regex[i]));
			}
			else
			{
				if (!first_regex)
					result.Append(wxT(" </regex>\n"));
				else
					first_regex = false;
				result.Append(wxT(" <regex>\n  <characters>"));
				result.Append(espace_xml_char(m_regex[i]));
				result.Append(wxT("</characters>\n"));
			}
		}

		++i;
	}
	if (result != wxT("<regexpressions>\n"))
		result.Append(wxT(" </regex>\n"));
	result.Append(wxT("</regexpressions>\n"));

	wxLogScriptVerbose(wxT("REGEXGEN: %s"), result.c_str());

	// Load this XML structure with the wxXmlDocument from wxWidgets
	wxStringInputStream input(result);
	wxXmlDocument doc;
	if (!doc.Load(input, wxT("UTF-8"), wxXMLDOC_KEEP_WHITESPACE_NODES))
	{
		m_valid = false;
	}
	else
	{
		// Start processing the XML file
		if (doc.GetRoot()->GetName() != wxT("regexpressions"))
		{
			m_valid = false;
		}
		else
		{
			// Go through XML nodes
			wxXmlNode *xml_regexpressions = doc.GetRoot()->GetChildren();
			while (xml_regexpressions && m_valid)
			{
				if (xml_regexpressions->GetName() == wxT("regex"))
				{
					wxXmlNode *xml_regex = xml_regexpressions->GetChildren();

					pgsRegex regex;
					regex.set_first(1);

					while (xml_regex && m_valid)
					{
						if (xml_regex->GetName() == wxT("characters"))
						{
							wxString content = xml_regex->GetNodeContent();
							for (size_t i = 0; i < content.Length(); i++)
							{
								regex.add_character(content[i]);
							}
						}
						else if (xml_regex->GetName() == wxT("range"))
						{
							wxString content = xml_regex->GetNodeContent();
							wxRegEx ex(wxT("^([0-9]+)(,([0-9]+))?$"));
							wxASSERT(ex.IsValid());
							if (ex.Matches(content))
							{
								long min;
								ex.GetMatch(content, 1).ToLong(&min);
								regex.set_first(min);
								wxString smax = ex.GetMatch(content, 3);
								if (!smax.IsEmpty())
								{
									long max;
									smax.ToLong(&max);
									regex.set_second(max);
								}
							}
							else
							{
								// m_valid = false;
							}
						}

						xml_regex = xml_regex->GetNext();
					}

					m_string_gens.Add(pgsStringGen(regex.get_first(),
					                               regex.get_second(), 1, seed,
					                               regex.get_characters()));
				}

				xml_regexpressions = xml_regexpressions->GetNext();
			}
		}
	}
}
コード例 #3
0
void pgsContext::pop_var()
{
	wxLogScriptVerbose(wxT("POP EXPR %s"), m_vars.back()->value().c_str());
	m_vars.pop_back();
}
コード例 #4
0
void pgsContext::push_var(pgsExpression * var)
{
	wxLogScriptVerbose(wxT("PUSH EXPR %s"), var->value().c_str());
	m_vars.push_back(var);
}
コード例 #5
0
void pgsContext::pop_stmt()
{
	wxLogScriptVerbose(wxT("POP STMT %s"), wxString(typeid(*(m_stmts.back()))
			.name(), wxConvUTF8).c_str());
	m_stmts.pop_back();
}
コード例 #6
0
void pgsContext::push_stmt(pgsStmt * stmt)
{
	wxLogScriptVerbose(wxT("PUSH STMT %s"), wxString(typeid(*stmt).name(),
			wxConvUTF8).c_str());
	m_stmts.push_back(stmt);
}