예제 #1
0
//----------------------------------------------------------------------------
QSqlDatabase ctkPluginStorageSQL::getConnection(bool create) const
{
  if (m_connectionNames.hasLocalData() && QSqlDatabase::contains(m_connectionNames.localData()))
  {
    return QSqlDatabase::database(m_connectionNames.localData());
  }

  if (!create)
  {
    throw ctkPluginDatabaseException(QString("No database connection."),
      ctkPluginDatabaseException::DB_NOT_OPEN_ERROR);
  }

  m_connectionNames.setLocalData(getConnectionName());

  QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE", m_connectionNames.localData());
  database.setDatabaseName(getDatabasePath());

  if (!database.isValid())
  {
    close();
    throw ctkPluginDatabaseException(QString("Invalid database connection: %1").arg(m_connectionNames.localData()),
      ctkPluginDatabaseException::DB_CONNECTION_INVALID);
  }

  if (!database.open())
  {
    close();
    throw ctkPluginDatabaseException(QString("Could not open database connection: %1 (%2)").arg(m_connectionNames.localData()).arg(database.lastError().text()),
      ctkPluginDatabaseException::DB_SQL_ERROR);
  }

  return database;
}
예제 #2
0
    bool SQLiteBackend::dbOpened()
    {
        QSqlDatabase db = QSqlDatabase::database(getConnectionName());
        QSqlQuery query(db);

        bool status = query.exec("PRAGMA journal_mode = WAL;");

        if (status)
            status = query.exec("PRAGMA synchronous = NORMAL;"); // TODO: dangerous, use some backups?

        if (status)
            status = query.exec("PRAGMA foreign_keys = ON;");

        if (status)
            status = Database::ASqlBackend::dbOpened();

        return status;
    }
예제 #3
0
string ClsFEConnection::validate(){
//    cout << "ClsFEConnection::validate()" << endl;
    string strMessage = "";


    if(pSynapse==NULL){
//	strMessage = getParameter(ClsTagLibrary::NameTag())->getValueAsString(); //--
//	strMessage = "Connection " + strSourceGroupName + "->" + strTargetGroupName;
	strMessage.append("\n\tNo Synapse defined");
    }

    if(strConnectionSourceID.size()<=0){
//	strMessage = getParameter(ClsTagLibrary::NameTag())->getValueAsString(); //--
	strMessage.append("\n\tNo source defined");
    }

    if(strConnectionTargetID.size()<=0){
//	strMessage = getParameter(ClsTagLibrary::NameTag())->getValueAsString(); //--
	strMessage.append("\n\tNo target defined");
    }


    if(listIndexQuadruples.size()<=0){
	strMessage.append("\n\tNo synapses defined");
    }


    if(strMessage.size()>0){
	string strSourceGroupName = ClsFESystemManager::Instance()->getGroupName(strConnectionSourceID).c_str();
	string strTargetGroupName = ClsFESystemManager::Instance()->getGroupName(strConnectionTargetID).c_str();
	strMessage = "Connection \"" + getConnectionName() + "\"\n(\"" + strSourceGroupName + "\"->\"" + strTargetGroupName + "\")" + strMessage;

    }


    return strMessage;

}