Esempio n. 1
0
wxArrayString TdsDatabaseLayer::GetViews()
{
  wxArrayString returnArray;

  DatabaseResultSet* pResult = NULL;
#ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS
  try
  {
#endif
    wxString query = _("sp_tables NULL, NULL, NULL, '''VIEW'''");
    pResult = ExecuteQuery(query);

    while (pResult->Next())
    {
      //wxPrintf(_("Adding view: '%s'\n"), pResult->GetResultString(_("TABLE_NAME")).Trim());
      returnArray.Add(pResult->GetResultString(_("TABLE_NAME")).Trim());
    }
#ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS
  }
  catch (DatabaseLayerException& e)
  {
    if (pResult != NULL)
    {
      CloseResultSet(pResult);
      pResult = NULL;
    }

    throw e;
  }
#endif

  if (pResult != NULL)
  {
    CloseResultSet(pResult);
    pResult = NULL;
  }

  return returnArray;
}
Esempio n. 2
0
wxArrayString wxPostgresDatabase::GetViews()
{
    wxArrayString returnArray;

    wxDatabaseResultSet* pResult = NULL;
#if wxUSE_DATABASE_EXCEPTIONS
    try
    {
#endif
        wxString query = _("SELECT table_name FROM information_schema.tables WHERE table_type='VIEW' AND table_schema='public';");
        pResult = ExecuteQuery(query);

        while (pResult->Next())
        {
            returnArray.Add(pResult->GetResultString(1));
        }
#if wxUSE_DATABASE_EXCEPTIONS
    }
    catch (wxDatabaseException& e)
    {
        if (pResult != NULL)
        {
            CloseResultSet(pResult);
            pResult = NULL;
        }

        throw e;
    }
#endif

    if (pResult != NULL)
    {
        CloseResultSet(pResult);
        pResult = NULL;
    }

    return returnArray;
}
wxArrayString FirebirdDatabaseLayer::GetViews()
{
  wxArrayString returnArray;

  DatabaseResultSet* pResult = NULL;
#ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS
  try
  {
#endif
    wxString query = _("SELECT RDB$RELATION_NAME FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG=0 AND RDB$VIEW_BLR IS NOT NULL");
    pResult = ExecuteQuery(query);

    while (pResult->Next())
    {
      returnArray.Add(pResult->GetResultString(1).Trim());
    }
#ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS
  }
  catch (DatabaseLayerException& e)
  {
    if (pResult != NULL)
    {
      CloseResultSet(pResult);
      pResult = NULL;
    }

    throw e;
  }
#endif

  if (pResult != NULL)
  {
    CloseResultSet(pResult);
    pResult = NULL;
  }

  return returnArray;
}
wxArrayString PostgresDatabaseLayer::GetTables()
{
  wxArrayString returnArray;

  DatabaseResultSet* pResult = NULL;
#ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS
  try
  {
#endif
    wxString query = _("SELECT table_name FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema='public';");
    pResult = ExecuteQuery(query);

    while (pResult->Next())
    {
      returnArray.Add(pResult->GetResultString(1));
    }
#ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS
  }
  catch (DatabaseLayerException& e)
  {
    if (pResult != NULL)
    {
      CloseResultSet(pResult);
      pResult = NULL;
    }

    throw e;
  }
#endif

  if (pResult != NULL)
  {
    CloseResultSet(pResult);
    pResult = NULL;
  }

  return returnArray;
}
Esempio n. 5
0
wxArrayString wxPostgresDatabase::GetPKColumns(const wxString& table)
{
    // Initialize variables
    wxArrayString returnArray;

    // Keep these variables outside of scope so that we can clean them up
    //  in case of an error
    wxPreparedStatement* pStatement = NULL;
    wxDatabaseResultSet* pResult = NULL;

#if wxUSE_DATABASE_EXCEPTIONS
    try
    {
#endif
        wxString query = _("SELECT pg_attribute.attname,format_type(pg_attribute.atttypid, pg_attribute.atttypmod) FROM pg_index, pg_class, pg_attribute WHERE   pg_class.oid = ? ::regclass AND   indrelid = pg_class.oid AND   pg_attribute.attrelid = pg_class.oid AND pg_attribute.attnum = any(pg_index.indkey) AND indisprimary;");
        pStatement = PrepareStatement(query);
        if (pStatement)
        {
            pStatement->SetParamString(1, table);
            pResult = pStatement->ExecuteQuery();
            if (pResult)
            {
                while (pResult->Next())
                {
                    returnArray.Add(pResult->GetResultString(wxT("attname")));
                }
            }
        }
#if wxUSE_DATABASE_EXCEPTIONS
    }
    catch (wxDatabaseException& e)
    {
        if (pResult != NULL)
        {
            CloseResultSet(pResult);
            pResult = NULL;
        }

        if (pStatement != NULL)
        {
            CloseStatement(pStatement);
            pStatement = NULL;
        }

        throw e;
    }
#endif

    if (pResult != NULL)
    {
        CloseResultSet(pResult);
        pResult = NULL;
    }

    if (pStatement != NULL)
    {
        CloseStatement(pStatement);
        pStatement = NULL;
    }

    return returnArray;
}
Esempio n. 6
0
wxArrayString wxPostgresDatabase::GetColumns(const wxString& table)
{
    // Initialize variables
    wxArrayString returnArray;

    // Keep these variables outside of scope so that we can clean them up
    //  in case of an error
    wxPreparedStatement* pStatement = NULL;
    wxDatabaseResultSet* pResult = NULL;

#if wxUSE_DATABASE_EXCEPTIONS
    try
    {
#endif
        wxString query = _("SELECT column_name FROM information_schema.columns WHERE table_name=? ORDER BY ordinal_position;");
        pStatement = PrepareStatement(query);
        if (pStatement)
        {
            pStatement->SetParamString(1, table);
            pResult = pStatement->ExecuteQuery();
            if (pResult)
            {
                while (pResult->Next())
                {
                    returnArray.Add(pResult->GetResultString(1));
                }
            }
        }
#if wxUSE_DATABASE_EXCEPTIONS
    }
    catch (wxDatabaseException& e)
    {
        if (pResult != NULL)
        {
            CloseResultSet(pResult);
            pResult = NULL;
        }

        if (pStatement != NULL)
        {
            CloseStatement(pStatement);
            pStatement = NULL;
        }

        throw e;
    }
#endif

    if (pResult != NULL)
    {
        CloseResultSet(pResult);
        pResult = NULL;
    }

    if (pStatement != NULL)
    {
        CloseStatement(pStatement);
        pStatement = NULL;
    }

    return returnArray;
}
Esempio n. 7
0
bool wxPostgresDatabase::ViewExists(const wxString& view)
{
    // Initialize variables
    bool bReturn = false;
    // Keep these variables outside of scope so that we can clean them up
    //  in case of an error
    wxPreparedStatement* pStatement = NULL;
    wxDatabaseResultSet* pResult = NULL;

#if wxUSE_DATABASE_EXCEPTIONS
    try
    {
#endif
        wxString query = _("SELECT COUNT(*) FROM information_schema.tables WHERE table_type='VIEW' AND table_name=?;");
        pStatement = PrepareStatement(query);
        if (pStatement)
        {
            pStatement->SetParamString(1, view);
            pResult = pStatement->ExecuteQuery();
            if (pResult)
            {
                if (pResult->Next())
                {
                    if(pResult->GetResultInt(1) != 0)
                    {
                        bReturn = true;
                    }
                }
            }
        }
#if wxUSE_DATABASE_EXCEPTIONS
    }
    catch (wxDatabaseException& e)
    {
        if (pResult != NULL)
        {
            CloseResultSet(pResult);
            pResult = NULL;
        }

        if (pStatement != NULL)
        {
            CloseStatement(pStatement);
            pStatement = NULL;
        }

        throw e;
    }
#endif

    if (pResult != NULL)
    {
        CloseResultSet(pResult);
        pResult = NULL;
    }

    if (pStatement != NULL)
    {
        CloseStatement(pStatement);
        pStatement = NULL;
    }

    return bReturn;
}
Esempio n. 8
0
wxArrayString TdsDatabaseLayer::GetColumns(const wxString& table)
{
  wxArrayString returnArray;

  // Keep these variables outside of scope so that we can clean them up
  //  in case of an error
/* -- Prepared statement support isn't working as well as it should so use concatenated wxStrings
  PreparedStatement* pStatement = NULL;
  DatabaseResultSet* pResult = NULL;

#ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS
  try
  {
#endif
    wxString query = _("sp_columns ?;");
    pStatement = PrepareStatement(query);
    if (pStatement)
    {
      pStatement->SetParamString(1, table);
      pResult = pStatement->ExecuteQuery();
      if (pResult)
      {
        while (pResult->Next())
        {
          //wxPrintf(_("Adding table: '%s'\n"), pResult->GetResultString(_("TABLE_NAME")).Trim());
          returnArray.Add(pResult->GetResultString(_("TABLE_NAME")).Trim());
        }
      }
    }
#ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS
  }
  catch (DatabaseLayerException& e)
  {
    if (pResult != NULL)
    {
      CloseResultSet(pResult);
      pResult = NULL;
    }

    if (pStatement != NULL)
    {
      CloseStatement(pStatement);
      pStatement = NULL;
    }

    throw e;
  }
#endif

  if (pResult != NULL)
  {
    CloseResultSet(pResult);
    pResult = NULL;
  }

  if (pStatement != NULL)
  {
    CloseStatement(pStatement);
    pStatement = NULL;
  }
*/
  DatabaseResultSet* pResult = NULL;
#ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS
  try
  {
#endif
    wxString query = wxString::Format(_("sp_columns %s;"), table.c_str());
    pResult = ExecuteQuery(query);

    while (pResult->Next())
    {
      //wxPrintf(_("Adding column: '%s'\n"), pResult->GetResultString(_("COLUMN_NAME")).Trim());
      returnArray.Add(pResult->GetResultString(_("COLUMN_NAME")).Trim());
    }
#ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS
  }
  catch (DatabaseLayerException& e)
  {
    if (pResult != NULL)
    {
      CloseResultSet(pResult);
      pResult = NULL;
    }

    throw e;
  }
#endif

  if (pResult != NULL)
  {
    CloseResultSet(pResult);
    pResult = NULL;
  }

  return returnArray;
}
Esempio n. 9
0
bool TdsDatabaseLayer::ViewExists(const wxString& view)
{
  bool bReturn = false;
  // Keep these variables outside of scope so that we can clean them up
  //  in case of an error
  PreparedStatement* pStatement = NULL;
  DatabaseResultSet* pResult = NULL;

#ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS
  try
  {
#endif
    wxString query = _("exec sp_tables ?, NULL, NULL, '''VIEW'''");
    pStatement = PrepareStatement(query);
    if (pStatement)
    {
      pStatement->SetParamString(1, view);
      pResult = pStatement->ExecuteQuery();
      if (pResult)
      {
        if (pResult->Next())
        {
          //wxPrintf(_("View found: '%s'\n"), pResult->GetResultString(_("TABLE_NAME")));
          if(view.CmpNoCase(pResult->GetResultString(_("TABLE_NAME"))) == 0)
          {
            bReturn = true;
          }
        }
      }
    }
#ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS
  }
  catch (DatabaseLayerException& e)
  {
    if (pResult != NULL)
    {
      CloseResultSet(pResult);
      pResult = NULL;
    }

    if (pStatement != NULL)
    {
      CloseStatement(pStatement);
      pStatement = NULL;
    }

    throw e;
  }
#endif

  if (pResult != NULL)
  {
    CloseResultSet(pResult);
    pResult = NULL;
  }

  if (pStatement != NULL)
  {
    CloseStatement(pStatement);
    pStatement = NULL;
  }

  return bReturn;
}
Esempio n. 10
0
wxArrayString FirebirdDatabaseLayer::GetColumns(const wxString& table)
{
  // Initialize variables
  wxArrayString returnArray;
  // Keep these variables outside of scope so that we can clean them up
  //  in case of an error
  PreparedStatement* pStatement = NULL;
  DatabaseResultSet* pResult = NULL;

#ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS
  try
  {
#endif
    wxString tableUpperCase = table.Upper();
    wxString query = _("SELECT RDB$FIELD_NAME FROM RDB$RELATION_FIELDS WHERE RDB$RELATION_NAME=?;");
    pStatement = PrepareStatement(query);
    if (pStatement)
    {
      pStatement->SetParamString(1, tableUpperCase);
      pResult = pStatement->ExecuteQuery();
      if (pResult)
      {
        while (pResult->Next())
        {
          returnArray.Add(pResult->GetResultString(1).Trim());
        }
      }
    }
#ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS
  }
  catch (DatabaseLayerException& e)
  {
    if (pResult != NULL)
    {
      CloseResultSet(pResult);
      pResult = NULL;
    }

    if (pStatement != NULL)
    {
      CloseStatement(pStatement);
      pStatement = NULL;
    }

    throw e;
  }
#endif

  if (pResult != NULL)
  {
    CloseResultSet(pResult);
    pResult = NULL;
  }

  if (pStatement != NULL)
  {
    CloseStatement(pStatement);
    pStatement = NULL;
  }

  return returnArray;
}
Esempio n. 11
0
bool FirebirdDatabaseLayer::ViewExists(const wxString& view)
{
  // Initialize variables
  bool bReturn = false;
  // Keep these variables outside of scope so that we can clean them up
  //  in case of an error
  PreparedStatement* pStatement = NULL;
  DatabaseResultSet* pResult = NULL;

#ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS
  try
  {
#endif
    wxString viewUpperCase = view.Upper();
    wxString query = _("SELECT COUNT(*) FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG=0 AND RDB$VIEW_BLR IS NOT NULL AND RDB$RELATION_NAME=?;");
    pStatement = PrepareStatement(query);
    if (pStatement)
    {
      pStatement->SetParamString(1, viewUpperCase);
      pResult = pStatement->ExecuteQuery();
      if (pResult)
      {
        if (pResult->Next())
        {
          if(pResult->GetResultInt(1) != 0)
          {
            bReturn = true;
          }
        }
      }
    }
#ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS
  }
  catch (DatabaseLayerException& e)
  {
    if (pResult != NULL)
    {
      CloseResultSet(pResult);
      pResult = NULL;
    }

    if (pStatement != NULL)
    {
      CloseStatement(pStatement);
      pStatement = NULL;
    }

    throw e;
  }
#endif

  if (pResult != NULL)
  {
    CloseResultSet(pResult);
    pResult = NULL;
  }

  if (pStatement != NULL)
  {
    CloseStatement(pStatement);
    pStatement = NULL;
  }

  return bReturn;
}