[tryton-debian-vcs] python-sql branch debian updated. debian/0.2-2-9-g05d9e26
Mathias Behrle
tryton-debian-vcs at alioth.debian.org
Fri Feb 28 16:49:37 UTC 2014
The following commit has been merged in the debian branch:
https://alioth.debian.org/plugins/scmgit/cgi-bin/gitweb.cgi/?p=tryton/python-sql.git;a=commitdiff;h=debian/0.2-2-9-g05d9e26
commit 05d9e2670297546496319215b1e1b8298a66cd9d
Author: Mathias Behrle <mathiasb at m9s.biz>
Date: Fri Feb 28 17:48:38 2014 +0100
Releasing debian version 0.3-1.
diff --git a/debian/changelog b/debian/changelog
index ed344e9..c0ee9e4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,16 @@
+python-sql (0.3-1) unstable; urgency=medium
+
+ * Updating year in debian copyright.
+ * Removing debian/source/options, we are building with dpkg defaults.
+ * Backporting correct fix for #725788.
+ * Simplifying rules file by using PYBUILD_NAME.
+ * Adding gpg verification for uscan.
+ * Adding gbp.conf for usage with git-buildpackage.
+ * Merging upstream version 0.3.
+ * Removing all patches, they went upstream.
+
+ -- Mathias Behrle <mathiasb at m9s.biz> Fri, 28 Feb 2014 17:36:14 +0100
+
python-sql (0.2-2) unstable; urgency=low
* Removing version constraint for build dependency python3.
commit b4131cd4660581d00c4f4f1bc5b4e3e3b18eaa69
Author: Mathias Behrle <mathiasb at m9s.biz>
Date: Fri Feb 28 17:35:57 2014 +0100
Removing all patches, they went upstream.
diff --git a/debian/patches/fix_slots_shadows_class_variable.patch b/debian/patches/fix_slots_shadows_class_variable.patch
deleted file mode 100644
index 00cb85f..0000000
--- a/debian/patches/fix_slots_shadows_class_variable.patch
+++ /dev/null
@@ -1,27 +0,0 @@
-Description: Fix slots shadows class variable in AliasManager
-This patch already went upstream and is subject for removal with version > 0.2
-Origin: http://code.google.com/p/python-sql/source/detail?r=217fc0c811dac6883f69e30c6943b95c97e41e77
-Bug: http://code.google.com/p/python-sql/issues/detail?id=12
-Reviewed-By: Mathias Behrle<mathiasb at m9s.biz>
-Last-Update: 2013-10-10
-
---- python-sql-0.2.orig/sql/__init__.py
-+++ python-sql-0.2/sql/__init__.py
-@@ -29,7 +29,7 @@
-
- from __future__ import division
-
--__version__ = '0.2'
-+__version__ = '0.3'
- __all__ = ['Flavor', 'Table', 'Literal', 'Column', 'Join', 'Asc', 'Desc']
-
- import string
-@@ -110,7 +110,7 @@ class AliasManager(object):
- '''
- Context Manager for unique alias generation
- '''
-- __slots__ = 'local'
-+ __slots__ = ()
-
- local = local()
- local.alias = None
diff --git a/debian/patches/series b/debian/patches/series
deleted file mode 100644
index 41e7474..0000000
--- a/debian/patches/series
+++ /dev/null
@@ -1,2 +0,0 @@
-fix_slots_shadows_class_variable.patch
-setup_python3_encoding.patch
diff --git a/debian/patches/setup_python3_encoding.patch b/debian/patches/setup_python3_encoding.patch
deleted file mode 100644
index 3effaf8..0000000
--- a/debian/patches/setup_python3_encoding.patch
+++ /dev/null
@@ -1,23 +0,0 @@
-Description: Backport of encoding fix
-This patch solves the encoding problem, when reading files with python3
-in a basic POSIX environment (#725788).
-
-Origin: upstream, https://code.google.com/p/python-sql/source/detail?r=fa73dd3e45dda96e88a1b266018ecfe3819c758c
-Bug-Debian: http://bugs.debian.org/725788
-
---- python-sql.orig/setup.py 2014-01-28 18:50:34.092730374 +0100
-+++ python-sql/setup.py 2014-01-28 18:57:36.000000000 +0100
-@@ -30,10 +30,12 @@
- from setuptools import setup, find_packages
- import os
- import re
-+import codecs
-
-
- def read(fname):
-- return open(os.path.join(os.path.dirname(__file__), fname)).read()
-+ return codecs.open(
-+ os.path.join(os.path.dirname(__file__), fname), 'r', 'utf-8').read()
-
-
- def get_version():
commit 90a0439c2b4207998f040edc66503b7410abd940
Author: Mathias Behrle <mathiasb at m9s.biz>
Date: Fri Feb 28 17:27:41 2014 +0100
Merging upstream version 0.3.
diff --git a/CHANGELOG b/CHANGELOG
index 2780393..06d65f3 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,9 @@
+Version 0.3 - 2014-01-31
+* Add returning to Update
+* Add missing params for returning
+* Add columns definitions to Function
+* Fix AtTimeZone mapping
+
Version 0.2 - 2013-09-18
* Fix usage mixture between Div operator and function
* Add array support in operators
diff --git a/PKG-INFO b/PKG-INFO
index 2a7162e..1dd3522 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: python-sql
-Version: 0.2
+Version: 0.3
Summary: Library to write SQL queries
Home-page: http://code.google.com/p/python-sql/
Author: B2CK
diff --git a/python_sql.egg-info/PKG-INFO b/python_sql.egg-info/PKG-INFO
index 2a7162e..1dd3522 100644
--- a/python_sql.egg-info/PKG-INFO
+++ b/python_sql.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: python-sql
-Version: 0.2
+Version: 0.3
Summary: Library to write SQL queries
Home-page: http://code.google.com/p/python-sql/
Author: B2CK
diff --git a/setup.py b/setup.py
index 28fe987..09e38fe 100644
--- a/setup.py
+++ b/setup.py
@@ -30,10 +30,12 @@
from setuptools import setup, find_packages
import os
import re
+import codecs
def read(fname):
- return open(os.path.join(os.path.dirname(__file__), fname)).read()
+ return codecs.open(
+ os.path.join(os.path.dirname(__file__), fname), 'r', 'utf-8').read()
def get_version():
diff --git a/sql/__init__.py b/sql/__init__.py
index 2c65f6b..1238546 100644
--- a/sql/__init__.py
+++ b/sql/__init__.py
@@ -29,7 +29,7 @@
from __future__ import division
-__version__ = '0.2'
+__version__ = '0.3'
__all__ = ['Flavor', 'Table', 'Literal', 'Column', 'Join', 'Asc', 'Desc']
import string
@@ -110,7 +110,7 @@ class AliasManager(object):
'''
Context Manager for unique alias generation
'''
- __slots__ = 'local'
+ __slots__ = ()
local = local()
local.alias = None
@@ -470,26 +470,29 @@ class Insert(Query):
@property
def params(self):
+ p = []
if isinstance(self.values, list):
- p = []
for values in self.values:
for value in values:
if isinstance(value, (Expression, Select)):
p.extend(value.params)
else:
p.append(value)
- return tuple(p)
elif isinstance(self.values, Select):
- return self.values.params
- else:
- return ()
+ p.extend(self.values.params)
+ if self.returning:
+ for exp in self.returning:
+ p.extend(exp.params)
+ return tuple(p)
class Update(Insert):
__slots__ = ('__where', '__values', 'from_')
- def __init__(self, table, columns, values, from_=None, where=None):
- super(Update, self).__init__(table, columns=columns, values=values)
+ def __init__(self, table, columns, values, from_=None, where=None,
+ returning=None):
+ super(Update, self).__init__(table, columns=columns, values=values,
+ returning=returning)
self.__where = None
self.from_ = From(from_) if from_ else None
self.where = where
@@ -534,7 +537,11 @@ class Update(Insert):
where = ''
if self.where:
where = ' WHERE ' + str(self.where)
- return 'UPDATE %s SET ' % table + values + from_ + where
+ returning = ''
+ if self.returning:
+ returning = ' RETURNING ' + ', '.join(map(str, self.returning))
+ return ('UPDATE %s SET ' % table + values + from_ + where
+ + returning)
@property
def params(self):
@@ -548,6 +555,9 @@ class Update(Insert):
p.extend(self.from_.params)
if self.where:
p.extend(self.where.params)
+ if self.returning:
+ for exp in self.returning:
+ p.extend(exp.params)
return tuple(p)
@@ -607,7 +617,13 @@ class Delete(Query):
@property
def params(self):
- return self.where.params if self.where else ()
+ p = []
+ if self.where:
+ p.extend(self.where.params)
+ if self.returning:
+ for exp in self.returning:
+ p.extend(exp.params)
+ return tuple(p)
class CombiningQuery(Query, FromItem, _SelectQueryMixin):
@@ -670,9 +686,9 @@ class Table(FromItem):
return Insert(self, columns=columns, values=values,
returning=returning)
- def update(self, columns, values, from_=None, where=None):
+ def update(self, columns, values, from_=None, where=None, returning=None):
return Update(self, columns=columns, values=values, from_=from_,
- where=where)
+ where=where, returning=returning)
def delete(self, only=False, using=None, where=None, returning=None):
return Delete(self, only=only, using=using, where=where,
@@ -774,7 +790,14 @@ class From(list):
return '(%s) AS "%s"' % (from_, from_.alias)
else:
alias = getattr(from_, 'alias', None)
- if alias:
+ columns_definitions = getattr(from_, 'columns_definitions',
+ None)
+ # XXX find a better test for __getattr__ which returns Column
+ if (alias and columns_definitions
+ and not isinstance(columns_definitions, Column)):
+ return '%s AS "%s" (%s)' % (from_, alias,
+ columns_definitions)
+ elif alias:
return '%s AS "%s"' % (from_, alias)
else:
return str(from_)
diff --git a/sql/functions.py b/sql/functions.py
index 58fb127..6e86138 100644
--- a/sql/functions.py
+++ b/sql/functions.py
@@ -47,13 +47,24 @@ __all__ = ['Abs', 'Cbrt', 'Ceil', 'Degrees', 'Div', 'Exp', 'Floor', 'Ln',
class Function(Expression, FromItem):
- __slots__ = ('args',)
+ __slots__ = ('args', '__columns_definitions')
table = ''
name = ''
_function = ''
- def __init__(self, *args):
+ def __init__(self, *args, **kwargs):
self.args = args
+ self.columns_definitions = kwargs.get('columns_definitions', [])
+
+ @property
+ def columns_definitions(self):
+ return ', '.join('"%s" %s' % (c, d)
+ for c, d in self.__columns_definitions)
+
+ @columns_definitions.setter
+ def columns_definitions(self, value):
+ assert isinstance(value, list)
+ self.__columns_definitions = value
@staticmethod
def _format(value):
@@ -453,7 +464,7 @@ class AtTimeZone(Function):
flavor = Flavor.get()
Mapping = flavor.function_mapping.get(self.__class__)
if Mapping:
- return str(Mapping(*self.args))
+ return str(Mapping(self.field, self.zone))
param = flavor.param
return '%s AT TIME ZONE %s' % (str(self.field), param)
diff --git a/sql/tests/test_delete.py b/sql/tests/test_delete.py
index 2ba1474..4254f44 100644
--- a/sql/tests/test_delete.py
+++ b/sql/tests/test_delete.py
@@ -52,3 +52,8 @@ class TestDelete(unittest.TestCase):
'DELETE FROM "t1" WHERE ("c" IN ('
'SELECT "a"."c" FROM "t2" AS "a"))')
self.assertEqual(query.params, ())
+
+ def test_delete_returning(self):
+ query = self.table.delete(returning=[self.table.c])
+ self.assertEqual(str(query), 'DELETE FROM "t" RETURNING "c"')
+ self.assertEqual(query.params, ())
diff --git a/sql/tests/test_functions.py b/sql/tests/test_functions.py
index 3872187..091e9b6 100644
--- a/sql/tests/test_functions.py
+++ b/sql/tests/test_functions.py
@@ -78,3 +78,18 @@ class TestFunctions(unittest.TestCase):
time_zone = AtTimeZone(self.table.c1, 'UTC')
self.assertEqual(str(time_zone), '"c1" AT TIME ZONE %s')
self.assertEqual(time_zone.params, ('UTC',))
+
+ def test_at_time_zone_mapping(self):
+ class MyAtTimeZone(Function):
+ _function = 'MY_TIMEZONE'
+
+ time_zone = AtTimeZone(self.table.c1, 'UTC')
+ flavor = Flavor(function_mapping={
+ AtTimeZone: MyAtTimeZone,
+ })
+ Flavor.set(flavor)
+ try:
+ self.assertEqual(str(time_zone), 'MY_TIMEZONE("c1", %s)')
+ self.assertEqual(time_zone.params, ('UTC',))
+ finally:
+ Flavor.set(Flavor())
diff --git a/sql/tests/test_insert.py b/sql/tests/test_insert.py
index 92954a2..283fa80 100644
--- a/sql/tests/test_insert.py
+++ b/sql/tests/test_insert.py
@@ -70,3 +70,11 @@ class TestInsert(unittest.TestCase):
self.assertEqual(str(query),
'INSERT INTO "t" ("c") VALUES (ABS(%s))')
self.assertEqual(query.params, (-1,))
+
+ def test_insert_returning(self):
+ query = self.table.insert([self.table.c1, self.table.c2],
+ [['foo', 'bar']], returning=[self.table.c1, self.table.c2])
+ self.assertEqual(str(query),
+ 'INSERT INTO "t" ("c1", "c2") VALUES (%s, %s) '
+ 'RETURNING "c1", "c2"')
+ self.assertEqual(query.params, ('foo', 'bar'))
diff --git a/sql/tests/test_select.py b/sql/tests/test_select.py
index b17142f..0adadd7 100644
--- a/sql/tests/test_select.py
+++ b/sql/tests/test_select.py
@@ -30,7 +30,7 @@
import unittest
from sql import Table, Join, Union, Literal, Flavor
-from sql.functions import Now
+from sql.functions import Now, Function
from sql.aggregate import Min
@@ -114,6 +114,17 @@ class TestSelect(unittest.TestCase):
self.assertEqual(str(query), 'SELECT * FROM NOW() AS "a"')
self.assertEqual(query.params, ())
+ def test_select_function_columns_definitions(self):
+ class Crosstab(Function):
+ _function = 'CROSSTAB'
+
+ query = Crosstab('query1', 'query2',
+ columns_definitions=[
+ ('c1', 'INT'), ('c2', 'CHAR'), ('c3', 'BOOL')]).select()
+ self.assertEqual(str(query), 'SELECT * FROM CROSSTAB(%s, %s) '
+ 'AS "a" ("c1" INT, "c2" CHAR, "c3" BOOL)')
+ self.assertEqual(query.params, ('query1', 'query2'))
+
def test_select_group_by(self):
column = self.table.c
query = self.table.select(column, group_by=column)
diff --git a/sql/tests/test_update.py b/sql/tests/test_update.py
index c0e0219..3cf1964 100644
--- a/sql/tests/test_update.py
+++ b/sql/tests/test_update.py
@@ -61,3 +61,10 @@ class TestUpdate(unittest.TestCase):
'UPDATE "t1" SET "c" = ('
'SELECT "b"."c" FROM "t2" AS "b" WHERE ("b"."i" = "t1"."i"))')
self.assertEqual(query.params, ())
+
+ def test_update_returning(self):
+ query = self.table.update([self.table.c], ['foo'],
+ returning=[self.table.c])
+ self.assertEqual(str(query),
+ 'UPDATE "t" SET "c" = %s RETURNING "t"."c"')
+ self.assertEqual(query.params, ('foo',))
--
python-sql
More information about the tryton-debian-vcs
mailing list