~ubuntu-branches/ubuntu/utopic/pgadmin3/utopic-proposed

« back to all changes in this revision

Viewing changes to pgadmin/schema/pgTextSearchConfiguration.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2011-06-07 23:03:54 UTC
  • mfrom: (1.3.1 upstream) (13 sid)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110607230354-3td4j9y71u4ahcvj
Tags: 1.14.0~beta1-1
* New upstream development release, adding Build-Depends on
  postgresql-server-dev-all >= 117~.
* Add Build-Depends on quilt, (un)patch to debian/rules and patch for fixing
  the include for kwlist.h in pgadmin/db/keywords.c.
* Add pg_config --includedir-server output to CPPFLAGS.
* Remove unrecognized configure options: --with-wx-config,
  --with-pgsql-include, --enable-gtk2, --enable-unicode.
* Clean up manually the files that are left behind after the broken
  distclean.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//////////////////////////////////////////////////////////////////////////
2
2
//
3
3
// pgAdmin III - PostgreSQL Tools
4
 
// 
5
 
// Copyright (C) 2002 - 2010, The pgAdmin Development Team
 
4
//
 
5
// Copyright (C) 2002 - 2011, The pgAdmin Development Team
6
6
// This software is released under the PostgreSQL Licence
7
7
//
8
8
// pgTextSearchConfiguration.cpp - Text Search Configuration class
18
18
#include "schema/pgTextSearchConfiguration.h"
19
19
 
20
20
 
21
 
pgTextSearchConfiguration::pgTextSearchConfiguration(pgSchema *newSchema, const wxString& newName)
22
 
: pgSchemaObject(newSchema, textSearchConfigurationFactory, newName)
 
21
pgTextSearchConfiguration::pgTextSearchConfiguration(pgSchema *newSchema, const wxString &newName)
 
22
        : pgSchemaObject(newSchema, textSearchConfigurationFactory, newName)
23
23
{
24
24
}
25
25
 
27
27
{
28
28
}
29
29
 
 
30
wxString pgTextSearchConfiguration::GetTranslatedMessage(int kindOfMessage) const
 
31
{
 
32
        wxString message = wxEmptyString;
 
33
 
 
34
        switch (kindOfMessage)
 
35
        {
 
36
                case RETRIEVINGDETAILS:
 
37
                        message = _("Retrieving details on FTS configuration");
 
38
                        message += wxT(" ") + GetName();
 
39
                        break;
 
40
                case REFRESHINGDETAILS:
 
41
                        message = _("Refreshing FTS configuration");
 
42
                        message += wxT(" ") + GetName();
 
43
                        break;
 
44
                case DROPINCLUDINGDEPS:
 
45
                        message = wxString::Format(_("Are you sure you wish to drop FTS configuration \"%s\" including all objects that depend on it?"),
 
46
                                                   GetFullIdentifier().c_str());
 
47
                        break;
 
48
                case DROPEXCLUDINGDEPS:
 
49
                        message = wxString::Format(_("Are you sure you wish to drop FTS configuration \"%s\"?"),
 
50
                                                   GetFullIdentifier().c_str());
 
51
                        break;
 
52
                case DROPCASCADETITLE:
 
53
                        message = _("Drop FTS configuration cascaded?");
 
54
                        break;
 
55
                case DROPTITLE:
 
56
                        message = _("Drop FTS configuration?");
 
57
                        break;
 
58
                case PROPERTIESREPORT:
 
59
                        message = _("FTS configuration properties report");
 
60
                        message += wxT(" - ") + GetName();
 
61
                        break;
 
62
                case PROPERTIES:
 
63
                        message = _("FTS configuration properties");
 
64
                        break;
 
65
                case DDLREPORT:
 
66
                        message = _("FTS configuration DDL report");
 
67
                        message += wxT(" - ") + GetName();
 
68
                        break;
 
69
                case DDL:
 
70
                        message = _("FTS configuration DDL");
 
71
                        break;
 
72
                case DEPENDENCIESREPORT:
 
73
                        message = _("FTS configuration dependencies report");
 
74
                        message += wxT(" - ") + GetName();
 
75
                        break;
 
76
                case DEPENDENCIES:
 
77
                        message = _("FTS configuration dependencies");
 
78
                        break;
 
79
                case DEPENDENTSREPORT:
 
80
                        message = _("FTS configuration dependents report");
 
81
                        message += wxT(" - ") + GetName();
 
82
                        break;
 
83
                case DEPENDENTS:
 
84
                        message = _("FTS configuration dependents");
 
85
                        break;
 
86
        }
 
87
 
 
88
        return message;
 
89
}
 
