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

Source Code for Module buildbot.db.util

 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 -def sql_insert(dbapi, table, columns):
17 """ 18 Make an SQL insert statement for the given table and columns, using the 19 appropriate paramstyle for the dbi. Note that this only supports positional 20 parameters. This will need to be reworked if Buildbot supports a backend with 21 a name-based paramstyle. 22 """ 23 24 if dbapi.paramstyle == 'qmark': 25 params = ",".join(("?",)*len(columns)) 26 elif dbapi.paramstyle == 'numeric': 27 params = ",".join(":%d" % d for d in range(1, len(columns)+1)) 28 elif dbapi.paramstyle == 'format': 29 params = ",".join(("%s",)*len(columns)) 30 else: 31 raise RuntimeError("unsupported paramstyle %s" % dbapi.paramstyle) 32 return "INSERT INTO %s (%s) VALUES (%s)" % (table, ", ".join(columns), params)
33