Package buildbot :: Package util :: Module sautils
[frames] | no frames]

Source Code for Module buildbot.util.sautils

 1  # This file is part of Buildbot.  Buildbot is free software: you can 
 2  # redistribute it and/or modify it under the terms of the GNU General Public 
 3  # License as published by the Free Software Foundation, version 2. 
 4  # 
 5  # This program is distributed in the hope that it will be useful, but WITHOUT 
 6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
 8  # details. 
 9  # 
10  # You should have received a copy of the GNU General Public License along with 
11  # this program; if not, write to the Free Software Foundation, Inc., 51 
12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
13  # 
14  # Copyright Buildbot Team Members 
15   
16  import sqlalchemy as sa 
17  from sqlalchemy.ext import compiler 
18  from sqlalchemy.sql.expression import Executable, ClauseElement 
19 20 # from http://www.sqlalchemy.org/docs/core/compiler.html#compiling-sub-elements-of-a-custom-expression-construct 21 22 -class InsertFromSelect(Executable, ClauseElement):
23 """ 24 An L{Executable} that can insert into C{table} the values from C{select} 25 """
26 - def __init__(self, table, select):
27 self.table = table 28 self.select = select
29
30 @compiler.compiles(InsertFromSelect) 31 -def _visit_insert_from_select(element, compiler, **kw):
32 return "INSERT INTO %s %s" % ( 33 compiler.process(element.table, asfrom=True), 34 compiler.process(element.select) 35 )
36
37 -def sa_version():
38 if hasattr(sa, '__version__'): 39 return tuple(map(int, sa.__version__.split('.'))) 40 return (0,0,0) # "it's old"
41