1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/sqlliterals/common.py Mon Aug 13 00:34:49 2007 +0200
1.3 @@ -0,0 +1,40 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +Convert one paramstyle to another in SQL statements.
1.8 +
1.9 +Copyright (C) 2007 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This library is free software; you can redistribute it and/or
1.12 +modify it under the terms of the GNU Lesser General Public
1.13 +License as published by the Free Software Foundation; either
1.14 +version 2.1 of the License, or (at your option) any later version.
1.15 +
1.16 +This library is distributed in the hope that it will be useful,
1.17 +but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.19 +Lesser General Public License for more details.
1.20 +
1.21 +You should have received a copy of the GNU Lesser General Public
1.22 +License along with this library; if not, write to the Free Software
1.23 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
1.24 +"""
1.25 +
1.26 +def replace(fromstyle, tostyle, regions):
1.27 +
1.28 + """
1.29 + Return a new sequence of regions, where the paramstyle 'fromstyle' is
1.30 + replaced with 'tostyle' in the appropriate elements of 'regions'.
1.31 + """
1.32 +
1.33 + new_regions = []
1.34 + non_literal = 1
1.35 + for region in regions:
1.36 + if non_literal:
1.37 + new_regions.append(region.replace(fromstyle, tostyle))
1.38 + else:
1.39 + new_regions.append(region)
1.40 + non_literal = not non_literal
1.41 + return new_regions
1.42 +
1.43 +# vim: tabstop=4 expandtab shiftwidth=4