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

« back to all changes in this revision

Viewing changes to pgadmin/schema/edbPackageFunction.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
// edbPackageFunction.cpp - EnterpriseDB Package member function
18
18
#include "schema/edbPackageFunction.h"
19
19
 
20
20
 
21
 
edbPackageFunction::edbPackageFunction(edbPackage *newPackage, const wxString& newName)
22
 
: edbPackageObject(newPackage, packageFunctionFactory, newName)
23
 
{
24
 
}
25
 
 
26
 
edbPackageFunction::edbPackageFunction(edbPackage *newPackage,pgaFactory &factory, const wxString& newName)
27
 
: edbPackageObject(newPackage, factory, newName)
28
 
{
29
 
}
30
 
 
31
 
edbPackageProcedure::edbPackageProcedure(edbPackage *newPackage, const wxString& newName)
32
 
: edbPackageFunction(newPackage, packageProcedureFactory, newName)
 
21
edbPackageFunction::edbPackageFunction(edbPackage *newPackage, const wxString &newName)
 
22
        : edbPackageObject(newPackage, packageFunctionFactory, newName)
 
23
{
 
24
}
 
25
 
 
26
edbPackageFunction::edbPackageFunction(edbPackage *newPackage, pgaFactory &factory, const wxString &newName)
 
27
        : edbPackageObject(newPackage, factory, newName)
 
28
{
 
29
}
 
30
 
 
31
edbPackageProcedure::edbPackageProcedure(edbPackage *newPackage, const wxString &newName)
 
32
        : edbPackageFunction(newPackage, packageProcedureFactory, newName)
33
33
{
34
34
}
35
35
 
36
36
wxString edbPackageFunction::GetFullName()
37
 
38
 
    return GetName() + wxT("(") + GetArgSigList() + wxT(")");
 
37
{
 
38
        return GetName() + wxT("(") + GetArgSigList() + wxT(")");
39
39
}
40
40
 
41
41
wxString edbPackageProcedure::GetFullName()
42
 
43
 
    if (GetArgSigList().IsEmpty())
44
 
        return GetName();
45
 
    else
46
 
        return GetName() + wxT("(") + GetArgSigList() + wxT(")");
 
42
{
 
43
        if (GetArgSigList().IsEmpty())
 
44
                return GetName();
 
45
        else
 
46
                return GetName() + wxT("(") + GetArgSigList() + wxT(")");
47
47
}
48
48
 
