Example #1
0
	Ptr<PropertyTable> Command::executeQuery()
	{
		mada_assert(isValid());

		Ptr<PropertyTable> table = PropertyTable::create();

		// Get result columns
		int numColumns = sqlite3_column_count(m_statement);
		if (numColumns < 0)
		{
			mada_throw_on_db_error(m_db->_getDbHandle(), numColumns);
		}

		for (int i = 0, end = numColumns; i < end; ++i)
		{
			const char* name = sqlite3_column_name(m_statement, i);
			if (name == NULL)
			{
				mada_throw_on_db_error(m_db->_getDbHandle(), SQLITE_ERROR);
			}

			PropertyDefinitionBase* pdb = PropertyDefinitionBase::findByName(name);

			mada_assert(pdb != NULL && "Unknown PropertyDefinition.");

			table->addColumn(PropertyId(pdb));
		}

		bool done = false;
		while (!done)
		{
			int resultCode = sqlite3_step(m_statement);

			if (resultCode == SQLITE_ROW)
			{
				addRow(table);
			}
			else if (resultCode == SQLITE_DONE)
			{
				done = true;
			}
			else
			{
				mada_throw_on_db_error(m_db->_getDbHandle(), resultCode);
			}
		}

		return table;
	}
Example #2
0
	PropertyId tail() const noexcept {
		assert(!empty());
		return PropertyId(objectsIt_ + 1, objectsEnd_);
	}