[Python-modules-commits] [python-pgspecial] 01/05: Imported Upstream version 1.3.0
ChangZhuo Chen
czchen at moszumanska.debian.org
Mon Mar 28 15:59:17 UTC 2016
This is an automated email from the git hooks/post-receive script.
czchen pushed a commit to branch master
in repository python-pgspecial.
commit e720edcab4d31af777a9e727379b58f77a612385
Author: ChangZhuo Chen (陳昌倬) <czchen at debian.org>
Date: Mon Mar 28 23:47:53 2016 +0800
Imported Upstream version 1.3.0
---
.gitignore | 108 ---------
.travis.yml | 23 --
DEVELOP.rst | 121 ----------
License.txt | 27 ---
PKG-INFO | 100 ++++++++
changelog.rst | 28 ---
pgspecial.egg-info/PKG-INFO | 100 ++++++++
pgspecial.egg-info/SOURCES.txt | 15 ++
pgspecial.egg-info/dependency_links.txt | 1 +
pgspecial.egg-info/pbr.json | 1 +
pgspecial.egg-info/requires.txt | 1 +
pgspecial.egg-info/top_level.txt | 1 +
pgspecial/__init__.py | 2 +-
pgspecial/dbcommands.py | 395 ++++++++++++++++++++++++--------
pgspecial/main.py | 37 ++-
release.py | 113 ---------
requirements-dev.txt | 4 -
scripts/README.rst | 21 --
scripts/docparser.py | 52 -----
setup.cfg | 5 +
tests/conftest.py | 36 ---
tests/dbutils.py | 71 ------
tests/pytest.ini | 2 -
tests/test_specials.py | 90 --------
tox.ini | 7 -
25 files changed, 563 insertions(+), 798 deletions(-)
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index bbf58a0..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,108 +0,0 @@
-### Python template
-# Byte-compiled / optimized / DLL files
-__pycache__/
-*.py[cod]
-*$py.class
-
-# C extensions
-*.so
-
-# Distribution / packaging
-.Python
-env/
-build/
-develop-eggs/
-dist/
-downloads/
-eggs/
-.eggs/
-lib/
-lib64/
-parts/
-sdist/
-var/
-*.egg-info/
-.installed.cfg
-*.egg
-
-# PyInstaller
-# Usually these files are written by a python script from a template
-# before PyInstaller builds the exe, so as to inject date/other infos into it.
-*.manifest
-*.spec
-
-# Installer logs
-pip-log.txt
-pip-delete-this-directory.txt
-
-# Unit test / coverage reports
-htmlcov/
-.tox/
-.coverage
-.coverage.*
-.cache
-nosetests.xml
-coverage.xml
-*,cover
-
-# Translations
-*.mo
-*.pot
-
-# Django stuff:
-*.log
-
-# Sphinx documentation
-docs/_build/
-
-# PyBuilder
-target/
-### JetBrains template
-# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
-
-*.iml
-
-## Directory-based project format:
-.idea/
-# if you remove the above rule, at least ignore the following:
-
-# User-specific stuff:
-# .idea/workspace.xml
-# .idea/tasks.xml
-# .idea/dictionaries
-
-# Sensitive or high-churn files:
-# .idea/dataSources.ids
-# .idea/dataSources.xml
-# .idea/sqlDataSources.xml
-# .idea/dynamic.xml
-# .idea/uiDesigner.xml
-
-# Gradle:
-# .idea/gradle.xml
-# .idea/libraries
-
-# Mongo Explorer plugin:
-# .idea/mongoSettings.xml
-
-## File-based project format:
-*.ipr
-*.iws
-
-## Plugin-specific files:
-
-# IntelliJ
-/out/
-
-# mpeltonen/sbt-idea plugin
-.idea_modules/
-
-# JIRA plugin
-atlassian-ide-plugin.xml
-
-# Crashlytics plugin (for Android Studio and IntelliJ)
-com_crashlytics_export_strings.xml
-crashlytics.properties
-crashlytics-build.properties
-
-# Created by .ignore support plugin (hsz.mobi)
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 5494afc..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,23 +0,0 @@
-language: python
-python:
- - "2.6"
- - "2.7"
- - "3.3"
- - "3.4"
-
-install:
- - pip install . pytest mock codecov psycopg2
-
-script:
- - coverage run --source pgspecial -m py.test
-
-after_success:
- - codecov
-
-notifications:
- webhooks:
- urls:
- - YOUR_WEBHOOK_URL
- on_success: change # options: [always|never|change] default: always
- on_failure: always # options: [always|never|change] default: always
- on_start: false # default: false
diff --git a/DEVELOP.rst b/DEVELOP.rst
deleted file mode 100644
index 1342f84..0000000
--- a/DEVELOP.rst
+++ /dev/null
@@ -1,121 +0,0 @@
-Development Guide
------------------
-This is a guide for developers who would like to contribute to this project.
-
-GitHub Workflow
----------------
-
-If you're interested in contributing to pgcli, first of all my heart felt
-thanks. `Fork the project <https://github.com/dbcli/pgspecial>`_ in github.
-Then clone your fork into your computer (``git clone <url-for-your-fork>``).
-Make the changes and create the commits in your local machine. Then push those
-changes to your fork. Then click on the pull request icon on github and create
-a new pull request. Add a description about the change and send it along. I
-promise to review the pull request in a reasonable window of time and get back
-to you.
-
-In order to keep your fork up to date with any changes from mainline, add a new
-git remote to your local copy called 'upstream' and point it to the main
-``pgspecial`` repo.
-
-::
-
- $ git remote add upstream git at github.com:dbcli/pgspecial.git
-
-Once the 'upstream' end point is added you can then periodically do a ``git
-pull upstream master`` to update your local copy and then do a ``git push
-origin master`` to keep your own fork up to date.
-
-Local Setup
------------
-
-The installation instructions in the README file are intended for users of
-``pgspecial``. If you're developing ``pgspecial``, you'll need to install it in
-a slightly different way so you can see the effects of your changes right away
-without having to go through the install cycle every time you change the code.
-
-It is highly recommended to use virtualenv for development. If you don't know
-what a virtualenv is, this `guide
-<http://docs.python-guide.org/en/latest/dev/virtualenvs/#virtual-environments>`_
-will help you get started.
-
-Create a virtualenv (let's call it ``pgspecial-dev``). Activate it:
-
-::
-
- virtualenv ./pgspecial-dev
- source ./pgspecial-dev/bin/activate
-
-Once the virtualenv is activated, `cd` into the local clone of pgspecial folder
-and install pgspecial using pip as follows:
-
-::
-
- $ pip install --editable .
-
- or
-
- $ pip install -e .
-
-This will install the necessary dependencies as well as install pgspecial from
-the working folder into the virtualenv. By installing it using `pip install -e`
-we've linked the pgspecial installation with the working copy. So any changes
-made to the code is immediately available in the installed version of
-pgspecial.
-
-Adding PostgreSQL Special (Meta) Commands
------------------------------------------
-
-If you want to add a new meta-command, you'll write a function that accepts 3
-parameters. Then you'll mark it with a ``@special_command`` decorator. For
-an example, look at ``list_roles`` in ``dbcommands.py``:
-
- ::
-
- @special_command('\\du', '\\du[+] [pattern]', 'List roles.')
- def list_roles(cur, pattern, verbose):
- # some code here
- return [(None, cur, headers, cur.statusmessage)]
-
-Things to note:
-
-* Your function should return 4 items: ``title, cur, headers, status``.
-* ``title`` is optional. It is something you can print out as first line of your
- output.
-* ``cur`` is cursor that contains records to iterate.
-* ``headers`` is result table's list of column headers.
-* ``status`` is optional. If provided, it will be printed out last.
-
-Now, take a closer look at the decorator. The first item in a tuple of
-arguments is the command's name. It should be unique. The second item is this
-command's syntax. The third item in the tuple is a string which is
-the documentation for that special command.
-
-The example command here, ``\du``, is a meta-command that lists all roles in
-the databases. The way you can see the SQL statement issued by PostgreSQL when
-this command is executed is to launch `psql -E` and entering ``\du``.
-
-That will print the results and also print the sql statement that was executed
-to produce that result. In most cases it's a single sql statement, but
-sometimes it's a series of sql statements that feed the results to each other
-to get to the final result.
-
-Running the tests
------------------
-
-The tests are using default user ``postgres`` at ``localhost``, without
-the password (authentication mode ``trust``). This can be changed in
-``tests/db_utils.py``.
-
-First, install the requirements for testing:
-
-::
-
- $ pip install -r requirements-dev.txt
-
-After that, tests can be run with:
-
-::
-
- $ cd tests
- $ py.test
diff --git a/License.txt b/License.txt
deleted file mode 100644
index 087af3a..0000000
--- a/License.txt
+++ /dev/null
@@ -1,27 +0,0 @@
-Copyright (c) 2015, dbcli
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
-* Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
-* Neither the name of pgspecial nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..e5c5a4a
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,100 @@
+Metadata-Version: 1.1
+Name: pgspecial
+Version: 1.3.0
+Summary: Meta-commands handler for Postgres Database.
+Home-page: http://pgcli.com
+Author: Amjith Ramanujam
+Author-email: amjith[dot]r[at]gmail.com
+License: LICENSE.txt
+Description: Meta-commands for Postgres
+ --------------------------
+
+ |BuildStatus| |PyPI|
+
+ This package provides an API to execute meta-commands (AKA "special", or
+ "backslash commands") on PostgreSQL.
+
+ Quick Start
+ -----------
+
+ This is a python package. It can be installed with:
+
+ ::
+
+ $ pip install pgspecial
+
+
+ Usage
+ -----
+
+ Once this library is included into your project, you will most likely use the
+ following imports:
+
+ ::
+
+ from pgspecial.main import PGSpecial
+ from pgspecial.namedqueries import NamedQueries
+
+ Then you will create and use an instance of PGSpecial:
+
+ ::
+
+ pgspecial = PGSpecial()
+ for result in pgspecial.execute(cur, sql):
+ # Do something
+
+ If you want to import named queries from an existing config file, it is
+ convenient to initialize and keep around the class variable in
+ ``NamedQueries``:
+
+ ::
+
+ from configobj import ConfigObj
+
+ NamedQueries.instance = NamedQueries.from_config(
+ ConfigObj('~/.config_file_name'))
+
+ Contributions:
+ --------------
+
+ If you're interested in contributing to this project, first of all I would like
+ to extend my heartfelt gratitude. I've written a small doc to describe how to
+ get this running in a development setup.
+
+ https://github.com/dbcli/pgspecial/blob/master/DEVELOP.rst
+
+ Please feel free to reach out to me if you need help.
+ My email: amjith.r at gmail.com, Twitter: `@amjithr <http://twitter.com/amjithr>`_
+
+ Projects using it:
+ ------------------
+
+ This module is being used by pgcli_: A REPL for Postgres.
+
+ If you find this module useful and include it in your project, I'll be happy
+ to know about it and list it here.
+
+ .. |BuildStatus| image:: https://api.travis-ci.org/dbcli/pgspecial.svg?branch=master
+ :target: https://travis-ci.org/dbcli/pgspecial
+
+ .. |PyPI| image:: https://badge.fury.io/py/pgspecial.svg
+ :target: https://pypi.python.org/pypi/pgspecial/
+ :alt: Latest Version
+
+ .. _pgcli: https://github.com/dbcli/pgcli
+
+Platform: UNKNOWN
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: BSD License
+Classifier: Operating System :: Unix
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: SQL
+Classifier: Topic :: Database
+Classifier: Topic :: Database :: Front-Ends
+Classifier: Topic :: Software Development
+Classifier: Topic :: Software Development :: Libraries :: Python Modules
diff --git a/changelog.rst b/changelog.rst
deleted file mode 100644
index 261db23..0000000
--- a/changelog.rst
+++ /dev/null
@@ -1,28 +0,0 @@
-1.2.0
-=====
-
-Features:
----------
-
-* Add support for ``\h``. (Thanks: `stuartquin`_)
- Users can now run ``\h [keyword]`` to checkout the help for a keyboard.
-
-1.1.0
-=====
-
-Features:
----------
-
-* Support for ``\x auto`` by `stuartquin`_ with `darikg`_ (ported over from `pgcli`_).
-
-1.0.0
-=====
-
-Features:
----------
-
-* First release as an independent package.
-
-.. _`pgcli`: https://github.com/dbcli/pgcli
-.. _`stuartquin`: https://github.com/stuartquin
-.. _`darikg`: https://github.com/darikg
diff --git a/pgspecial.egg-info/PKG-INFO b/pgspecial.egg-info/PKG-INFO
new file mode 100644
index 0000000..e5c5a4a
--- /dev/null
+++ b/pgspecial.egg-info/PKG-INFO
@@ -0,0 +1,100 @@
+Metadata-Version: 1.1
+Name: pgspecial
+Version: 1.3.0
+Summary: Meta-commands handler for Postgres Database.
+Home-page: http://pgcli.com
+Author: Amjith Ramanujam
+Author-email: amjith[dot]r[at]gmail.com
+License: LICENSE.txt
+Description: Meta-commands for Postgres
+ --------------------------
+
+ |BuildStatus| |PyPI|
+
+ This package provides an API to execute meta-commands (AKA "special", or
+ "backslash commands") on PostgreSQL.
+
+ Quick Start
+ -----------
+
+ This is a python package. It can be installed with:
+
+ ::
+
+ $ pip install pgspecial
+
+
+ Usage
+ -----
+
+ Once this library is included into your project, you will most likely use the
+ following imports:
+
+ ::
+
+ from pgspecial.main import PGSpecial
+ from pgspecial.namedqueries import NamedQueries
+
+ Then you will create and use an instance of PGSpecial:
+
+ ::
+
+ pgspecial = PGSpecial()
+ for result in pgspecial.execute(cur, sql):
+ # Do something
+
+ If you want to import named queries from an existing config file, it is
+ convenient to initialize and keep around the class variable in
+ ``NamedQueries``:
+
+ ::
+
+ from configobj import ConfigObj
+
+ NamedQueries.instance = NamedQueries.from_config(
+ ConfigObj('~/.config_file_name'))
+
+ Contributions:
+ --------------
+
+ If you're interested in contributing to this project, first of all I would like
+ to extend my heartfelt gratitude. I've written a small doc to describe how to
+ get this running in a development setup.
+
+ https://github.com/dbcli/pgspecial/blob/master/DEVELOP.rst
+
+ Please feel free to reach out to me if you need help.
+ My email: amjith.r at gmail.com, Twitter: `@amjithr <http://twitter.com/amjithr>`_
+
+ Projects using it:
+ ------------------
+
+ This module is being used by pgcli_: A REPL for Postgres.
+
+ If you find this module useful and include it in your project, I'll be happy
+ to know about it and list it here.
+
+ .. |BuildStatus| image:: https://api.travis-ci.org/dbcli/pgspecial.svg?branch=master
+ :target: https://travis-ci.org/dbcli/pgspecial
+
+ .. |PyPI| image:: https://badge.fury.io/py/pgspecial.svg
+ :target: https://pypi.python.org/pypi/pgspecial/
+ :alt: Latest Version
+
+ .. _pgcli: https://github.com/dbcli/pgcli
+
+Platform: UNKNOWN
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: BSD License
+Classifier: Operating System :: Unix
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: SQL
+Classifier: Topic :: Database
+Classifier: Topic :: Database :: Front-Ends
+Classifier: Topic :: Software Development
+Classifier: Topic :: Software Development :: Libraries :: Python Modules
diff --git a/pgspecial.egg-info/SOURCES.txt b/pgspecial.egg-info/SOURCES.txt
new file mode 100644
index 0000000..0a1bb52
--- /dev/null
+++ b/pgspecial.egg-info/SOURCES.txt
@@ -0,0 +1,15 @@
+README.rst
+setup.py
+pgspecial/__init__.py
+pgspecial/dbcommands.py
+pgspecial/iocommands.py
+pgspecial/main.py
+pgspecial/namedqueries.py
+pgspecial.egg-info/PKG-INFO
+pgspecial.egg-info/SOURCES.txt
+pgspecial.egg-info/dependency_links.txt
+pgspecial.egg-info/pbr.json
+pgspecial.egg-info/requires.txt
+pgspecial.egg-info/top_level.txt
+pgspecial/help/__init__.py
+pgspecial/help/commands.py
\ No newline at end of file
diff --git a/pgspecial.egg-info/dependency_links.txt b/pgspecial.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/pgspecial.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/pgspecial.egg-info/pbr.json b/pgspecial.egg-info/pbr.json
new file mode 100644
index 0000000..56bde1b
--- /dev/null
+++ b/pgspecial.egg-info/pbr.json
@@ -0,0 +1 @@
+{"is_release": false, "git_version": "77fb297"}
\ No newline at end of file
diff --git a/pgspecial.egg-info/requires.txt b/pgspecial.egg-info/requires.txt
new file mode 100644
index 0000000..e86a836
--- /dev/null
+++ b/pgspecial.egg-info/requires.txt
@@ -0,0 +1 @@
+click >= 4.1
diff --git a/pgspecial.egg-info/top_level.txt b/pgspecial.egg-info/top_level.txt
new file mode 100644
index 0000000..a8ad873
--- /dev/null
+++ b/pgspecial.egg-info/top_level.txt
@@ -0,0 +1 @@
+pgspecial
diff --git a/pgspecial/__init__.py b/pgspecial/__init__.py
index 8a0fb6b..008ca77 100644
--- a/pgspecial/__init__.py
+++ b/pgspecial/__init__.py
@@ -1,5 +1,5 @@
__all__ = []
-__version__ = '1.2.0'
+__version__ = '1.3.0'
def export(defn):
diff --git a/pgspecial/dbcommands.py b/pgspecial/dbcommands.py
index 041d630..127fd93 100644
--- a/pgspecial/dbcommands.py
+++ b/pgspecial/dbcommands.py
@@ -25,16 +25,40 @@ def list_roles(cur, pattern, verbose):
"""
Returns (title, rows, headers, status)
"""
- sql = '''SELECT r.rolname, r.rolsuper, r.rolinherit,
- r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,
- r.rolconnlimit, r.rolvaliduntil,
- ARRAY(SELECT b.rolname
- FROM pg_catalog.pg_auth_members m
- JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)
- WHERE m.member = r.oid) as memberof''' + (''',
- pg_catalog.shobj_description(r.oid, 'pg_authid') AS description'''
- if verbose else '') + """, r.rolreplication
- FROM pg_catalog.pg_roles r """
+
+ if cur.connection.server_version > 90000:
+ sql = '''
+ SELECT r.rolname,
+ r.rolsuper,
+ r.rolinherit,
+ r.rolcreaterole,
+ r.rolcreatedb,
+ r.rolcanlogin,
+ r.rolconnlimit,
+ r.rolvaliduntil,
+ ARRAY(SELECT b.rolname FROM pg_catalog.pg_auth_members m JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid) WHERE m.member = r.oid) as memberof,
+ '''
+ if verbose:
+ sql += '''
+ pg_catalog.shobj_description(r.oid, 'pg_authid') AS description,
+ '''
+ sql += '''
+ r.rolreplication
+ FROM pg_catalog.pg_roles r
+ '''
+ else:
+ sql = '''
+ SELECT u.usename AS rolname,
+ u.usesuper AS rolsuper,
+ true AS rolinherit,
+ false AS rolcreaterole,
+ u.usecreatedb AS rolcreatedb,
+ true AS rolcanlogin,
+ -1 AS rolconnlimit,
+ u.valuntil as rolvaliduntil,
+ ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid = ANY(g.grolist)) as memberof
+ FROM pg_catalog.pg_user u
+ '''
params = []
if pattern:
@@ -177,24 +201,41 @@ def list_functions(cur, pattern, verbose):
else:
verbose_columns = verbose_table = ''
- sql = '''
- SELECT n.nspname as "Schema",
- p.proname as "Name",
- pg_catalog.pg_get_function_result(p.oid)
- as "Result data type",
- pg_catalog.pg_get_function_arguments(p.oid)
- as "Argument data types",
- CASE
- WHEN p.proisagg THEN 'agg'
- WHEN p.proiswindow THEN 'window'
- WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype
- THEN 'trigger'
- ELSE 'normal'
- END as "Type" ''' + verbose_columns + '''
- FROM pg_catalog.pg_proc p
- LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
- ''' + verbose_table + '''
- WHERE '''
+ if cur.connection.server_version > 90000:
+ sql = '''
+ SELECT n.nspname as "Schema",
+ p.proname as "Name",
+ pg_catalog.pg_get_function_result(p.oid)
+ as "Result data type",
+ pg_catalog.pg_get_function_arguments(p.oid)
+ as "Argument data types",
+ CASE
+ WHEN p.proisagg THEN 'agg'
+ WHEN p.proiswindow THEN 'window'
+ WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype
+ THEN 'trigger'
+ ELSE 'normal'
+ END as "Type" ''' + verbose_columns + '''
+ FROM pg_catalog.pg_proc p
+ LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
+ ''' + verbose_table + '''
+ WHERE '''
+ else:
+ sql = '''
+ SELECT n.nspname as "Schema",
+ p.proname as "Name",
+ pg_catalog.format_type(p.prorettype, NULL) as "Result data type",
+ pg_catalog.oidvectortypes(p.proargtypes) as "Argument data types",
+ CASE
+ WHEN p.proisagg THEN 'agg'
+ WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN 'trigger'
+ ELSE 'normal'
+ END as "Type" ''' + verbose_columns + '''
+ FROM pg_catalog.pg_proc p
+ LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
+ ''' + verbose_table + '''
+ WHERE '''
+
schema_pattern, func_pattern = sql_name_pattern(pattern)
params = []
@@ -253,18 +294,27 @@ def list_datatypes(cur, pattern, verbose):
sql += ''' pg_catalog.obj_description(t.oid, 'pg_type')
as "Description" '''
- sql += ''' FROM pg_catalog.pg_type t
- LEFT JOIN pg_catalog.pg_namespace n
- ON n.oid = t.typnamespace
- WHERE (t.typrelid = 0 OR
- ( SELECT c.relkind = 'c'
- FROM pg_catalog.pg_class c
- WHERE c.oid = t.typrelid))
- AND NOT EXISTS(
- SELECT 1
- FROM pg_catalog.pg_type el
- WHERE el.oid = t.typelem
- AND el.typarray = t.oid) '''
+ if cur.connection.server_version > 90000:
+ sql += ''' FROM pg_catalog.pg_type t
+ LEFT JOIN pg_catalog.pg_namespace n
+ ON n.oid = t.typnamespace
+ WHERE (t.typrelid = 0 OR
+ ( SELECT c.relkind = 'c'
+ FROM pg_catalog.pg_class c
+ WHERE c.oid = t.typrelid))
+ AND NOT EXISTS(
+ SELECT 1
+ FROM pg_catalog.pg_type el
+ WHERE el.oid = t.typelem
+ AND el.typarray = t.oid) '''
+ else:
+ sql += ''' FROM pg_catalog.pg_type t
+ LEFT JOIN pg_catalog.pg_namespace n
+ ON n.oid = t.typnamespace
+ WHERE (t.typrelid = 0 OR
+ ( SELECT c.relkind = 'c'
+ FROM pg_catalog.pg_class c
+ WHERE c.oid = t.typrelid)) '''
schema_pattern, type_pattern = sql_name_pattern(pattern)
params = []
@@ -370,17 +420,46 @@ def describe_one_table_details(cur, schema_name, relation_name, oid, verbose):
else:
suffix = "''"
- sql ="""SELECT c.relchecks, c.relkind, c.relhasindex,
- c.relhasrules, c.relhastriggers, c.relhasoids,
- %s,
- c.reltablespace,
- CASE WHEN c.reloftype = 0 THEN ''
- ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text
- END,
- c.relpersistence
- FROM pg_catalog.pg_class c
- LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)
- WHERE c.oid = '%s'""" % (suffix, oid)
+ if cur.connection.server_version > 90000:
+ sql = """SELECT c.relchecks, c.relkind, c.relhasindex,
+ c.relhasrules, c.relhastriggers, c.relhasoids,
+ %s,
+ c.reltablespace,
+ CASE WHEN c.reloftype = 0 THEN ''
+ ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text
+ END,
+ c.relpersistence
+ FROM pg_catalog.pg_class c
+ LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)
+ WHERE c.oid = '%s'""" % (suffix, oid)
+ elif cur.connection.server_version >= 80400:
+ sql = """SELECT c.relchecks,
+ c.relkind,
+ c.relhasindex,
+ c.relhasrules,
+ c.relhastriggers,
+ c.relhasoids,
+ %s,
+ c.reltablespace,
+ 0 AS reloftype,
+ 'p' AS relpersistence
+ FROM pg_catalog.pg_class c
+ LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)
+ WHERE c.oid = '%s'""" % (suffix, oid)
+ else:
+ sql = """SELECT c.relchecks,
+ c.relkind,
+ c.relhasindex,
+ c.relhasrules,
+ c.reltriggers > 0 AS relhastriggers,
+ c.relhasoids,
+ %s,
+ c.reltablespace,
+ 0 AS reloftype,
+ 'p' AS relpersistence
+ FROM pg_catalog.pg_class c
+ LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)
+ WHERE c.oid = '%s'""" % (suffix, oid)
# Create a namedtuple called tableinfo and match what's in describe.c
@@ -403,13 +482,42 @@ def describe_one_table_details(cur, schema_name, relation_name, oid, verbose):
seq_values = cur.fetchone()
# Get column info
- sql = """SELECT a.attname, pg_catalog.format_type(a.atttypid, a.atttypmod),
- (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)
- FROM pg_catalog.pg_attrdef d WHERE d.adrelid = a.attrelid AND d.adnum =
- a.attnum AND a.atthasdef), a.attnotnull, a.attnum, (SELECT c.collname
- FROM pg_catalog.pg_collation c, pg_catalog.pg_type t WHERE c.oid =
- a.attcollation AND t.oid = a.atttypid AND a.attcollation <>
- t.typcollation) AS attcollation"""
+ if cur.connection.server_version > 90000:
+ sql = """SELECT a.attname,
+ pg_catalog.format_type(a.atttypid, a.atttypmod),
+ (
+ SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)
+ FROM pg_catalog.pg_attrdef d
+ WHERE d.adrelid = a.attrelid
+ AND d.adnum = a.attnum
+ AND a.atthasdef
+ ),
+ a.attnotnull,
+ a.attnum,
+ (
+ SELECT c.collname
+ FROM pg_catalog.pg_collation c,
+ pg_catalog.pg_type t
+ WHERE c.oid = a.attcollation
+ AND t.oid = a.atttypid
+ AND a.attcollation <> t.typcollation
+ ) AS attcollation
+ """
+ else:
+ sql = """SELECT a.attname,
+ pg_catalog.format_type(a.atttypid, a.atttypmod),
+ (
+ SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)
+ FROM pg_catalog.pg_attrdef d
+ WHERE d.adrelid = a.attrelid
+ AND d.adnum = a.attnum
+ AND a.atthasdef
+ ),
+ a.attnotnull,
+ a.attnum,
+ NULL AS attcollation
+ """
+
if tableinfo.relkind == 'i':
sql += """, pg_catalog.pg_get_indexdef(a.attrelid, a.attnum, TRUE)
@@ -545,17 +653,58 @@ def describe_one_table_details(cur, schema_name, relation_name, oid, verbose):
if (tableinfo.relkind == 'i'):
# /* Footer information about an index */
- sql = """SELECT i.indisunique, i.indisprimary, i.indisclustered,
- i.indisvalid, (NOT i.indimmediate) AND EXISTS (SELECT 1 FROM
- pg_catalog.pg_constraint WHERE conrelid = i.indrelid AND conindid =
- i.indexrelid AND contype IN ('p','u','x') AND condeferrable) AS
- condeferrable, (NOT i.indimmediate) AND EXISTS (SELECT 1 FROM
- pg_catalog.pg_constraint WHERE conrelid = i.indrelid AND conindid =
- i.indexrelid AND contype IN ('p','u','x') AND condeferred) AS
- condeferred, a.amname, c2.relname, pg_catalog.pg_get_expr(i.indpred,
- i.indrelid, true) FROM pg_catalog.pg_index i, pg_catalog.pg_class c,
- pg_catalog.pg_class c2, pg_catalog.pg_am a WHERE i.indexrelid = c.oid
- AND c.oid = '%s' AND c.relam = a.oid AND i.indrelid = c2.oid;""" % oid
+ if cur.connection.server_version > 90000:
+ sql = """SELECT i.indisunique,
+ i.indisprimary,
+ i.indisclustered,
+ i.indisvalid,
+ (NOT i.indimmediate) AND EXISTS (
+ SELECT 1
+ FROM pg_catalog.pg_constraint
+ WHERE conrelid = i.indrelid
+ AND conindid = i.indexrelid
+ AND contype IN ('p','u','x')
+ AND condeferrable
+ ) AS condeferrable,
+ (NOT i.indimmediate) AND EXISTS (
+ SELECT 1
+ FROM pg_catalog.pg_constraint
+ WHERE conrelid = i.indrelid
+ AND conindid = i.indexrelid
+ AND contype IN ('p','u','x')
+ AND condeferred
+ ) AS condeferred,
+ a.amname,
+ c2.relname,
+ pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)
+ FROM pg_catalog.pg_index i,
+ pg_catalog.pg_class c,
+ pg_catalog.pg_class c2,
+ pg_catalog.pg_am a
+ WHERE i.indexrelid = c.oid
+ AND c.oid = '%s'
+ AND c.relam = a.oid
+ AND i.indrelid = c2.oid;
+ """ % oid
+ else:
+ sql = """SELECT i.indisunique,
+ i.indisprimary,
+ i.indisclustered,
+ 't' AS indisvalid,
+ 'f' AS condeferrable,
+ 'f' AS condeferred,
+ a.amname,
+ c2.relname,
+ pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)
+ FROM pg_catalog.pg_index i,
+ pg_catalog.pg_class c,
+ pg_catalog.pg_class c2,
+ pg_catalog.pg_am a
+ WHERE i.indexrelid = c.oid
+ AND c.oid = '%s'
+ AND c.relam = a.oid
+ AND i.indrelid = c2.oid;
+ """ % oid
log.debug(sql)
cur.execute(sql)
@@ -624,17 +773,57 @@ def describe_one_table_details(cur, schema_name, relation_name, oid, verbose):
#/* Footer information about a table */
if (tableinfo.hasindex):
- sql = "SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered, "
- sql += "i.indisvalid, "
- sql += "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n "
- sql += ("pg_catalog.pg_get_constraintdef(con.oid, true), "
- "contype, condeferrable, condeferred")
- sql += ", c2.reltablespace"
- sql += ("\nFROM pg_catalog.pg_class c, pg_catalog.pg_class c2, "
- "pg_catalog.pg_index i\n")
- sql += " LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))\n"
- sql += ("WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
- "ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname;") % oid
+ if cur.connection.server_version > 90000:
+ sql = """SELECT c2.relname,
+ i.indisprimary,
+ i.indisunique,
+ i.indisclustered,
+ i.indisvalid,
+ pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),
+ pg_catalog.pg_get_constraintdef(con.oid, true),
... 647 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-pgspecial.git
More information about the Python-modules-commits
mailing list