49
49
wxString edbPackageFunction::GetArgListWithNames()
50
50
{
51
 
    wxString args;
52
 
 
53
 
    for (unsigned int i=0; i < argTypesArray.Count(); i++)
54
 
    {
55
 
        if (i > 0)
56
 
            args += wxT(", ");
57
 
 
58
 
        wxString arg;
59
 
 
60
 
        if (GetIsProcedure())
61
 
        {
62
 
            if (!argNamesArray.Item(i).IsEmpty())
63
 
                arg += qtIdent(argNamesArray.Item(i));
64
 
 
65
 
            if (!argModesArray.Item(i).IsEmpty())
66
 
            {
67
 
                if (arg.IsEmpty())
68
 
                    arg += argModesArray.Item(i);
69
 
                else
70
 
                    arg += wxT(" ") + argModesArray.Item(i);
71
 
            }
72
 
        }
73
 
        else
74
 
        {
75
 
            if (!argModesArray.Item(i).IsEmpty())
76
 
                arg += argModesArray.Item(i);
77
 
 
78
 
            if (!argNamesArray.Item(i).IsEmpty())
79
 
            {
80
 
                if (arg.IsEmpty())
81
 
                    arg += qtIdent(argNamesArray.Item(i));
82
 
                else
83
 
                    arg += wxT(" ") + qtIdent(argNamesArray.Item(i));
84
 
            }
85
 
        }
86
 
 
87
 
        if (!arg.IsEmpty())
88
 
            arg += wxT(" ") + argTypesArray.Item(i);
89
 
        else
90
 
            arg += argTypesArray.Item(i);
91
 
 
92
 
        // Parameter default value
93
 
        if (GetConnection()->HasFeature(FEATURE_FUNCTION_DEFAULTS) || GetConnection()->BackendMinimumVersion(8, 4))
94
 
        {
95
 
            if (!argModesArray.Item(i).IsSameAs(wxT("OUT"), false) && !argDefsArray.Item(i).IsEmpty())
96
 
                arg += wxT(" DEFAULT ") + argDefsArray.Item(i);
97
 
        }
98
 
 
99
 
        args += arg;
100
 
    }
101
 
    return args;
 
51
        wxString args;
 
52
 
 
53
        for (unsigned int i = 0; i < argTypesArray.Count(); i++)
 
54
        {
 
55
                if (i > 0)
 
56
                        args += wxT(", ");
 
57
 
 
58
                wxString arg;
 
59
 
 
60
                if (GetIsProcedure())
 
61
                {
 
62
                        if (!argNamesArray.Item(i).IsEmpty())
 
63
                                arg += qtIdent(argNamesArray.Item(i));
 
64
 
 
65
                        if (!argModesArray.Item(i).IsEmpty())
 
66
                        {
 
67
                                if (arg.IsEmpty())
 
68
                                        arg += argModesArray.Item(i);
 
69
                                else
 
70
                                        arg += wxT(" ") + argModesArray.Item(i);
 
71
                        }
 
72
                }
 
73
                else
 
74
                {
 
75
                        if (!argModesArray.Item(i).IsEmpty())
 
76
                                arg += argModesArray.Item(i);
 
77
 
 
78
                        if (!argNamesArray.Item(i).IsEmpty())
 
79
                        {
 
80
                                if (arg.IsEmpty())
 
81
                                        arg += qtIdent(argNamesArray.Item(i));
 
82
                                else
 
83
                                        arg += wxT(" ") + qtIdent(argNamesArray.Item(i));
 
84
                        }
 
85
                }
 
86
 
 
87
                if (!arg.IsEmpty())
 
88
                        arg += wxT(" ") + argTypesArray.Item(i);
 
89
                else
 
90
                        arg += argTypesArray.Item(i);
 
91
 
 
92
                // Parameter default value
 
93
                if (GetConnection()->HasFeature(FEATURE_FUNCTION_DEFAULTS) || GetConnection()->BackendMinimumVersion(8, 4))
 
94
                {
 
95
                        if (!argModesArray.Item(i).IsSameAs(wxT("OUT"), false) && !argDefsArray.Item(i).IsEmpty())
 
96
                                arg += wxT(" DEFAULT ") + argDefsArray.Item(i);
 
97
                }
 
98
 
 
99
                args += arg;
 
100
        }
 
101
        return args;
102
102
}
103
103
 
104
104
wxString edbPackageFunction::GetArgSigList()
105
105
{
106
 
    wxString args;
107
 
 
108
 
    for (unsigned int i=0; i < argTypesArray.Count(); i++)
109
 
    {
110
 
        // OUT parameters are not considered part of the signature
111
 
        if (argModesArray.Item(i) != wxT("OUT"))
112
 
        {
113
 
            if (i > 0)
114
 
                args += wxT(", ");
115
 
 
116
 
            args += argTypesArray.Item(i);
117
 
        }
118
 
    }
119
 
    return args;
 
106
        wxString args;
 
107
 
 
108
        for (unsigned int i = 0; i < argTypesArray.Count(); i++)
 
109
        {
 
110
                // OUT parameters are not considered part of the signature
 
111
                if (argModesArray.Item(i) != wxT("OUT"))
 
112
                {
 
113
                        if (i > 0)
 
114
                                args += wxT(", ");
 
115
 
 
116
                        args += argTypesArray.Item(i);
 
117
                }
 
118
        }
 
119
        return args;
120
120
}
121
121
 
122
122
wxString edbPackageFunction::GetSql(ctlTree *browser)
123
123
{
124
 
    if (sql.IsNull())
125
 
    {
126
 
        sql = wxT("-- Package Function: ") + GetName() + wxT("\n\n");
127
 
        sql += GetSource() + wxT("\n\n");
128
 
    }
 
124
        if (sql.IsNull())
 
125
        {
 
126
                sql = wxT("-- Package Function: ") + GetName() + wxT("\n\n");
 
127
                sql += GetSource() + wxT("\n\n");
 
128
        }
129
129
 
130
 
    return sql;
 
130
        return sql;
131
131
}
132
132
 
133
133
wxString edbPackageProcedure::GetSql(ctlTree *browser)
134
134
{
135
 
    if (sql.IsNull())
136
 
    {
137
 
        sql = wxT("-- Package Procedure: ") + GetName() + wxT("\n\n");
138
 
        sql += GetSource() + wxT("\n\n");
139
 
    }
 
135
        if (sql.IsNull())
 
136
        {
 
137
                sql = wxT("-- Package Procedure: ") + GetName() + wxT("\n\n");
 
138
                sql += GetSource() + wxT("\n\n");
 
139
        }
140
140
 
141
 
    return sql;
 
141
        return sql;
142
142
}
143
143
 
