示例#1
0
bool ODBCStatementImpl::canBind() const
{
	if (!bindings().empty())
		return (*bindings().begin())->canBind();

	return false;
}
示例#2
0
void SQLiteStatementImpl::bindImpl()
{
	_stepCalled = false;
	_nextResponse = 0;
	if (_pStmt == 0) return;

	sqlite3_reset(_pStmt);

	int paramCount = sqlite3_bind_parameter_count(_pStmt);
	BindIt bindEnd = bindings().end();
	if (0 == paramCount || bindEnd == _bindBegin) 
	{
		_canBind = false;
		return;
	}

	std::size_t availableCount = 0;
	Bindings::difference_type bindCount = 0;
	Bindings::iterator it = _bindBegin;
	for (; it != bindEnd; ++it)
	{
		availableCount += (*it)->numOfColumnsHandled();
		if (availableCount <= paramCount) ++bindCount;
		else break;
	}

	Bindings::difference_type remainingBindCount = bindEnd - _bindBegin;
	if (bindCount < remainingBindCount)
	{
		bindEnd = _bindBegin + bindCount;
		_canBind = true;
	}
	else if (bindCount > remainingBindCount)
		throw ParameterCountMismatchException();

	std::size_t boundRowCount;
	if (_bindBegin != bindings().end())
	{
		boundRowCount = (*_bindBegin)->numOfRowsHandled();

		Bindings::iterator oldBegin = _bindBegin;
		for (std::size_t pos = 1; _bindBegin != bindEnd && (*_bindBegin)->canBind(); ++_bindBegin)
		{
			if (boundRowCount != (*_bindBegin)->numOfRowsHandled())
				throw BindingException("Size mismatch in Bindings. All Bindings MUST have the same size");

			(*_bindBegin)->bind(pos);
			pos += (*_bindBegin)->numOfColumnsHandled();
		}

		if ((*oldBegin)->canBind())
		{
			//container binding will come back for more, so we must rewind
			_bindBegin = oldBegin;
			_canBind = true;
		}
		else _canBind = false;
	}
}
bool SQLiteStatementImpl::canBind() const
{
	bool ret = false;
	if (!bindings().empty() && _pStmt)
		ret = (*bindings().begin())->canBind();

	return ret;
}
bool MySQLStatementImpl::canBind() const
{
	bool ret = false;

	if ((_stmt.state() >= StatementExecutor::STMT_COMPILED) && !bindings().empty())
		ret = (*bindings().begin())->canBind();

	return ret;
}
示例#5
0
void ODBCStatementImpl::doBind(bool clear, bool reset)
{
	if (clear) this->clear();
	Bindings& binds = bindings();
	if (!binds.empty())
	{
		Bindings::iterator it    = binds.begin();
		Bindings::iterator itEnd = binds.end();

		if (it != itEnd && 0 == _affectedRowCount)
			_affectedRowCount = static_cast<Poco::UInt32>((*it)->numOfRowsHandled());

		if (reset)
		{
			it = binds.begin();
			for (; it != itEnd; ++it) (*it)->reset();
		}

		for (std::size_t pos = 0; it != itEnd && (*it)->canBind(); ++it)
		{
			(*it)->bind(pos);
			pos += (*it)->numOfColumnsHandled();
		}
	}
}
示例#6
0
	Result<Eldritch2::UniquePointer<AssetView>>	MeshView::CreateView( Allocator& allocator, Device& device, DeviceMemoryPool& pool, const AssetLibrary& library, const Utf8Char* const name, Range<const char*> rawBytes ) {
		Eldritch2::UniquePointer<VkVertexInputAttributeDescription[]>	attributes( CreateInputAttributeDescriptions( allocator ) );
		Eldritch2::UniquePointer<VkVertexInputBindingDescription[]>		bindings( CreateVertexInputBindings( allocator ) );
		Eldritch2::UniquePointer<Submesh[]>								submeshes( CreateSubmeshes( allocator ) );
		UniquePointer<VkBuffer>											buffer;

		VkMemoryRequirements	memoryRequirements;
		vkGetBufferMemoryRequirements( device, buffer.Get(), &memoryRequirements );

		Result<DeviceMemoryPool::Allocation>	allocateMemoryResult( pool.TryAllocateRegion( memoryRequirements.size ) );
		if( !allocateMemoryResult ) {
			library.GetLog()( MessageSeverity::Error, "Unable to allocate device memory for mesh '{}'! (Size: {} bytes)" ET_UTF8_NEWLINE_LITERAL, name, memoryRequirements.size );
			return allocateMemoryResult.GetErrorCode();
		}

		const VkResult	bindMemoryResult( vkBindBufferMemory( device, buffer.Get(), pool.GetDeviceMemory(), allocateMemoryResult->GetOffsetIntoPoolInBytes() ) );
		if( VkResult::VK_SUCCESS != bindMemoryResult ) {
			library.GetLog()( MessageSeverity::Error, "Unable to bind device memory for mesh '{}'!" ET_UTF8_NEWLINE_LITERAL, name );
		}

		auto	result( MakeUnique<MeshView>( allocator, name, eastl::move( buffer ), eastl::move( *allocateMemoryResult ), eastl::move( attributes ), eastl::move( bindings ), eastl::move( submeshes ) ) );
		if( !result ) {
			return Error::OutOfMemory;
		}

		return eastl::move( result );
	}