90
 
30
91
bool pgTextSearchConfiguration::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
31
92
{
32
 
    wxString sql = wxT("DROP TEXT SEARCH CONFIGURATION ") + this->GetSchema()->GetQuotedIdentifier() + wxT(".") + this->GetIdentifier();
33
 
 
34
 
    if (cascaded)
35
 
        sql += wxT(" CASCADE");
36
 
 
37
 
    return GetDatabase()->ExecuteVoid(sql);
 
93
        wxString sql = wxT("DROP TEXT SEARCH CONFIGURATION ") + this->GetSchema()->GetQuotedIdentifier() + wxT(".") + this->GetIdentifier();
 
94
 
 
95
        if (cascaded)
 
96
                sql += wxT(" CASCADE");
 
97
 
 
98
        return GetDatabase()->ExecuteVoid(sql);
38
99
}
39
100
 
40
101
 
41
102
wxString pgTextSearchConfiguration::GetSql(ctlTree *browser)
42
103
{
43
 
    if (sql.IsNull())
44
 
    {
45
 
        sql = wxT("-- Text Search Configuration: ") + GetFullIdentifier() + wxT("\n\n")
46
 
            + wxT("-- DROP TEXT SEARCH CONFIGURATION ") + GetFullIdentifier() + wxT("\n\n")
47
 
            + wxT("CREATE TEXT SEARCH CONFIGURATION ") + GetFullIdentifier() + wxT(" (")
48
 
            + wxT("\n  PARSER = ") + qtTypeIdent(GetParser())
49
 
            + wxT("\n);\n");
50
 
 
51
 
        for (size_t i=0 ; i < tokens.GetCount() ; i++)
52
 
            sql += wxT("ALTER TEXT SEARCH CONFIGURATION ") + GetQuotedFullIdentifier()
53
 
                +  wxT(" ADD MAPPING FOR ") + tokens.Item(i).BeforeFirst('/') 
54
 
                +  wxT(" WITH ") + tokens.Item(i).AfterFirst('/') 
55
 
                +  wxT(";\n");
56
 
 
57
 
        if (!GetComment().IsNull())
58
 
            sql += wxT("COMMENT ON TEXT SEARCH CONFIGURATION ") + GetFullIdentifier()
59
 
            + wxT(" IS ") + qtDbString(GetComment()) + wxT(";\n");
60
 
    }
61
 
 
62
 
    return sql;
 
104
        if (sql.IsNull())
 
105
        {
 
106
                sql = wxT("-- Text Search Configuration: ") + GetFullIdentifier() + wxT("\n\n")
 
107
                      + wxT("-- DROP TEXT SEARCH CONFIGURATION ") + GetFullIdentifier() + wxT("\n\n")
 
108
                      + wxT("CREATE TEXT SEARCH CONFIGURATION ") + GetFullIdentifier() + wxT(" (")
 
109
                      + wxT("\n  PARSER = ") + qtTypeIdent(GetParser())
 
110
                      + wxT("\n);\n");
 
111
 
 
112
                for (size_t i = 0 ; i < tokens.GetCount() ; i++)
 
113
                        sql += wxT("ALTER TEXT SEARCH CONFIGURATION ") + GetQuotedFullIdentifier()
 
114
                               +  wxT(" ADD MAPPING FOR ") + tokens.Item(i).BeforeFirst('/')
 
115
                               +  wxT(" WITH ") + tokens.Item(i).AfterFirst('/')
 
116
                               +  wxT(";\n");
 
117
 
 
118
                if (!GetComment().IsNull())
 
119
                        sql += wxT("COMMENT ON TEXT SEARCH CONFIGURATION ") + GetFullIdentifier()
 
120
                               + wxT(" IS ") + qtDbString(GetComment()) + wxT(";\n");
 
121
        }
 
122
 
 
123
        return sql;
63
124
}
64
125
 