144
144
void edbPackageFunction::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
145
145
{
146
 
    if (properties)
147
 
    {
148
 
        CreateListColumns(properties);
 
146
        if (properties)
 
147
        {
 
148
                CreateListColumns(properties);
149
149
 
150
 
        properties->AppendItem(_("Name"), GetName());
151
 
        properties->AppendItem(_("OID"), GetOid());
152
 
        properties->AppendItem(_("Argument count"), GetArgCount());
153
 
        properties->AppendItem(_("Arguments"), GetArgListWithNames());
154
 
        properties->AppendItem(_("Signature arguments"), GetArgSigList());
155
 
        if (!GetIsProcedure())
156
 
            properties->AppendItem(_("Return type"), GetReturnType());
157
 
        properties->AppendItem(_("Visibility"), GetVisibility());
158
 
        properties->AppendItem(_("Source"), firstLineOnly(GetSource()));
159
 
    }
 
150
                properties->AppendItem(_("Name"), GetName());
 
151
                properties->AppendItem(_("OID"), GetOid());
 
152
                properties->AppendItem(_("Argument count"), GetArgCount());
 
153
                properties->AppendItem(_("Arguments"), GetArgListWithNames());
 
154
                properties->AppendItem(_("Signature arguments"), GetArgSigList());
 
155
                if (!GetIsProcedure())
 
156
                        properties->AppendItem(_("Return type"), GetReturnType());
 
157
                properties->AppendItem(_("Visibility"), GetVisibility());
 
158
                properties->AppendItem(_("Source"), firstLineOnly(GetSource()));
 
159
        }
160
160
}
161
161
 
162
162
 
163
163
 
164
164
pgObject *edbPackageFunction::Refresh(ctlTree *browser, const wxTreeItemId item)
165
165
{
166
 
    pgObject *packageFunction=0;
167
 
    pgCollection *coll=browser->GetParentCollection(item);
168
 
    if (coll)
169
 
    {
170
 
        if (coll->GetConnection()->EdbMinimumVersion(8, 2))
171
 
            packageFunction = packageFunctionFactory.CreateObjects(coll, 0, wxT("\n   AND pronamespace=") + GetPackage()->GetOidStr() + wxT(" AND proname='") + GetName() + wxT("'"));
172
 
        else
173
 
            packageFunction = packageFunctionFactory.CreateObjects(coll, 0, wxT("\n   AND packageoid=") + GetPackage()->GetOidStr() + wxT(" AND eltname='") + GetName() + wxT("'"));
174
 
    }
 
166
        pgObject *packageFunction = 0;
 
167
        pgCollection *coll = browser->GetParentCollection(item);
 
168
        if (coll)
 
169
        {
 
170
                if (coll->GetConnection()->EdbMinimumVersion(8, 2))
 
171
                        packageFunction = packageFunctionFactory.CreateObjects(coll, 0, wxT("\n   AND pronamespace=") + GetPackage()->GetOidStr() + wxT(" AND proname='") + GetName() + wxT("'"));
 
172
                else
 
173
                        packageFunction = packageFunctionFactory.CreateObjects(coll, 0, wxT("\n   AND packageoid=") + GetPackage()->GetOidStr() + wxT(" AND eltname='") + GetName() + wxT("'"));
 
174
        }
175
175
 
176
 
    return packageFunction;
 
176
        return packageFunction;
177
177
}
178
178
 
179
179
 
181
181
 