void SQLiteStatementImpl::bindImpl()
{
	_stepCalled = false;
	_nextResponse = 0;
	if (_pStmt == 0) return;

	sqlite3_reset(_pStmt);

	// bind
	Bindings& binds = bindings();
	int pc = sqlite3_bind_parameter_count(_pStmt);
	if (binds.empty() && 0 == pc) return;
	if (binds.empty() && pc > 0) throw ParameterCountMismatchException();

	std::size_t pos = 1; // sqlite starts with 1 not 0!

	Bindings::iterator it    = binds.begin();
	Bindings::iterator itEnd = binds.end();
	for (; it != itEnd && (*it)->canBind(); ++it)
	{
		std::size_t nc = (*it)->numOfColumnsHandled();
		if (pos + nc > pc + 1) throw ParameterCountMismatchException();
		(*it)->bind(pos);
		pos += nc;
	}
}
void test_a_db_with_a_connection_with_tables::can_update_integer_attribute_bound_value()
{
	// insert new object
	DB::Statement statement = connection->prepare(
				"insert into object default values");
	CPPUNIT_ASSERT(statement.isValid());
	CPPUNIT_ASSERT(connection->execute(statement));
	long long object_id = connection->lastInsertRowId();
	CPPUNIT_ASSERT(object_id != 0);

	// insert integer attribute
	statement = connection->prepare(
				"insert into attribute_integer (value,type,object_id) values (%lld,%d,%lld)",
				1111,
				1235,
				object_id);
	CPPUNIT_ASSERT(statement.isValid());
	CPPUNIT_ASSERT(connection->execute(statement));

	// prepare update integer attribute statement
	statement = connection->prepare(
				"update attribute_integer set value=? where type=%d and object_id=%lld",
				1235,
				object_id);
	CPPUNIT_ASSERT(statement.isValid());

	// bind long long value to the parameter an update the record
	CPPUNIT_ASSERT(DB::Bindings(statement).bindInt64(1,2222));
	CPPUNIT_ASSERT(connection->execute(statement));

	// Retrieve the value from the record
	DB::Statement retrieveStmt = connection->prepare(
				"select value from attribute_integer as t where t.type=%d and t.object_id=%lld",
				1235,
				object_id);
	CPPUNIT_ASSERT(retrieveStmt.isValid());
	DB::Result result = connection->perform(retrieveStmt);
	CPPUNIT_ASSERT_EQUAL(result.getLongLong(1), (long long)2222);

	// verify that binding to a parameter before resetting the statement will fail.
	DB::LogErrorHandler eh = DB::setLogErrorHandler(dummy_print);
	DB::Bindings bindings(statement);
	CPPUNIT_ASSERT(!bindings.bindInt(1,3333));
	DB::setLogErrorHandler(eh);

	// reset statement and bind another value to the statement
	CPPUNIT_ASSERT(bindings.reset());
	CPPUNIT_ASSERT(bindings.bindInt(1,3333));

	// perform the update statement again with the newly bound value
	CPPUNIT_ASSERT(connection->execute(statement));

	// reset the retrieve statement and perform it again to get the latest value of the integer attribute
	CPPUNIT_ASSERT(retrieveStmt.reset());
	result = connection->perform(retrieveStmt);
	CPPUNIT_ASSERT(result.isValid());
	CPPUNIT_ASSERT_EQUAL(result.getLongLong(1), (long long)3333);
}
示例#9
0
bool Unification::unify(Predicate& p,Predicate& q,VarBinding& original_bindings){
	bool match = false;
	VarBinding bindings(original_bindings);
	if (name_match(p,q)){
		match = arguments_match(p,q,bindings);
	}
	if (match) original_bindings = bindings;
	return match;
}	
示例#10
0
messagewin::messagewin(cstring p, cstring opt):
	  targetif(targetif::query_target), 
	  toplevel(p.lower(), opt)
{
	sessionid = 0;
	info = false;
	serverentry = NULL;
	build_messagewindow(this);
	bindings();
}
void MySQLStatementImpl::bindImpl()
{
	Poco::Data::AbstractBindingVec& binds = bindings();
	std::size_t pos = 0;
	Poco::Data::AbstractBindingVec::iterator it = binds.begin();
	Poco::Data::AbstractBindingVec::iterator itEnd = binds.end();
	for (; it != itEnd && (*it)->canBind(); ++it)
	{
		(*it)->bind(pos);
		pos += (*it)->numOfColumnsHandled();
	}

	_stmt.bindParams(_binder.getBindArray(), _binder.size());
	_stmt.execute();
	_hasNext = NEXT_DONTKNOW;
}
void TestStatementImpl::bindImpl()
{
	// bind
	typedef Poco::Data::AbstractBindingVec Bindings;
	Bindings& binds = bindings();
	if (binds.empty())
		return;

	Bindings::iterator it    = binds.begin();
	Bindings::iterator itEnd = binds.end();
	std::size_t pos = 0;
	for (; it != itEnd && (*it)->canBind(); ++it)
	{
		(*it)->bind(pos);
		pos += (*it)->numOfColumnsHandled();
	}
}
示例#13
0
querywin::querywin(cstring p, cstring opt): 
	  targetif(targetif::query_target), 
          toplevel(cstring(".query") << _serial++, opt)