65
126
 
66
127
void pgTextSearchConfiguration::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
67
128
{
68
 
    if (properties)
69
 
    {
70
 
        CreateListColumns(properties);
 
129
        if (properties)
 
130
        {
 
131
                CreateListColumns(properties);
71
132
 
72
 
        properties->AppendItem(_("Name"), GetName());
73
 
        properties->AppendItem(_("OID"), GetOid());
74
 
        properties->AppendItem(_("Owner"), GetOwner());
75
 
        properties->AppendItem(_("Parser"), GetParser());
76
 
        properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
77
 
    }
 
133
                properties->AppendItem(_("Name"), GetName());
 
134
                properties->AppendItem(_("OID"), GetOid());
 
135
                properties->AppendItem(_("Owner"), GetOwner());
 
136
                properties->AppendItem(_("Parser"), GetParser());
 
137
                properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
 
138
        }
78
139
}
79
140
 
80
141
 
81
142
 
82
143
pgObject *pgTextSearchConfiguration::Refresh(ctlTree *browser, const wxTreeItemId item)
83
144
{
84
 
    pgObject *config=0;
85
 
    pgCollection *coll=browser->GetParentCollection(item);
86
 
    if (coll)
87
 
        config = textSearchConfigurationFactory.CreateObjects(coll, 0, wxT("\n   AND cfg.oid=") + GetOidStr());
88
 
 
89
 
    return config;
90
 
}
91
 
 
 
145
        pgObject *config = 0;
 
146
        pgCollection *coll = browser->GetParentCollection(item);
 
147
        if (coll)
 
148
                config = textSearchConfigurationFactory.CreateObjects(coll, 0, wxT("\n   AND cfg.oid=") + GetOidStr());
 
149
 
 
150
        return config;
 
151
}
 
152
 
 
153
 
 
154
wxString pgTextSearchConfigurationCollection::GetTranslatedMessage(int kindOfMessage) const
 
155
{
 
156
        wxString message = wxEmptyString;
 
157
 
 
158
        switch (kindOfMessage)
 
159
        {
 
160
                case RETRIEVINGDETAILS:
 
161
                        message = _("Retrieving details on FTS configurations");
 
162
                        break;
 
163
                case REFRESHINGDETAILS:
 
164
                        message = _("Refreshing FTS configurations");
 
165
                        break;
 
166
                case OBJECTSLISTREPORT:
 
167
                        message = _("FTS configurations list report");
 
168
                        break;
 
169
        }
 
170
 
 
171
        return message;
 
172
}
92
173
 
93
174
 
94
175
//////////////////////////////////////////////////////
96
177
 