182
182
edbPackageFunction *edbPackageFunctionFactory::AppendFunctions(pgObject *obj, edbPackage *package, ctlTree *browser, const wxString &restriction)
183
183
{
184
 
    edbPackageFunction *packageFunction=0;
 
184
        edbPackageFunction *packageFunction = 0;
185
185
        pgSet *packageFunctions;
186
186
 
187
 
    // Caches
188
 
    cacheMap typeCache, exprCache;
189
 
    wxString sql, argDefsCol;
190
 
 
191
 
    if (obj->GetConnection()->HasFeature(FEATURE_FUNCTION_DEFAULTS))
192
 
        argDefsCol = wxT("proargdefvals, ");
193
 
 
194
 
    if (obj->GetConnection()->EdbMinimumVersion(8, 2))
195
 
    {
 
187
        // Caches
 
188
        cacheMap typeCache, exprCache;
 
189
        wxString sql, argDefsCol;
 
190
 
 
191
        if (obj->GetConnection()->HasFeature(FEATURE_FUNCTION_DEFAULTS))
 
192
                argDefsCol = wxT("proargdefvals, ");
 
193
 
 
194
        if (obj->GetConnection()->EdbMinimumVersion(8, 2))
 
195
        {
196
196
                sql = wxT("SELECT pg_proc.oid, proname AS eltname, prorettype AS eltdatatype, pronargs AS nargs, proaccess AS visibility,\n")
197
 
            wxT("       proallargtypes AS allargtypes, proargtypes AS argtypes, proargnames AS argnames, proargmodes AS argmodes,") + argDefsCol + wxT("\n")
198
 
              wxT("       CASE WHEN format_type(prorettype, NULL) = 'void' THEN 'P' ELSE 'F' END AS eltclass\n")
199
 
              wxT("  FROM pg_proc, pg_namespace\n")
200
 
              + restriction + wxT("\n")
201
 
              wxT("  AND pg_proc.pronamespace = pg_namespace.oid\n")
202
 
                      wxT("  ORDER BY eltname");
203
 
    }
204
 
    else
205
 
    {
 
197
                      wxT("       proallargtypes AS allargtypes, proargtypes AS argtypes, proargnames AS argnames, proargmodes AS argmodes,") + argDefsCol + wxT("\n")
 
198
                      wxT("       CASE WHEN format_type(prorettype, NULL) = 'void' THEN 'P' ELSE 'F' END AS eltclass\n")
 
199
                      wxT("  FROM pg_proc, pg_namespace\n")
 
200
                      + restriction + wxT("\n")
 
201
                      wxT("  AND pg_proc.pronamespace = pg_namespace.oid\n")
 
202
                      wxT("  ORDER BY eltname");
 
203
        }
 
204
        else
 
205
        {
206
206
                sql = wxT("SELECT oid, eltname, eltdatatype, eltclass, nargs, visibility,\n")
207
 
              wxT("       allargtypes, argtypes, argnames, argmodes\n")
208
 
              wxT("  FROM edb_pkgelements\n")
 
207
                      wxT("       allargtypes, argtypes, argnames, argmodes\n")
 
208
                      wxT("  FROM edb_pkgelements\n")
209
209
                      + restriction + wxT("\n")
210
210
                      wxT("  ORDER BY eltname");
211
 
    }
212
 
 
213
 
    packageFunctions = obj->GetDatabase()->ExecuteSet(sql);
214
 
 
215
 
    pgSet *types = obj->GetDatabase()->ExecuteSet(wxT(
216
 
                    "SELECT oid, format_type(oid, NULL) AS typname FROM pg_type"));
217
 
 
218
 
    while(!types->Eof())
219
 
    {
220
 
        typeCache[types->GetVal(wxT("oid"))] = types->GetVal(wxT("typname"));
221
 
        types->MoveNext();
222
 
    }
223
 
 
224
 
    if (packageFunctions)
225
 
    {
226
 
        while (!packageFunctions->Eof())
227
 
        {
228
 
            if (packageFunctions->GetVal(wxT("eltclass")) == wxT("F"))
229
 
                packageFunction = new edbPackageFunction(package, packageFunctions->GetVal(wxT("eltname")));
230
 
            else
231
 
                packageFunction = new edbPackageProcedure(package, packageFunctions->GetVal(wxT("eltname")));
232
 
 
233
 
            // Tokenize the arguments
234
 
            wxStringTokenizer argTypesTkz(wxEmptyString), argModesTkz(wxEmptyString);
235
 
            queryTokenizer argNamesTkz(wxEmptyString, (wxChar)','),  argDefsTkz(wxEmptyString, (wxChar)',');
236
 
            wxString tmp;
237
 
 
238
 
            // Types
239
 
            tmp = packageFunctions->GetVal(wxT("allargtypes"));
240
 
            if (!tmp.IsEmpty())
241
 
                argTypesTkz.SetString(tmp.Mid(1, tmp.Length()-2), wxT(","));
242
 
            else
243
 
            {
244
 
                tmp = packageFunctions->GetVal(wxT("argtypes"));
245
 
                if (!tmp.IsEmpty())
246
 
                    argTypesTkz.SetString(tmp);
247
 
            }
248
 
 
249
 
            // Names
250
 
            tmp = packageFunctions->GetVal(wxT("argnames"));
251
 
            if (!tmp.IsEmpty())
252
 
                argNamesTkz.SetString(tmp.Mid(1, tmp.Length()-2), wxT(","));
253
 
 
254
 
            // Modes
255
 
            tmp = packageFunctions->GetVal(wxT("argmodes"));
256
 
            if (!tmp.IsEmpty())
257
 
                argModesTkz.SetString(tmp.Mid(1, tmp.Length()-2), wxT(","));
258
 
 
259
 
            // Function defaults
260
 
            if (obj->GetConnection()->HasFeature(FEATURE_FUNCTION_DEFAULTS))
261
 
            {
262
 
                tmp = packageFunctions->GetVal(wxT("proargdefvals"));
263
 
                if (!tmp.IsEmpty())
264
 
                    argDefsTkz.SetString(tmp.Mid(1, tmp.Length()-2), wxT(","));
265
 
            }
266
 
 
267
 
            // Now iterate the arguments and build the arrays
268
 
            wxString type, name, mode, def;
269
 
            
270
 
            while (argTypesTkz.HasMoreTokens())
271
 
            {
272
 
                // Add the arg type. This is a type oid, so 
273
 
                // look it up in the hashmap
274
 
                type = argTypesTkz.GetNextToken();
275
 
                packageFunction->iAddArgType(typeCache[type]);
276
 
 
277
 
                // Now add the name, stripping the quotes if
278
 
                // necessary. 
279
 
                name = argNamesTkz.GetNextToken();
280
 
                if (!name.IsEmpty())
281
 
                {
282
 
                    if (name[0] == '"')
283
 
                        name = name.Mid(1, name.Length()-2);
284
 
                    packageFunction->iAddArgName(name);
285
 
                }
286
 
                else
287
 
                    packageFunction->iAddArgName(wxEmptyString);
288
 
 
289
 
                // Now the mode
290
 
                mode = argModesTkz.GetNextToken();
291
 
                if (!mode.IsEmpty())
292
 
                {
293
 
                    if (mode == wxT('o') || mode == wxT("2"))
294
 
                        mode = wxT("OUT");
295
 
                    else if (mode == wxT("b"))
296
 
                        if (packageFunctions->GetVal(wxT("eltclass")) == wxT("F"))
297
 
                            mode = wxT("IN OUT");
298
 
                        else
299
 
                            mode = wxT("INOUT");
300
 
                    else if (mode == wxT("3"))
301
 
                        mode = wxT("IN OUT");
302
 
                    else
303
 
                        mode = wxT("IN");
304
 
 
305
 
                    packageFunction->iAddArgMode(mode);
306
 
                }
307
 
                else
308
 
                    packageFunction->iAddArgMode(wxEmptyString);
309
 
 
310
 
                // Finally the defaults, as we got them. 
311
 
                def = argDefsTkz.GetNextToken();
312
 
                if (!def.IsEmpty() && !def.IsSameAs(wxT("-")))
313
 
                {
314
 
                    if (def[0] == '"')
315
 
                        def = def.Mid(1, def.Length()-2);
316
 
 
317
 
                    // Check the cache first - if we don't have a value, get it and cache for next time
318
 
                    wxString val = exprCache[def];
319
 
                    if (val == wxEmptyString)
320
 
                    {
321
 
                        val = obj->GetDatabase()->ExecuteScalar(wxT("SELECT pg_get_expr('") + def + wxT("', 'pg_catalog.pg_class'::regclass)"));
322
 
                        exprCache[def] = val;
323
 
                    }
324
 
                    packageFunction->iAddArgDef(val);
325
 
                }
326
 
                else
327
 
                    packageFunction->iAddArgDef(wxEmptyString);
328
 
            }
329
 
 
330
 
            packageFunction->iSetOid(packageFunctions->GetOid(wxT("oid")));
331
 
            packageFunction->iSetArgCount(packageFunctions->GetOid(wxT("nargs")));
332
 
            packageFunction->iSetReturnType(typeCache[packageFunctions->GetVal(wxT("eltdatatype"))]);
333
 
 
334
 
            if (packageFunctions->GetVal(wxT("visibility")) == wxT("+"))
335
 
                packageFunction->iSetVisibility(_("Public"));
336
 
            else if (packageFunctions->GetVal(wxT("visibility")) == wxT("-"))
337
 
                packageFunction->iSetVisibility(_("Private"));
338
 
            else
339
 
                packageFunction->iSetVisibility(_("Unknown"));
340
 
 
341
 
            packageFunction->iSetSource(package->GetBodyInner());
342
 
 
343
 
            if (browser)
344
 
            {
345
 
                browser->AppendObject(obj, packageFunction);
 
211
        }
 
212
 
 
213
        packageFunctions = obj->GetDatabase()->ExecuteSet(sql);
 
214
 
 
215
        pgSet *types = obj->GetDatabase()->ExecuteSet(wxT(
 
216
                           "SELECT oid, format_type(oid, NULL) AS typname FROM pg_type"));
 
217
 
 
218
        while(!types->Eof())
 
219
        {
 
220
                typeCache[types->GetVal(wxT("oid"))] = types->GetVal(wxT("typname"));
 
221
                types->MoveNext();
 
222
        }
 
223
 
 
224
        if (packageFunctions)
 
225
        {
 
226
                while (!packageFunctions->Eof())
 
227
                {
 
228
                        if (packageFunctions->GetVal(wxT("eltclass")) == wxT("F"))
 
229
                                packageFunction = new edbPackageFunction(package, packageFunctions->GetVal(wxT("eltname")));
 
230
                        else
 
231
                                packageFunction = new edbPackageProcedure(package, packageFunctions->GetVal(wxT("eltname")));
 
232
 
 
233
                        // Tokenize the arguments
 
234
                        wxStringTokenizer argTypesTkz(wxEmptyString), argModesTkz(wxEmptyString);
 
235
                        queryTokenizer argNamesTkz(wxEmptyString, (wxChar)','),  argDefsTkz(wxEmptyString, (wxChar)',');
 
236
                        wxString tmp;
 
237
 
 
238
                        // Types
 
239
                        tmp = packageFunctions->GetVal(wxT("allargtypes"));
 
240
                        if (!tmp.IsEmpty())
 
241
                                argTypesTkz.SetString(tmp.Mid(1, tmp.Length() - 2), wxT(","));
 
242
                        else
 
243
                        {
 
244
                                tmp = packageFunctions->GetVal(wxT("argtypes"));
 
245
                                if (!tmp.IsEmpty())
 
246
                                        argTypesTkz.SetString(tmp);
 
247
                        }
 
248
 
 
249
                        // Names
 
250
                        tmp = packageFunctions->GetVal(wxT("argnames"));
 
251
                        if (!tmp.IsEmpty())
 
252
                                argNamesTkz.SetString(tmp.Mid(1, tmp.Length() - 2), wxT(","));
 
253
 
 
254
                        // Modes
 
255
                        tmp = packageFunctions->GetVal(wxT("argmodes"));
 
256
                        if (!tmp.IsEmpty())
 
257
                                argModesTkz.SetString(tmp.Mid(1, tmp.Length() - 2), wxT(","));
 
258
 
 
259
                        // Function defaults
 
260
                        if (obj->GetConnection()->HasFeature(FEATURE_FUNCTION_DEFAULTS))
 
261
                        {
 
262
                                tmp = packageFunctions->GetVal(wxT("proargdefvals"));
 
263
                                if (!tmp.IsEmpty())
 
264
                                        argDefsTkz.SetString(tmp.Mid(1, tmp.Length() - 2), wxT(","));
 
265
                        }
 
266
 
 
267
                        // Now iterate the arguments and build the arrays
 
268
                        wxString type, name, mode, def;
 
269
 
 
270
                        while (argTypesTkz.HasMoreTokens())
 
271
                        {
 
272
                                // Add the arg type. This is a type oid, so
 
273
                                // look it up in the hashmap
 
274
                                type = argTypesTkz.GetNextToken();
 
275
                                packageFunction->iAddArgType(typeCache[type]);
 
276
 
 
277
                                // Now add the name, stripping the quotes if
 
278
                                // necessary.
 
279
                                name = argNamesTkz.GetNextToken();
 
280
                                if (!name.IsEmpty())
 
281
                                {
 
282
                                        if (name[0] == '"')
 
283
                                                name = name.Mid(1, name.Length() - 2);
 
284
                                        packageFunction->iAddArgName(name);
 
285
                                }
 
286
                                else
 
287
                                        packageFunction->iAddArgName(wxEmptyString);
 
288
 
 
289
                                // Now the mode
 
290
                                mode = argModesTkz.GetNextToken();
 
291
                                if (!mode.IsEmpty())
 
292
                                {
 
293
                                        if (mode == wxT('o') || mode == wxT("2"))
 
294
                                                mode = wxT("OUT");
 
295
                                        else if (mode == wxT("b"))
 
296
                                                if (packageFunctions->GetVal(wxT("eltclass")) == wxT("F"))
 
297
                                                        mode = wxT("IN OUT");
 
298
                                                else
 
299
                                                        mode = wxT("INOUT");
 
300
                                        else if (mode == wxT("3"))
 
301
                                                mode = wxT("IN OUT");
 
302
                                        else
 
303
                                                mode = wxT("IN");
 
304
 
 
305
                                        packageFunction->iAddArgMode(mode);
 
306
                                }
 
307
                                else
 
308
                                        packageFunction->iAddArgMode(wxEmptyString);
 
309
 
 
310
                                // Finally the defaults, as we got them.
 
311
                                def = argDefsTkz.GetNextToken();
 
312
                                if (!def.IsEmpty() && !def.IsSameAs(wxT("-")))
 
313
                                {
 
314
                                        if (def[0] == '"')
 
315
                                                def = def.Mid(1, def.Length() - 2);
 
316
 
 
317
                                        // Check the cache first - if we don't have a value, get it and cache for next time
 
318
                                        wxString val = exprCache[def];
 
319
                                        if (val == wxEmptyString)
 
320
                                        {
 
321
                                                val = obj->GetDatabase()->ExecuteScalar(wxT("SELECT pg_get_expr('") + def + wxT("', 'pg_catalog.pg_class'::regclass)"));
 
322
                                                exprCache[def] = val;
 
323
                                        }
 
324
                                        packageFunction->iAddArgDef(val);
 
325
                                }
 
326
                                else
 
327
                                        packageFunction->iAddArgDef(wxEmptyString);
 
328
                        }
 
329
 
 
330
                        packageFunction->iSetOid(packageFunctions->GetOid(wxT("oid")));
 
331
                        packageFunction->iSetArgCount(packageFunctions->GetOid(wxT("nargs")));
 
332
                        packageFunction->iSetReturnType(typeCache[packageFunctions->GetVal(wxT("eltdatatype"))]);
 
333
 
 
334
                        if (packageFunctions->GetVal(wxT("visibility")) == wxT("+"))
 
335
                                packageFunction->iSetVisibility(_("Public"));
 
336
                        else if (packageFunctions->GetVal(wxT("visibility")) == wxT("-"))
 
337
                                packageFunction->iSetVisibility(_("Private"));
 
338
                        else
 
339
                                packageFunction->iSetVisibility(_("Unknown"));
 
340
 
 
341
                        packageFunction->iSetSource(package->GetBodyInner());
 
342
 
 
343
                        if (browser)
 
344
                        {
 
345
                                browser->AppendObject(obj, packageFunction);
346
346
                                packageFunctions->MoveNext();
347
 
            }
348
 
            else
349
 
                break;
350
 
        }
 
347
                        }
 
348
                        else
 
349
                                break;
 
350
                }
351
351
 
352
352
                delete packageFunctions;
353
 
        delete types;
354
 
    }
355
 
    return packageFunction;
 
353
                delete types;
 
354
        }
 
355
        return packageFunction;
356
356
}
357
357
 