{
	sessionid = 0;
	serverentry = NULL;
	person = p;
	cstring dcc_status = tk->evaluate("dcc status " + p + " chat");
	if(dcc_status == "active")
		has_dcc = active;
	else
		has_dcc = none;
	use_dcc = false;
	build_querywindow(this);
	bindings();
	info = true;
}
示例#14
0
BOOL CIISConfigHelper::EnumWebSitesFromMetaBase(std::vector<IISWebSite>& sites)
{
	sites.clear();

	CIISMetaBase MetaBase;
	CComPtr<IMSAdminBase> pAdminBase;
	std::vector<std::wstring> Keys;

	// connect to the metabase
	if (MetaBase.Init() == false ||
		MetaBase.GetAdminBase(&pAdminBase) == false ||
		MetaBase.EnumKeys(_T("/LM/W3SVC"), Keys) == false)
	{
		return FALSE;
	}

	// loop thru the metabase keys
	int nKeys = (int) Keys.size();
	for (int i = 0; i < nKeys; i++)
	{
		std::wstring sKey = Keys[i];

		std::wstring sKeyPath = L"/LM/W3SVC/";
		sKeyPath += sKey;

		CIISMetaBaseData KeyType;
		if (KeyType.ReadData(pAdminBase, sKeyPath.c_str(), MD_KEY_TYPE) == false)
			continue;

		std::wstring sKeyType;
		if (KeyType.GetAsString(sKeyType) == false)
			continue;

		// we are looking for web servers
		if (sKeyType.compare(L"IIsWebServer") != 0)
			continue;

		CString sDescription = CString(sKey.c_str());

		std::wstring sComment;
		CIISMetaBaseData Description;
		if (Description.ReadData(pAdminBase, sKeyPath.c_str(), MD_SERVER_COMMENT) == true)
		{			
			Description.GetAsString(sComment);			
		}

		std::wstring sKeyPathForVR = sKeyPath + L"/ROOT";		

		CIISMetaBaseData VRPath;
		if (VRPath.ReadData(pAdminBase, sKeyPathForVR.c_str(), MD_VR_PATH) == false)
			continue;

		std::wstring sVRPath;
		if (VRPath.GetAsString(sVRPath) != true)
			continue;		

		IISWebSite item;
		item.eSource = IISWebSite::Metabase;
		item.sInstance = sKey.c_str();
		item.sMetaBasePath = sKeyPath.c_str();		
		item.sDescription = sComment.c_str();
		item.sFileSystemPath = sVRPath.c_str();			

		CIISMetaBaseData ServerBindings;
		if (ServerBindings.ReadData(pAdminBase, sKeyPath.c_str(), MD_SERVER_BINDINGS) == true)
		{
			std::vector<std::wstring> Ports;
			if (ServerBindings.GetAsStringVector(Ports) == true)			
			{
				size_t nPorts = Ports.size();
				for (size_t i = 0; i < nPorts; i++)
				{
					if (Ports[i].size() == 0)
						continue;

					IISWebSiteBindings bindings(Ports[i].c_str());			
					item.Ports.Add(bindings);			
				}
			}
		}

		CIISMetaBaseData SecureBindings;
		if (SecureBindings.ReadData(pAdminBase, sKeyPath.c_str(), MD_SECURE_BINDINGS) == true)
		{
			std::vector<std::wstring> SecurePorts;
			if (SecureBindings.GetAsStringVector(SecurePorts) == true)
			{
				size_t nSecurePorts = SecurePorts.size();
				for (size_t i = 0; i < nSecurePorts; i++)
				{
					if (SecurePorts[i].size() == 0)
						continue;			

					IISWebSiteBindings bindings(SecurePorts[i].c_str());
					item.SecurePorts.Add(bindings);
				}				
			}
		}

		sites.push_back(item);
	}	

	return TRUE;
}
示例#15
0
RIFActionBlock RIFActionBlock::parse(DPtr<uint8_t> *utf8str)
    throw(BadAllocException, SizeUnknownException,
          InvalidCodepointException, InvalidEncodingException,
          MalformedIRIRefException, TraceableException) {
  if (utf8str == NULL) {
    THROW(TraceableException, "utf8str must not be NULL.");
  }
  if (!utf8str->sizeKnown()) {
    THROWX(SizeUnknownException);
  }
  const uint8_t *begin = utf8str->dptr();
  const uint8_t *end = begin + utf8str->size();
  const uint8_t *mark = begin;
  for (; mark != end && is_space(*mark); ++mark) {
    // find beginning of action block
  }
  if (end - mark < 4) {
    THROW(TraceableException, "Could not find action block.");
  }
  if (ascii_strncmp(mark, "Do", 2) != 0) {
    THROW(TraceableException, "Action block must start with \"Do\".");
  }
  mark += 2;
  for (; mark != end && is_space(*mark); ++mark) {
    // search for left parenthesis
  }
  if (mark == end || *mark != to_ascii('(')) {
    THROW(TraceableException, "Could not find opening parenthesis.");
  }
  for (--end; end != mark && is_space(*end); --end) {
    // find right parenthesis
  }
  if (end == mark || *end != to_ascii(')')) {
    THROW(TraceableException, "Could not find closing parenthesis.");
  }
  for (--end; end != mark && is_space(*end); --end) {
    // find end of last action
  }
  ++end;
  for (++mark; mark != end && is_space(*mark); ++mark) {
    // find first binding or action
  }
  if (mark == end) {
    THROW(TraceableException, "Action block is (illegaly) empty.");
  }
  deque<RIFAction> actions;
  ActVarMap bindings(RIFVar::cmplt0);
  bool find_bindings = (*mark == to_ascii('('));
  const uint8_t *bound = mark;
  while (bound != end) {
    for (; bound != end && *bound != to_ascii(')'); ++bound) {
      // find end of action block binding or action... maybe
    }
    if (bound != end) {
      ++bound;
    }
    DPtr<uint8_t> *str = utf8str->sub(mark - begin, bound - mark);
    if (find_bindings) {
      try {
        RIFActVarBind bind = RIFActVarBind::parse(str);
        str->drop();
        str = NULL;
        pair<ActVarMap::iterator, bool> p = bindings.insert(
            pair<RIFVar, RIFActVarBind>(bind.getActVar(), bind));
        if (!p.second) {
          THROW(TraceableException,
                "Cannot have multiple bindings for same action variable.");
        }
      } catch (BadAllocException &e) {
        str->drop();
        RETHROW(e, "Cannot parse action variable binding.");
      } catch (InvalidCodepointException &e) {
        str->drop();
        RETHROW(e, "Cannot parse action variable binding.");
      } catch (InvalidEncodingException &e) {
        str->drop();
        RETHROW(e, "Cannot parse action variable binding.");
      } catch (MalformedIRIRefException &e) {
        str->drop();
        continue;
      } catch (TraceableException &e) {
        if (str == NULL) {
          RETHROW(e, "Malformed action block.");
        }
        str->drop();
        continue;
      }
    } else {
      try {
        RIFAction act = RIFAction::parse(str);
        str->drop();
        actions.push_back(act);
      } catch (BadAllocException &e) {
        str->drop();
        RETHROW(e, "Cannot parse action.");
      } catch (InvalidCodepointException &e) {
        str->drop();
        RETHROW(e, "Cannot parse action.");
      } catch (InvalidEncodingException &e) {
        str->drop();
        RETHROW(e, "Cannot parse action.");
      } catch (MalformedIRIRefException &e) {
        str->drop();
        continue;
      } catch (TraceableException &e) {
        str->drop();
        continue;
      }
    }
    for (mark = bound; mark != end && is_space(*mark); ++mark) {
      // find beginning of next action block binding or action... maybe
    }
    bound = mark;
    find_bindings = find_bindings && (*mark == to_ascii('('));
  }
  DPtr<RIFAction> *pact;
  try {
    NEW(pact, APtr<RIFAction>, actions.size());
  } RETHROW_BAD_ALLOC
  copy(actions.begin(), actions.end(), pact->dptr());
  try {
    RIFActionBlock block(pact, bindings);
    pact->drop();
    return block;
  } catch (TraceableException &e) {
    pact->drop();
    RETHROW(e, "Cannot parse action block.");
  }
}
void SQLiteStatementImpl::compileImpl()
{
	if (!_pLeftover)
	{
		_bindBegin = bindings().begin();
	}

	std::string statement(toString());

	sqlite3_stmt* pStmt = 0;
	const char* pSql = _pLeftover ? _pLeftover->c_str() : statement.c_str();

	if (0 == std::strlen(pSql))
		throw InvalidSQLStatementException("Empty statements are illegal");

	int rc = SQLITE_OK;
	const char* pLeftover = 0;
	bool queryFound = false;

	do
	{
		rc = sqlite3_prepare_v2(_pDB, pSql, -1, &pStmt, &pLeftover);
		if (rc != SQLITE_OK)
		{
			if (pStmt) sqlite3_finalize(pStmt);
			pStmt = 0;
			std::string errMsg = sqlite3_errmsg(_pDB);
			Utility::throwException(_pDB, rc, errMsg);
		}
		else if (rc == SQLITE_OK && pStmt)
		{
			queryFound = true;
		}
		else if (rc == SQLITE_OK && !pStmt) // comment/whitespace ignore
		{
			pSql = pLeftover;
			if (std::strlen(pSql) == 0)
			{
				// empty statement or an conditional statement! like CREATE IF NOT EXISTS
				// this is valid
				queryFound = true;
			}
		}
	} while (rc == SQLITE_OK && !pStmt && !queryFound);

	//Finalization call in clear() invalidates the pointer, so the value is remembered here.
	//For last statement in a batch (or a single statement), pLeftover == "", so the next call
	// to compileImpl() shall return false immediately when there are no more statements left.
	std::string leftOver(pLeftover);
	trimInPlace(leftOver);
	clear();
	_pStmt = pStmt;
	if (!leftOver.empty())
	{
		_pLeftover = new std::string(leftOver);
		_canCompile = true;
	}
	else _canCompile = false;

	_pBinder = new Binder(_pStmt);
	_pExtractor = new Extractor(_pStmt);

	if (SQLITE_DONE == _nextResponse && _isExtracted)
	{
		//if this is not the first compile and there has already been extraction
		//during previous step, switch to the next set if there is one provided
		if (hasMoreDataSets())
		{
			activateNextDataSet();
			_isExtracted = false;
		}
	}

	int colCount = sqlite3_column_count(_pStmt);

	if (colCount)
	{
		std::size_t curDataSet = currentDataSet();
		if (curDataSet >= _columns.size()) _columns.resize(curDataSet + 1);
		for (int i = 0; i < colCount; ++i)
		{
			MetaColumn mc(i, sqlite3_column_name(_pStmt, i), Utility::getColumnType(_pStmt, i));
				_columns[curDataSet].push_back(mc);
		}
	}
}
示例#17
0
Value Interpreter::exec(const InstructionList &instructions)
{
	Bindings bindings(&globals_);
	return exec(instructions, bindings);
}