Ejemplo n.º 1
0
StdString OracleWriter::getDateFormatString(StdString const &oValue, bool bTimestamp) const
{
    StdString pattern = "0000-00-00 00:00:00";

    if(oValue.length() == 10)
        return "YYYY.MM.DD";

    if(oValue.length() >= 19 || bTimestamp == false)
        return "YYYY.MM.DD HH24:MI:SS";

    pattern += ".";
    StdString format = "YYYY.MM.DD HH24:MI:SS.";

    StdString v = oValue.substr(pattern.length(), oValue.length());
    for(size_t i = 0; i < v.length(); i++)
    {
        if(v[i] >= '0' && v[i] <= '9')
        {
            format += 'F';
            continue;
        }
        break;
    }

    return format;
}
Ejemplo n.º 2
0
StdChar CSVWriterConfigPanel::getBracket(StdChar &oClose) const
{
	oClose = 0;

	if(mGUI->mQuoteBtn->isChecked())
	{
		oClose = '"';
		return '"';
	}

	if(mGUI->mParenthesisBtn->isChecked())
	{
		oClose = ')';
		return '(';
	}

	if(mGUI->mBracketBtn->isChecked())
	{
		oClose = ']';
		return '[';
	}

	if(mGUI->mCurlyBtn->isChecked())
	{
		oClose = '}';
		return '{';
	}

	if(mGUI->mSignBtn->isChecked())
	{
		oClose = '>';
		return '<';
	}

	if(mGUI->mCustomQuoteBtn->isChecked())
	{
		StdString s = spt::string::fromQt(mGUI->mSeparatorCustomTxt->text());
		if(s.length() > 0)
		{
			if(s.length() > 1)
				oClose = s[1];
			else
			{
				switch(s[0])
				{
					case '\'':
					case '"':
						oClose = s[0];
					break;
				}
			}

			return s[0];
		}
	}

	return 0;
}
Ejemplo n.º 3
0
StdString SociContainer::selectorToQuery(void)
{
	StdString q = getSelector();
	if(q.length() == 0)
		return q;

	if(q[0] == '{' && q != "{}" && q.length() > 1)
		q = "select * from "+ q.substr(1, q.length()-2);
	else
		q = mQuery;

	return q;
}
Ejemplo n.º 4
0
void SociContainer::setSelector(StdString const &oId)
{
	Progress prg("Loading from Table ...");

	if(oId.length() > 0 && oId[0] == '{') // If it is a table we select it
	{
		mTablename = oId.substr(1, oId.length()-2);
		selectTable(mTablename, false);
	}
	else
		mTablename = "";

	super::setSelector(oId);
	refreshPreview(selectorToQuery(), mPreviewLimit);
}
Ejemplo n.º 5
0
std::vector<DatabaseColumn *> SociContainer::readColumnsFromTable(StdString const &oTablename)
{
	if(oTablename.length() == 0)
		return std::vector<DatabaseColumn *>();

	return readColumnsFromQuery("select * from " +oTablename+" limit 1", false);
}
Ejemplo n.º 6
0
bool OracleWriter::prepareOpen(std::vector<DatabaseColumn *> const &oColumns)
{
    setSQLLog(createConfigPanel()->getPath(), createConfigPanel()->getExportSQL(), createConfigPanel()->getExportSQLOnly());
    if(!SociContainer::prepareOpen(oColumns))
        return false;

    OracleWriterPanel *wp = createConfigPanel();
    setAutocommit(wp->getAutoCommitCount());

    StdString table = getTablename();
    if(table.length() == 0)
    {
        ErrorMessage(spt::logging::LoggingItem::LOG_ERROR, MODULENAME, "No target table selected!");
        return false;
    }

    if(getSession() == NULL)
    {
        ErrorMessage(spt::logging::LoggingItem::LOG_ERROR, MODULENAME, "Database session not initialized!");
        return false;
    }

    if(mAllowTruncate)
    {
#warning TODO: Implement truncate
    }

    if(mAllowModifyColumns)
    {
#warning TODO: Implement modify columns
    }

    return true;
}
Ejemplo n.º 7
0
long Universe::getClassPathExt(vector<StdString>& tokens,
        const StdString& arg) const {
#define EXT_TOKENS 2
    long result = ERR_SUCCESS;
    long fpIndex = arg.find_last_of(fileSeparator);
    long ssepIndex = arg.find(".som");

    if (fpIndex == StdString::npos) { //no new path
        //different from CSOM (see also HandleArguments):
        //we still want to strip the suffix from the filename, so
        //we set the start to -1, in order to start the substring
        //from character 0. npos is -1 too, but this is to make sure
        fpIndex = -1;
        //instead of returning here directly, we have to remember that
        //there is no new class path and return it later
        result = ERR_FAIL;
    } else
        tokens[0] = arg.substr(0, fpIndex);

    //adding filename (minus ".som" if present) to second slot
    ssepIndex =
            ((ssepIndex != StdString::npos) && (ssepIndex > fpIndex)) ?
                    (ssepIndex - 1) : arg.length();
    tokens[1] = arg.substr(fpIndex + 1, ssepIndex - (fpIndex));
    return result;
}
Ejemplo n.º 8
0
StdChar CSVWriterConfigPanel::getSeparator(void)
{
	if(mGUI->mSeparatorSemicolonBtn->isChecked())
		return ';';

	if(mGUI->mSeparatorColonBtn->isChecked())
		return ':';

	if(mGUI->mSeparatorSpaceBtn->isChecked())
		return ' ';

	if(mGUI->mSeparatorTabBtn->isChecked())
		return '\t';

	if(mGUI->mSeparatorCommaBtn->isChecked())
		return ',';

	if(mGUI->mSeparatorCustomBtn->isChecked())
	{
		StdString s = spt::string::fromQt(mGUI->mSeparatorCustomTxt->text());
		if(s.length() > 0)
			return s[0];
	}

	return ';';
}
Ejemplo n.º 9
0
bool SociContainer::connect(StdString const &oConnectString)
{
	StdString con = getConnectString();

	if(oConnectString.length() > 0)
	{
		if(con != oConnectString)
		{
			disconnect();
			con = oConnectString;
		}
	}

	if(mSession != NULL) // Same connect string and session already exists.
		return true;

	if(con.length() == 0)
		return false;

	setConnectString(con);

	bool rc = true;
	Progress prg("Connecting to database");
	prg->setLabelText("Connecting to database ...");
	prg->setMaximum(prg->maximum()+1);

	QApplication::processEvents();
	StdString connectStr = sociConnectString(con);

	try
	{
		mSession = new soci::session(sociFactory(), connectStr);
		mSociConnectString = connectStr;
		refreshTables();
	}
	catch(std::runtime_error const &e)
	{
		mSociConnectString = "";
		ErrorMessage(spt::logging::LoggingItem::LOG_ERROR, MODULENAME, e.what());
		rc = false;
	}
	prg->setValue(prg->value()+1);

	return rc;
}
Ejemplo n.º 10
0
bool SociContainer::isTable(void)
{
	StdString t = getSelector();
	if(t.length() == 0)
		return true;

	if(t[0] == '{')
		return true;

	return false;
}
Ejemplo n.º 11
0
bool CSVContainer::connect(StdString const &oFilename)
{
    StdString fn = oFilename;
    if(fn.length() == 0)
        fn = getConnectString();

    if(fn.length() == 0)
        return false;

    bool rc = super::connect(fn);
    if(rc == false)
        return false;

    Progress prg("Open CSV", "Opening File");
    setRownum(0);
    CSV &csv = getCSV();
    if(fn.length() > 0)
    {
        CSV::ErrorCode rc;
        disconnect();

        csv.setFilename(fn);
        CSV::Openmode md = getOpenmode();
        if((rc = csv.open(md)) != CSV::ErrorCode::CSV_OK)
        {
            ErrorMessage(spt::logging::LoggingItem::LOG_ERROR, "CSV", "Unable to open "+fn);
            csv.setFilename("");
            return false;
        }
    }
    else
        return false;

    csv.rewind();

    return true;
}
Ejemplo n.º 12
0
bool CProjectSettings::CloseProjectSettings()
{
	// check bool if settings have changed
	if ( IsChangedSinceLastSave ) 
	{
		// popup to ask if save - yes/no/(cancel)
		int answer = AfxMessageBox( "Do you want to save the changes in the project?", MB_YESNOCANCEL );

		// do what the user clicked
		if (answer == IDCANCEL)
		{
			// Cancel: we dont want to do anything...
			return FALSE;
		}
		else if ( answer == IDYES )
		{
			// get the filename
			StdString fileName = getSaveFileName();

			// check if it is a valid path
			if ( fileName.length() == 0 )
			{
				// Selecting a file
				StdString typeExtension( _T("gdsprj") );
				StdString filterStr = "GDS project files (*." + typeExtension + ")|*." + typeExtension + "||"; 
				CFileDialog myFileDialog(FALSE, typeExtension, NULL, OFN_ENABLESIZING|OFN_EXPLORER|OFN_OVERWRITEPROMPT, filterStr);

				// set the file selector default dir to project dir
				myFileDialog.m_ofn.lpstrInitialDir = GetDirectory();

				// Adding it to the listBox
				if ( myFileDialog.DoModal() == IDOK ) 
				{
					// get the selected file with path
					fileName = myFileDialog.GetPathName();
					
					// saving the filename in the object as well
					setSaveFileName( fileName );
				}
				else
				{
					// the user clicked cancel: exiting save dialog
					return FALSE;
				}
			}

			// send message to make projectloader serialize us.
			CHashString hszProjectLoader(_T("CProjectLoadSave"));
			CHashString hszNewParticleSaveFilepath( fileName );
			static DWORD msgHash_SaveFile = CHashString(_T("SaveFile")).GetUniqueID();
			DWORD result = EngineGetToolBox()->SendMessage(msgHash_SaveFile, sizeof(TCHAR *), (void *)hszNewParticleSaveFilepath.GetString(), 0, &hszProjectLoader);

			// mark settings as saved
			IsChangedSinceLastSave = FALSE;
		}
		else
		{
			// we are here, if the user clicked NO SAVE
			// then we don't save anything, but return TRUE
			// that will lead to close GDS
			return TRUE;
		}
	}
	// Closing project destroys consistency	
	SetSettingsStateConsistency( FALSE );
	
	return TRUE;
}
Ejemplo n.º 13
0
std::vector<std::vector<StdString>> SociContainer::fetchRows(std::vector<DatabaseColumn *> &oColumns, StdString const &oQuery, bool &bException, int nCount)
{
	StdString t;
	StdString sql;
	std::vector<std::vector<StdString>> rows;
	bException = false;

	if(oQuery.length() == 0)
		return rows;

	Progress prg("Fetching rows ...");
	int n = 0;
	if(mSession == NULL)
	{
		connect();
		if(mSession == NULL)
		{
			ErrorMessage(spt::logging::LoggingItem::LOG_ERROR, MODULENAME, "Unable to connect to "+getConnectString());
			return rows;
		}
	}
	prg->setLabelText("Fetching rows ...");

	if(nCount > 0)
	{
		prg->setMaximum(prg->maximum()+nCount+1);
		sql = limitQuery(oQuery, nCount);
	}
	else
	{
		prg->setMaximum(prg->maximum()+1);
		sql = oQuery;
	}

	try
	{
		soci::rowset<soci::row> rs = (mSession->prepare << sql);
		for(soci::row const &row : rs)
		{
			QApplication::processEvents();
			if(prg->wasCanceled())
				break;

			n++;
			std::stringstream ss;
			ss << "Row "<< n << " ...";

			prg->setLabelText(spt::string::toQt(ss.str()));
			if(nCount)
				prg->setValue(prg->value()+1);

			rows.push_back(fromRow(oColumns, row));

			if(n >= nCount)
				break;
		}
	}
	catch(std::exception &e)
	{
		bException = true;
		ErrorMessage(spt::logging::LoggingItem::LOG_ERROR, MODULENAME, sql);
		ErrorMessage(spt::logging::LoggingItem::LOG_ERROR, MODULENAME, e.what());
	}
	n -= nCount;
	prg->setValue(prg->value()+1+n);

	return rows;
}
Ejemplo n.º 14
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;
}