358
358
pgObject *edbPackageFunctionFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
359
359
{
360
 
    wxString restr;
361
 
    
362
 
    if (collection->GetDatabase()->GetConnection()->EdbMinimumVersion(8, 2))
363
 
        restr = wxT(" WHERE format_type(prorettype, NULL) != 'void' AND pronamespace = ");
364
 
    else
365
 
        restr = wxT(" WHERE eltclass = 'F' AND packageoid = ");
366
 
 
367
 
    restr += ((edbPackageObjCollection *)collection)->GetPackage()->GetOidStr();
368
 
 
369
 
    return AppendFunctions(collection, ((edbPackageObjCollection *)collection)->GetPackage(), browser, restr);
 
360
        wxString restr;
 
361
 
 
362
        if (collection->GetDatabase()->GetConnection()->EdbMinimumVersion(8, 2))
 
363
                restr = wxT(" WHERE format_type(prorettype, NULL) != 'void' AND pronamespace = ");
 
364
        else
 
365
                restr = wxT(" WHERE eltclass = 'F' AND packageoid = ");
 
366
 
 
367
        restr += ((edbPackageObjCollection *)collection)->GetPackage()->GetOidStr();
 
368
 
 
369
        return AppendFunctions(collection, ((edbPackageObjCollection *)collection)->GetPackage(), browser, restr);
370
370
}
371
371
 
