Exemplo n.º 1
0
bool CViewDatabase::SetViewState(const CStdString &path, int window, const CViewState &state)
{
  try
  {
    if (NULL == m_pDB.get()) return false;
    if (NULL == m_pDS.get()) return false;

    CStdString path1(path);
    CUtil::AddSlashAtEnd(path1);
    if (path1.IsEmpty()) path1 = "root://";

    CStdString sql = FormatSQL("select idView from view where window = %i and path like '%s'", window, path1.c_str());
    m_pDS->query(sql.c_str());
    if (!m_pDS->eof())
    { // update the view
      long idView = m_pDS->fv("idView").get_asLong();
      m_pDS->close();
      sql = FormatSQL("update view set viewMode=%i,sortMethod=%i,sortOrder=%i where idView=%i", state.m_viewMode, (int)state.m_sortMethod, (int)state.m_sortOrder, idView);
      m_pDS->exec(sql.c_str());
    }
    else
    { // add the view
      m_pDS->close();
      sql = FormatSQL("insert into view (idView, path, window, viewMode, sortMethod, sortOrder) values(NULL, '%s', %i, %i, %i, %i)", path1.c_str(), window, state.m_viewMode, (int)state.m_sortMethod, (int)state.m_sortOrder);
      m_pDS->exec(sql.c_str());
    }
  }
  catch (...)
  {
    CLog::Log(LOGERROR, "%s failed on path '%s'", __FUNCTION__, path.c_str());
  }
  return true;
}
Exemplo n.º 2
0
void * FbMasterInfoBase::Execute(wxEvtHandler * owner, FbThread * thread, const FbFilterObj &filter)
{
	if (thread->IsClosed()) return NULL;

	FbCommonDatabase database;
	database.JoinThread(thread);
	FbGenreFunction func_genre;
	FbAggregateFunction func_aggregate;
	database.CreateFunction(wxT("AGGREGATE"), 1, func_aggregate);
	database.CreateFunction(wxT("GENRE"), 1, func_genre);
	database.AttachConfig();
	if (thread->IsClosed()) return NULL;

	wxString sql;
	switch (GetMode()) {
		case FB2_MODE_LIST: sql = GetListSQL(database); break;
		case FB2_MODE_TREE: sql = GetTreeSQL(database); break;
	}
	sql = FormatSQL(sql, GetWhere(database), filter);

	FbSQLite3Statement stmt = database.PrepareStatement(sql);
	Bind(stmt);
	FbSQLite3ResultSet result = stmt.ExecuteQuery();
	if (!result.IsOk()) return NULL;

	switch (GetMode()) {
		case FB2_MODE_LIST: MakeList(owner, thread, result); break;
		case FB2_MODE_TREE: MakeTree(owner, thread, result); break;
	}
	return NULL;
}
Exemplo n.º 3
0
bool CViewDatabase::GetViewState(const CStdString &path, int window, CViewState &state)
{
  try
  {
    if (NULL == m_pDB.get()) return false;
    if (NULL == m_pDS.get()) return false;

    CStdString path1(path);
    CUtil::AddSlashAtEnd(path1);
    if (path1.IsEmpty()) path1 = "root://";

    CStdString sql = FormatSQL("select * from view where window = %i and path like '%s'", window, path1.c_str());
    m_pDS->query(sql.c_str());

    if (!m_pDS->eof())
    { // have some information
      state.m_viewMode = m_pDS->fv("viewMode").get_asInteger();
      state.m_sortMethod = (SORT_METHOD)m_pDS->fv("sortMethod").get_asInteger();
      state.m_sortOrder = (SORT_ORDER)m_pDS->fv("sortOrder").get_asInteger();
      m_pDS->close();
      return true;
    }
    m_pDS->close();
  }
  catch (...)
  {
    CLog::Log(LOGERROR, "%s, failed on path '%s'", __FUNCTION__, path.c_str());
  }
  return false;
}
Exemplo n.º 4
0
void CentralTestMachineClass::InsertToDatabase(TQuery* query)
{
    query -> Close();
    query -> SQL -> Clear();
    query->SQL->Add("Insert into c_test_machine "
        "(test_cid, machine_cid, machine_test_name, protocol, test_order) "
        "values ("
        ":tid, :mid, :tname, :pro, :to) ");
    FormatSQL( query );

    try
    {
        query -> ExecSQL();
    }
    catch(Exception& e)
    {
        if(e.Message != "Error creating cursor handle")
        {
            AnsiString strError =
                "Error inserting new CentralTestMachine.\n" + e.Message;
            Application->MessageBox(
                strError.c_str(),
                "CentralTestMachineClass Error",MB_OK);
            LogMod->LogCentralDb( TLogMod::LOGLOCAL, strError );
        }
    }
    LogMod->LogCentralDb( TLogMod::LOGLOCAL, query );
    LogMod->Commit( query );
}
Exemplo n.º 5
0
void CentralTestMachineClass::UpdateToDatabase(TQuery* query)
{
    // write updated record
    query -> SQL -> Clear();
    query->SQL->Add("Update c_test_machine set "
        "machine_test_name = :tname, "
        "protocol = :pro, "
        "test_order = :to "
        " where test_cid = :tid and "
        "       machine_cid = :mid ");
    FormatSQL( query );
    LogRecord( "Update: New record: " );

    query -> Prepare();
    try
    {
        query -> ExecSQL();
    }
    catch(Exception& e)
    {
        if(e.Message != "Error creating cursor handle")
        {
            AnsiString strError =
                "Error updating CentralTestMachine.\n" + e.Message;
            Application->MessageBox(
                strError.c_str(),
                "CentralTestMachineClass Error",MB_OK);
            LogMod->LogCentralDb( TLogMod::LOGLOCAL, strError );
        }
    }
    LogMod->LogCentralDb( TLogMod::LOGLOCAL, query );
    LogMod->Commit( query );
}
Exemplo n.º 6
0
bool CViewDatabase::ClearViewStates(int windowID)
{
  try
  {
    if (NULL == m_pDB.get()) return false;
    if (NULL == m_pDS.get()) return false;

    CStdString sql = FormatSQL("delete from view where window = %i", windowID);
    m_pDS->exec(sql.c_str());
  }
  catch (...)
  {
    CLog::Log(LOGERROR, "%s failed on window '%i'", __FUNCTION__, windowID);
  }
  return true;
}
Exemplo n.º 7
0
void ProfileClass::InsertToDatabase(TQuery* query)
{
    query -> Close();
    query -> SQL -> Clear();
    if ( theProject->isBeforeVersion( 2, 1 ) )
    {
        query->SQL->Add(
            "Insert into test_profile_description("
            "test_profile_id, test_profile_name, "
            "test_profile_description, date_last_modified, note_exists )"
            "values (:tpid, :name, :descr, :date, :note) ");
    }
    else
    {
        query->SQL->Add(
            "Insert into test_profile_description("
            "test_profile_id, test_profile_name, "
            "test_profile_description, date_last_modified, note_exists, profile_flags )"
            "values (:tpid, :name, :descr, :date, :note, :flag) ");
    }

    FormatSQL( query );

    try
    {
        query -> ExecSQL();
    }
    catch(Exception& e)
    {
        if(e.Message == "Error creating cursor handle")
        {
            //do nothing
        }
        else
        {
            AnsiString strError =
                "Error inserting test profile into database\n" + e.Message;
            Application->MessageBox(
                strError.c_str(),
                "ProfileClass Error",MB_OK);
            LogMod->LogProjectDb( TLogMod::LOGLOCAL, strError );
        }
    }
    LogMod->LogProjectDb( TLogMod::LOGLOCAL, query );
    LogMod->Commit( query );
}
Exemplo n.º 8
0
void ProfileClass::UpdateToDatabase(TQuery* query)
{
    // write updated record
    query -> SQL -> Clear();
    query->SQL->Add(
        "Update test_profile_description set "
        "test_profile_name = :name, "
        "test_profile_description = :descr, "
        "date_last_modified = :date, ");
    if ( !theProject->isBeforeVersion( 2, 1 ) )
    {
        query->SQL->Add(
            "profile_flags = :flag, ");
    }
    query->SQL->Add(
        "note_exists = :note "
        "where test_profile_id = :tpid");
    FormatSQL( query );
    LogRecord( "Update: New record: " );

    query -> Prepare();
    try
    {
        query -> ExecSQL();
    }
    catch(Exception& e)
    {
        if(e.Message != "Error creating cursor handle")
        {
            AnsiString strError =
                "Error inserting test profile descriptor\n" + e.Message;
            Application->MessageBox(
                strError.c_str(),
                "ProfileClass Error",MB_OK);
            LogMod->LogProjectDb( TLogMod::LOGLOCAL, strError );
        }
    }
    LogMod->LogProjectDb( TLogMod::LOGLOCAL, query );
    LogMod->Commit( query );
}