server/sqlutils.py
changeset 4353 7db69db4913c
parent 4342 b4e186da08f2
child 4436 294e084f1263
equal deleted inserted replaced
4352:afe1f9bc308a 4353:7db69db4913c
    31 
    31 
    32 
    32 
    33 lgc.USE_MX_DATETIME = False
    33 lgc.USE_MX_DATETIME = False
    34 SQL_PREFIX = 'cw_'
    34 SQL_PREFIX = 'cw_'
    35 
    35 
    36 def bw_run_command(cmd):
    36 def _run_command(cmd):
    37     """backup/restore command are string w/ lgc < 0.47, lists with earlier versions
    37     """backup/restore command are string w/ lgc < 0.47, lists with earlier versions
    38     """
    38     """
    39     if isinstance(cmd, basestring):
    39     if isinstance(cmd, basestring):
    40         print cmd
    40         print '->', cmd
    41         return os.system(cmd)
    41         return subprocess.call(cmd, shell=True)
    42     print ' '.join(cmd)
    42     print ' '.join(cmd)
    43     return subprocess.call(cmd)
    43     return subprocess.call(cmd)
    44 
    44 
    45 
    45 
    46 def sqlexec(sqlstmts, cursor_or_execute, withpb=not os.environ.get('APYCOT_ROOT'),
    46 def sqlexec(sqlstmts, cursor_or_execute, withpb=not os.environ.get('APYCOT_ROOT'),
   181 
   181 
   182     def backup_to_file(self, backupfile):
   182     def backup_to_file(self, backupfile):
   183         for cmd in self.dbhelper.backup_commands(self.dbname, self.dbhost,
   183         for cmd in self.dbhelper.backup_commands(self.dbname, self.dbhost,
   184                                                  self.dbuser, backupfile,
   184                                                  self.dbuser, backupfile,
   185                                                  keepownership=False):
   185                                                  keepownership=False):
   186             if bw_run_command(cmd):
   186             if _run_command(cmd):
   187                 if not confirm('-> Failed. Continue anyway?', default='n'):
   187                 if not confirm('   [Failed] Continue anyway?', default='n'):
   188                     raise Exception('Failed command: %s' % cmd)
   188                     raise Exception('Failed command: %s' % cmd)
   189 
   189 
   190     def restore_from_file(self, backupfile, confirm, drop=True):
   190     def restore_from_file(self, backupfile, confirm, drop=True):
   191         for cmd in self.dbhelper.restore_commands(self.dbname, self.dbhost,
   191         for cmd in self.dbhelper.restore_commands(self.dbname, self.dbhost,
   192                                                   self.dbuser, backupfile,
   192                                                   self.dbuser, backupfile,
   193                                                   self.encoding,
   193                                                   self.encoding,
   194                                                   keepownership=False,
   194                                                   keepownership=False,
   195                                                   drop=drop):
   195                                                   drop=drop):
   196             if bw_run_command(cmd):
   196             if _run_command(cmd):
   197                 if not confirm('Failed. Continue anyway?', default='n'):
   197                 if not confirm('   [Failed] Continue anyway?', default='n'):
   198                     raise Exception('Failed command: %s' % cmd)
   198                     raise Exception('Failed command: %s' % cmd)
   199 
   199 
   200     def merge_args(self, args, query_args):
   200     def merge_args(self, args, query_args):
   201         if args is not None:
   201         if args is not None:
   202             args = dict(args)
   202             args = dict(args)
   235                     result.append(value)
   235                     result.append(value)
   236                     continue
   236                     continue
   237                 result.append(process_value(value, descr[col], encoding, binary))
   237                 result.append(process_value(value, descr[col], encoding, binary))
   238             results[i] = result
   238             results[i] = result
   239         return results
   239         return results
   240 
       
   241 
   240 
   242     def preprocess_entity(self, entity):
   241     def preprocess_entity(self, entity):
   243         """return a dictionary to use as extra argument to cursor.execute
   242         """return a dictionary to use as extra argument to cursor.execute
   244         to insert/update an entity into a SQL database
   243         to insert/update an entity into a SQL database
   245         """
   244         """