372
372
pgObject *edbPackageProcedureFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
373
373
{
374
 
    wxString restr;
375
 
    
376
 
    if (collection->GetDatabase()->GetConnection()->EdbMinimumVersion(8, 2))
377
 
        restr = wxT(" WHERE format_type(prorettype, NULL) = 'void' AND pronamespace = ");
378
 
    else
379
 
        restr = wxT(" WHERE eltclass = 'P' AND packageoid = ");
380
 
 
381
 
    restr += ((edbPackageObjCollection *)collection)->GetPackage()->GetOidStr();
382
 
 
383
 
    return AppendFunctions(collection, ((edbPackageObjCollection *)collection)->GetPackage(), browser, restr);
 
374
        wxString restr;
 
375
 
 
376
        if (collection->GetDatabase()->GetConnection()->EdbMinimumVersion(8, 2))
 
377
                restr = wxT(" WHERE format_type(prorettype, NULL) = 'void' AND pronamespace = ");
 
378
        else
 
379
                restr = wxT(" WHERE eltclass = 'P' AND packageoid = ");
 
380
 
 
381
        restr += ((edbPackageObjCollection *)collection)->GetPackage()->GetOidStr();
 
382
 
 
383
        return AppendFunctions(collection, ((edbPackageObjCollection *)collection)->GetPackage(), browser, restr);
384
384
}
385
385
 
