Пример #1
0
bool Postgres::DatabaseExists(const wxString& sDatabaseName)
  {
  if(!IsConnected())
    throw wx::Exception(wxT("Postgres::DatabaseExists() Database not connected."));

  // The query uses field 'datdba' as it's lightweight (int4)
  wxString sqryDatabaseExists = wxT("         \
SELECT datdba                                 \
FROM pg_database                              \
WHERE datname = $1;                           \
");

  // Unfortunately, SQL has a stupid rule about case folding.
  // PG holds table names internally as lower case.
  wxString sDbLower = sDatabaseName.Lower();

  ArrayRecord arParams;
  arParams.push_back(wxVariant(sDbLower));
  ArrayRecordArray ara;
  stc.CacheExecute
    (
    wxT("Postgres::DatabaseExists"),
    sqryDatabaseExists,
    arParams,
    ara
    );

  return (ara.size() > 0)? true : false;
  }
Пример #2
0
bool Postgres::TableExists(const wxString& sTableName)
  {
  if(!IsConnected())
    throw wx::Exception(wxT("Postgres::TableExists() Database not connected."));

  wxString sqryTableExists = wxT("            \
SELECT                                        \
  cl.relname                                  \
FROM                                          \
  pg_class cl                                 \
INNER JOIN                                    \
  pg_namespace ns                             \
ON                                            \
  cl.relnamespace = ns.oid                    \
WHERE                                         \
  ns.nspname = 'public'                       \
AND                                           \
  cl.reltype <> 0                             \
AND                                           \
  cl.relkind = 'r'                            \
AND                                           \
  cl.relname = $1;                            \
");

  ArrayRecord arParams;
  arParams.push_back(wxVariant(sTableName));
  ArrayRecordArray ara;
  stc.CacheExecute
    (
    wxT("Postgres::TableExists"),
    sqryTableExists,
    arParams,
    ara
    );

  return (ara.size() != 0)? true : false;;
  }
Пример #3
0
wxArrayString Postgres::GetTables()
  {
  if(!IsConnected())
    throw wx::Exception(wxT("Postgres::GetTables() Database not connected."));

  wxString sqryTables = wxT("                 \
SELECT                                        \
  relname                                     \
FROM                                          \
  pg_class cl                                 \
INNER JOIN                                    \
  pg_namespace ns                             \
ON                                            \
  cl.relnamespace = ns.oid                    \
WHERE                                         \
  ns.nspname = 'public'                       \
AND                                           \
  cl.reltype <> 0                             \
AND                                           \
  cl.relkind = 'r';                           \
");

  ArrayRecordArray ara;
  stc.CacheExecute
    (
    wxT("Postgres::GetTables"),
    sqryTables,
    ArrayRecord(),
    ara
    );

  ArrayRecord ar;
  for(ArrayRecordArray::iterator it = ara.begin(); it != ara.end(); it++)
    ar.push_back(it->at(0));

  return ar.GetArrayString();
  }