duplicate_database missing

Bug #1319843 reported by Carlo - Didotech.com
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
New
Undecided
Unassigned
OpenERP Community Backports (Server)
New
Undecided
Unassigned
6.1
New
Undecided
Unassigned

Bug Description

on webinterface is not possible to duplicate db as on version 7

this will fix bug:

=== modified file 'openerp/service/web_services.py'
--- openerp/service/web_services.py 2012-03-23 11:17:50 +0000
+++ openerp/service/web_services.py 2014-05-04 12:49:29 +0000
@@ -101,7 +101,7 @@

     def dispatch(self, method, params):
         if method in [ 'create', 'get_progress', 'drop', 'dump',
- 'restore', 'rename',
+ 'restore', 'rename', 'duplicate_database',
             'change_admin_password', 'migrate_databases',
             'create_database' ]:
             passwd = params[0]
@@ -126,6 +126,18 @@
         finally:
             cr.close()

+ def exp_duplicate_database(self, db_original_name, db_name):
+ _logger.info('Duplicate database `%s` to `%s`.', db_original_name, db_name)
+ sql_db.close_db(db_original_name)
+ db = sql_db.db_connect('postgres')
+ cr = db.cursor()
+ try:
+ cr.autocommit(True) # avoid transaction block
+ cr.execute("""CREATE DATABASE "%s" ENCODING 'unicode' TEMPLATE "%s" """ % (db_name, db_original_name))
+ finally:
+ cr.close()
+ return True
+
     def exp_create(self, db_name, demo, lang, user_password='admin'):
         self.id_protect.acquire()
         self.id += 1

@@ -185,11 +197,17 @@
             # Try to terminate all other connections that might prevent
             # dropping the database
             try:
- cr.execute("""SELECT pg_terminate_backend(procpid)
+
+ # PostgreSQL 9.2 renamed pg_stat_activity.procpid to pid:
+ # http://www.postgresql.org/docs/9.2/static/release-9-2.html#AEN110389
+ pid_col = 'pid' if cr._cnx.server_version >= 90200 else 'procpid'
+
+ cr.execute("""SELECT pg_terminate_backend(%(pid_col)s)
                               FROM pg_stat_activity
- WHERE datname = %s AND
- procpid != pg_backend_pid()""",
+ WHERE datname = %%s AND
+ %(pid_col)s != pg_backend_pid()""" % {'pid_col': pid_col},
                            (db_name,))
+
             except Exception:
                 pass

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.