386
 
#include "images/function.xpm"
387
 
#include "images/functions.xpm"
 
386
#include "images/function.pngc"
 
387
#include "images/functions.pngc"
388
388
 
389
 
edbPackageFunctionFactory::edbPackageFunctionFactory(const wxChar *tn, const wxChar *ns, const wxChar *nls, const char **img) 
390
 
: edbPackageObjFactory(tn, ns, nls, img)
 
389
edbPackageFunctionFactory::edbPackageFunctionFactory(const wxChar *tn, const wxChar *ns, const wxChar *nls, wxImage *img)
 
390
        : edbPackageObjFactory(tn, ns, nls, img)
391
391
{
392
 
    metaType = EDB_PACKAGEFUNCTION;
 
392
        metaType = EDB_PACKAGEFUNCTION;
393
393
}
394
394
 
395
 
edbPackageFunctionFactory packageFunctionFactory(__("Function"), __("New Function..."), __("Create a new Function."), function_xpm);
396
 
static pgaCollectionFactory cff(&packageFunctionFactory, __("Functions"), functions_xpm);
 
395
edbPackageFunctionFactory packageFunctionFactory(__("Function"), __("New Function..."), __("Create a new Function."), function_png_img);
 
396
static pgaCollectionFactory cff(&packageFunctionFactory, __("Functions"), functions_png_img);
397
397
 
