server/sqlutils.py
changeset 10589 7c23b7de2b8d
parent 10588 fdaa0e4b7eaf
child 10607 6519ae8cca0c
equal deleted inserted replaced
10588:fdaa0e4b7eaf 10589:7c23b7de2b8d
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """SQL utilities functions and classes."""
    18 """SQL utilities functions and classes."""
       
    19 from __future__ import print_function
    19 
    20 
    20 __docformat__ = "restructuredtext en"
    21 __docformat__ = "restructuredtext en"
    21 
    22 
    22 import sys
    23 import sys
    23 import os
    24 import os
    41 
    42 
    42 lgc.USE_MX_DATETIME = False
    43 lgc.USE_MX_DATETIME = False
    43 SQL_PREFIX = 'cw_'
    44 SQL_PREFIX = 'cw_'
    44 
    45 
    45 def _run_command(cmd):
    46 def _run_command(cmd):
    46     print ' '.join(cmd)
    47     print(' '.join(cmd))
    47     return subprocess.call(cmd)
    48     return subprocess.call(cmd)
    48 
    49 
    49 
    50 
    50 def sqlexec(sqlstmts, cursor_or_execute, withpb=True,
    51 def sqlexec(sqlstmts, cursor_or_execute, withpb=True,
    51             pbtitle='', delimiter=';', cnx=None):
    52             pbtitle='', delimiter=';', cnx=None):
    92             failed.append(sql)
    93             failed.append(sql)
    93         else:
    94         else:
    94             if cnx:
    95             if cnx:
    95                 cnx.commit()
    96                 cnx.commit()
    96     if withpb:
    97     if withpb:
    97         print
    98         print()
    98     if sqlstmts_as_string:
    99     if sqlstmts_as_string:
    99         failed = delimiter.join(failed)
   100         failed = delimiter.join(failed)
   100     return failed
   101     return failed
   101 
   102 
   102 
   103