backend/satellite_tools/sync_handlers.py | 6 +++---
backend/server/rhnSQL/__init__.py | 9 ++++++---
backend/server/rhnSQL/driver_postgresql.py | 12 +++++++++++-
3 files changed, 20 insertions(+), 7 deletions(-)
New commits:
commit c75b9598e9830917bd7b332b89af86d0c13e1e9d
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Tue Jun 29 10:59:39 2010 +0200
We want to pull the backend type from the config file as well.
diff --git a/backend/server/rhnSQL/__init__.py b/backend/server/rhnSQL/__init__.py
index 661ec9f..12fe17f 100644
--- a/backend/server/rhnSQL/__init__.py
+++ b/backend/server/rhnSQL/__init__.py
@@ -67,7 +67,7 @@ def __init__DB(backend, host, port, username, password, database):
__DB.connect()
return 0
-def initDB(dsn=None, backend=ORACLE, host="localhost", port=None,
username=None,
+def initDB(dsn=None, backend=None, host="localhost", port=None, username=None,
password=None, database=None):
"""
Initialize the database.
@@ -76,6 +76,9 @@ def initDB(dsn=None, backend=ORACLE, host="localhost",
port=None, username=None,
password, and database. (sid in this case)
"""
+ if backend == None:
+ backend=CFG.DB_BACKEND
+
if not SUPPORTED_BACKENDS.has_key(backend):
raise rhnException("Unsupported database backend", backend)
commit 30903ca16fa55cab6994dbd97595eb549bd3f619
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Fri Jun 25 16:13:28 2010 +0200
Add initial support for anonymous PL/pgSQL blocks.
We invoke them via functions that get created on the fly.
Use it for _query_update_family_counts.
diff --git a/backend/satellite_tools/sync_handlers.py
b/backend/satellite_tools/sync_handlers.py
index aafb6af..5f55670 100644
--- a/backend/satellite_tools/sync_handlers.py
+++ b/backend/satellite_tools/sync_handlers.py
@@ -786,18 +786,18 @@ def purge_extra_channel_families():
_query_update_family_counts = rhnSQL.Statement("""
declare
- cursor ch_fam_cursor is
+ /*pg_cs*/ cursor ch_fam_cursor /*pg cursor*/ is
select cf.id channel_family_id, wc.id org_id
from rhnChannelFamily cf, web_customer wc;
begin
for row in ch_fam_cursor loop
- rhn_channel.update_family_counts(row.channel_family_id,
+ /*pg perform*/ rhn_channel.update_family_counts(row.channel_family_id,
row.org_id);
end loop;
end;
""")
def update_channel_family_counts():
- h = rhnSQL.prepare(_query_update_family_counts)
+ h = rhnSQL.prepare(_query_update_family_counts, params=())
h.execute()
rhnSQL.commit()
diff --git a/backend/server/rhnSQL/__init__.py b/backend/server/rhnSQL/__init__.py
index dea1bd3..661ec9f 100644
--- a/backend/server/rhnSQL/__init__.py
+++ b/backend/server/rhnSQL/__init__.py
@@ -180,11 +180,11 @@ def database():
def cursor():
db = __test_DB()
return db.cursor()
-def prepare(sql):
+def prepare(sql, params=None):
db = __test_DB()
if isinstance(sql, Statement):
sql = sql.statement
- return db.prepare(sql)
+ return db.prepare(sql, params=params)
def execute(sql, *args, **kwargs):
db = __test_DB()
return apply(db.execute, (sql, ) + args, kwargs)
diff --git a/backend/server/rhnSQL/driver_postgresql.py
b/backend/server/rhnSQL/driver_postgresql.py
index 038048c..73b113f 100644
--- a/backend/server/rhnSQL/driver_postgresql.py
+++ b/backend/server/rhnSQL/driver_postgresql.py
@@ -21,6 +21,7 @@
import sys
import re
import pgsql
+import hashlib
import sql_base
from server import rhnSQL
@@ -193,7 +194,16 @@ class Database(sql_base.Database):
"Exception information: %s" % sys.exc_info()[1])
self.connect() # only allow one try
- def prepare(self, sql, force=0):
+ def prepare(self, sql, force=0, params=None):
+ if params != None: # support for anonymour plpgsql
+ sql = re.sub(r'/\*pg_cs\*/\s*cursor', '', sql)
+ sql = re.sub(r'/\*pg (.+?)\*/', '\g<1>', sql)
+ s = hashlib.new('sha1')
+ s.update(sql)
+ sha1 = s.hexdigest()
+ c = self.prepare("create function rhn_asdf_%s (%s) returns void as
$%s$%s$%s$ language plpgsql" % ( sha1, ','.join(params), sha1, sql, sha1 ))
+ c.execute()
+ sql = "select rhn_asdf_%s()" % sha1
return Cursor(dbh=self.dbh, sql=sql, force=force)
def commit(self):