398
398
pgCollection *edbPackageObjFactory::CreateCollection(pgObject *obj)
399
399
{
400
 
    return new edbPackageObjCollection(GetCollectionFactory(), (edbPackage*)obj);
 
400
        return new edbPackageObjCollection(GetCollectionFactory(), (edbPackage *)obj);
401
401
}
402
402
 
403
 
#include "images/procedure.xpm"
404
 
#include "images/procedures.xpm"
 
403
#include "images/procedure.pngc"
 
404
#include "images/procedures.pngc"
405
405
 
406
 
edbPackageProcedureFactory::edbPackageProcedureFactory() 
407
 
: edbPackageFunctionFactory(__("Procedure"), __("New Procedure..."), __("Create a new Procedure."), procedure_xpm)
 
406
edbPackageProcedureFactory::edbPackageProcedureFactory()
 
407
        : edbPackageFunctionFactory(__("Procedure"), __("New Procedure..."), __("Create a new Procedure."), procedure_png_img)
408
408
{
409
409
}
410
410
 
411
411
edbPackageProcedureFactory packageProcedureFactory;
412
 
static pgaCollectionFactory cfp(&packageProcedureFactory, __("Procedures"), procedures_xpm);
 
412
static pgaCollectionFactory cfp(&packageProcedureFactory, __("Procedures"), procedures_png_img);
413
413
 
414
414