Example #1
0
bool SociContainer::begin(void)
{
	mRecordCount = 0;
	Progress prg("Open database", "Connecting ...");
	prg->setMaximum(prg->maximum()+2);

	if(!getSession())
	{
		prg->setValue(prg->value()+2);
		ErrorMessage(spt::logging::LoggingItem::LOG_ERROR, MODULENAME, "Unable to open database.");
		return false;
	}
	prg->setValue(prg->value()+1);
	if(isReader())
	{
		if(!prepareStatement(selectorToQuery()))
			return false;
	}
	prg->setValue(prg->value()+1);


	if(mSQLToFile)
	{
		mSQLFile.open(mSQLFilename, std::ios::out | std::ios::trunc);
		if(!mSQLFile.is_open())
		{
			ErrorMessage(spt::logging::LoggingItem::LOG_ERROR, MODULENAME, StdString("Unable to open the file: ")+mSQLFilename);
			return false;
		}
	}

	return true;
}
Example #2
0
void rpsArchive::io(void *dst, size_t size)
{
    if(isReader()) {
        read(dst, size);
    }
    else {
        write(dst, size);
    }
}
FilePanel *FileContainerBase::getFilePanel(void)
{
	if(mFilePanel == NULL)
	{
		mFilePanel = new FilePanel(isReader(), super::getMainWindow());
		mFilePanel->addPathListener(this);
	}

	return mFilePanel;
}
uint64_t findDocVer(DbMap *docStore, DocId docId, DocId txnId, uint64_t ts) {
	DbAddr *addr = fetchIdSlot(docStore, docId);
	DbMap *db = docStore->parent;
	uint64_t txnTs;

	//	examine all prior versions

	while (addr->bits) {
		DbDoc *doc = getObj(docStore, *addr);

		// is version in same txn?

		if (doc->txnId.bits == txnId.bits)
			return addr->bits;

		// is version committed?

		if (doc->docTs)
		  if (doc->docTs < ts)
			return addr->bits;

		// is txn committed?

		if (txnId.bits) {
			Txn *txn = fetchIdSlot(db, txnId);

			if (isCommitted(txn->ts) && ts >= txn->ts)
				return addr->bits;

            while (isReader((txnTs = txn->ts)) && txnTs < ts)
                compareAndSwap(&txn->ts, txnTs, ts);
		}

		addr = doc->oldDoc;
	}

	return 0;
}
Example #5
0
std::vector<DatabaseColumn *> SociContainer::readColumnsFromQuery(StdString const &oQuery, bool bLimit)
{
	std::vector<DatabaseColumn *> columns;
	StdString query = oQuery;

	if(query.length() == 0)
		return columns;

	Progress prg("Retrieve columns ...");
	if(mSession == NULL)
	{
		connect();
		if(mSession == NULL)
			return columns;
	}

	prg->setMaximum(prg->maximum()+1);
	soci::session &session = *mSession;
	prg->setLabelText("Retrieve columns ...");

	try
	{
		if(bLimit)
			query = limitQuery(query, 1);

		std::string q = query;
		soci::rowset<soci::row> rs = (session.prepare << q);
		soci::rowset<soci::row>::const_iterator it = rs.begin();
		if(it != rs.end())
		{
			soci::row const &row = *it;
			for(std::size_t i = 0; i < row.size(); i++)
			{
				const soci::column_properties &props = row.get_properties(i);

				DatabaseColumn *col = new DatabaseColumn();
				col->setName(props.get_name());
				col->setPosition(i);
				columns.push_back(col);

				switch(props.get_data_type())
				{
					case soci::dt_string:
						col->setType(spt::db::DataType::type_string);
					break;

					case soci::dt_double:
						col->setType(spt::db::DataType::type_decimal);
					break;

					case soci::dt_long_long:
					case soci::dt_integer:
					case soci::dt_unsigned_long_long:
						col->setType(spt::db::DataType::type_integer);
					break;

					case soci::dt_date:
					{
						col->setType(spt::db::DataType::type_date);
					}
					break;

					default:
					{
						col->setType(spt::db::DataType::type_unknown);
					}
				}
			}
		}
	}
	catch(std::runtime_error const &e)
	{
		if(isReader())
		{
			ErrorMessage(spt::logging::LoggingItem::LOG_ERROR, MODULENAME, "Unable to retrieve columns for query ["+query+"]");
			ErrorMessage(spt::logging::LoggingItem::LOG_ERROR, MODULENAME, e.what());
		}
	}

	prg->setValue(prg->value()+1);

	return columns;
}