97
178
pgObject *pgTextSearchConfigurationFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
98
179
{
99
 
    pgTextSearchConfiguration *config=0;
 
180
        pgTextSearchConfiguration *config = 0;
100
181
 
101
182
        pgSet *configurations;
102
183
        configurations = collection->GetDatabase()->ExecuteSet(
103
 
                wxT("SELECT cfg.oid, cfg.cfgname, pg_get_userbyid(cfg.cfgowner) as cfgowner, cfg.cfgparser, parser.prsname as parsername, description\n")
104
 
                wxT("  FROM pg_ts_config cfg\n")
105
 
                wxT("  LEFT OUTER JOIN pg_ts_parser parser ON parser.oid=cfg.cfgparser\n")
106
 
                wxT("  LEFT OUTER JOIN pg_description des ON des.objoid=cfg.oid\n")
107
 
                wxT(" WHERE cfg.cfgnamespace = ") + collection->GetSchema()->GetOidStr() 
108
 
                + restriction + wxT("\n")
109
 
                wxT(" ORDER BY cfg.cfgname"));
110
 
 
111
 
    if (configurations)
112
 
    {
113
 
        while (!configurations->Eof())
114
 
        {
115
 
            config = new pgTextSearchConfiguration(collection->GetSchema(), configurations->GetVal(wxT("cfgname")));
116
 
            config->iSetOid(configurations->GetOid(wxT("oid")));
117
 
            config->iSetOwner(configurations->GetVal(wxT("cfgowner")));
118
 
            config->iSetComment(configurations->GetVal(wxT("description")));
119
 
            config->iSetParser(configurations->GetVal(wxT("parsername")));
120
 
            config->iSetParserOid(configurations->GetOid(wxT("cfgparser")));
121
 
 
122
 
            pgSet *maps;
123
 
            maps = collection->GetDatabase()->ExecuteSet(
124
 
            wxT("SELECT\n")
125
 
            wxT("  (SELECT t.alias FROM pg_catalog.ts_token_type(cfgparser) AS t")
126
 
            wxT("    WHERE t.tokid = maptokentype) AS tokenalias,\n")
127
 
            wxT("  dictname\n")
128
 
            wxT("FROM pg_ts_config_map\n")
129
 
            wxT("  LEFT OUTER JOIN pg_ts_config ON mapcfg=pg_ts_config.oid\n")
130
 
            wxT("  LEFT OUTER JOIN pg_ts_dict ON mapdict=pg_ts_dict.oid\n")
131
 
            wxT("WHERE mapcfg=") + config->GetOidStr() + wxT("\n")
132
 
            wxT("ORDER BY 1, mapseqno"));
133
 
 
134
 
            if (maps)
135
 
            {
136
 
                wxString tokenToAdd;
137
 
                while (!maps->Eof())
138
 
                {
139
 
                    if (tokenToAdd.Length() > 0 &&
140
 
                      !tokenToAdd.BeforeFirst('/').IsSameAs(maps->GetVal(wxT("tokenalias")), false))
141
 
                    {
142
 
                        config->GetTokens().Add(tokenToAdd);
143
 
                        tokenToAdd = wxT("");
144
 
                    }
145
 
 
146
 
                    if (tokenToAdd.Length() == 0)
147
 
                        tokenToAdd = maps->GetVal(wxT("tokenalias")) + wxT("/") + maps->GetVal(wxT("dictname"));
148
 
                    else
149
 
                        tokenToAdd += wxT(",") + maps->GetVal(wxT("dictname"));
150
 
 
151
 
                    maps->MoveNext();
152
 
                }
153
 
 
154
 
                if (tokenToAdd.Length() > 0 &&
155
 
                  !tokenToAdd.BeforeFirst('/').IsSameAs(maps->GetVal(wxT("tokenalias")), false))
156
 
                {
157
 
                    config->GetTokens().Add(tokenToAdd);
158
 
                    tokenToAdd = wxT("");
159
 
                }
160
 
 
161
 
                delete maps;
162
 
            }
163
 
 
164
 
            if (browser)
165
 
            {
166
 
                browser->AppendObject(collection, config);
167
 
                            configurations->MoveNext();
168
 
            }
169
 
            else
170
 
                break;
171
 
        }
 
184
                             wxT("SELECT cfg.oid, cfg.cfgname, pg_get_userbyid(cfg.cfgowner) as cfgowner, cfg.cfgparser, parser.prsname as parsername, description\n")
 
185
                             wxT("  FROM pg_ts_config cfg\n")
 
186
                             wxT("  LEFT OUTER JOIN pg_ts_parser parser ON parser.oid=cfg.cfgparser\n")
 
187
                             wxT("  LEFT OUTER JOIN pg_description des ON des.objoid=cfg.oid\n")
 
188
                             wxT(" WHERE cfg.cfgnamespace = ") + collection->GetSchema()->GetOidStr()
 
189
                             + restriction + wxT("\n")
 
190
                             wxT(" ORDER BY cfg.cfgname"));
 
191
 
 
192
        if (configurations)
 
193
        {
 
194
                while (!configurations->Eof())
 
195
                {
 
196
                        config = new pgTextSearchConfiguration(collection->GetSchema(), configurations->GetVal(wxT("cfgname")));
 
197
                        config->iSetOid(configurations->GetOid(wxT("oid")));
 
198
                        config->iSetOwner(configurations->GetVal(wxT("cfgowner")));
 
199
                        config->iSetComment(configurations->GetVal(wxT("description")));
 
200
                        config->iSetParser(configurations->GetVal(wxT("parsername")));
 
201
                        config->iSetParserOid(configurations->GetOid(wxT("cfgparser")));
 
202
 
 
203
                        pgSet *maps;
 
204
                        maps = collection->GetDatabase()->ExecuteSet(
 
205
                                   wxT("SELECT\n")
 
206
                                   wxT("  (SELECT t.alias FROM pg_catalog.ts_token_type(cfgparser) AS t")
 
207
                                   wxT("    WHERE t.tokid = maptokentype) AS tokenalias,\n")
 
208
                                   wxT("  dictname\n")
 
209
                                   wxT("FROM pg_ts_config_map\n")
 
210
                                   wxT("  LEFT OUTER JOIN pg_ts_config ON mapcfg=pg_ts_config.oid\n")
 
211
                                   wxT("  LEFT OUTER JOIN pg_ts_dict ON mapdict=pg_ts_dict.oid\n")
 
212
                                   wxT("WHERE mapcfg=") + config->GetOidStr() + wxT("\n")
 
213
                                   wxT("ORDER BY 1, mapseqno"));
 
214
 
 
215
                        if (maps)
 
216
                        {
 
217
                                wxString tokenToAdd;
 
218
                                while (!maps->Eof())
 
219
                                {
 
220
                                        if (tokenToAdd.Length() > 0 &&
 
221
                                                !tokenToAdd.BeforeFirst('/').IsSameAs(maps->GetVal(wxT("tokenalias")), false))
 
222
                                        {
 
223
                                                config->GetTokens().Add(tokenToAdd);
 
224
                                                tokenToAdd = wxT("");
 
225
                                        }
 
226
 
 
227
                                        if (tokenToAdd.Length() == 0)
 
228
                                                tokenToAdd = maps->GetVal(wxT("tokenalias")) + wxT("/") + maps->GetVal(wxT("dictname"));
 
229
                                        else
 
230
                                                tokenToAdd += wxT(",") + maps->GetVal(wxT("dictname"));
 
231
 
 
232
                                        maps->MoveNext();
 
233
                                }
 
234
 
 
235
                                if (tokenToAdd.Length() > 0 &&
 
236
                                        !tokenToAdd.BeforeFirst('/').IsSameAs(maps->GetVal(wxT("tokenalias")), false))
 
237
                                {
 
238
                                        config->GetTokens().Add(tokenToAdd);
 
239
                                        tokenToAdd = wxT("");
 
240
                                }
 
241
 
 
242
                                delete maps;
 
243
                        }
 
244
 
 
245
                        if (browser)
 
246
                        {
 
247
                                browser->AppendObject(collection, config);
 
248
                                configurations->MoveNext();
 
249
                        }
 
250
                        else
 
251
                                break;
 
252
                }
172
253
 
173
254
                delete configurations;
174
 
    }
175
 
    return config;
 
255
        }
 
256
        return config;
176
257
}
177
258
 
178
259
 
179
 
#include "images/configuration.xpm"
180
 
#include "images/configurations.xpm"
 
260
#include "images/configuration.pngc"
 
261
#include "images/configurations.pngc"
181
262
 
182
 
pgTextSearchConfigurationFactory::pgTextSearchConfigurationFactory() 
183
 
: pgSchemaObjFactory(__("FTS Configuration"), __("New FTS Configuration..."), __("Create a new FTS Configuration."), configuration_xpm)
 
263
pgTextSearchConfigurationFactory::pgTextSearchConfigurationFactory()
 
264
        : pgSchemaObjFactory(__("FTS Configuration"), __("New FTS Configuration..."), __("Create a new FTS Configuration."), configuration_png_img)
184
265
{
185
266
}
186
267
 
187
268
 
188
269
pgTextSearchConfigurationFactory textSearchConfigurationFactory;
189
 
static pgaCollectionFactory cf(&textSearchConfigurationFactory, __("FTS Configurations"), configurations_xpm);
 
270
static pgaCollectionFactory cf(&textSearchConfigurationFactory, __("FTS Configurations"), configurations_png_img);