<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to 127: working with schemas</title><link>https://sourceforge.net/p/sqlobject/bugs/127/</link><description>Recent changes to 127: working with schemas</description><atom:link href="https://sourceforge.net/p/sqlobject/bugs/127/feed.rss" rel="self"/><language>en</language><lastBuildDate>Wed, 02 Nov 2005 15:17:26 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/sqlobject/bugs/127/feed.rss" rel="self" type="application/rss+xml"/><item><title>working with schemas</title><link>https://sourceforge.net/p/sqlobject/bugs/127/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;We use heavily schemas within a database (using&lt;br /&gt;
PostgreSQL), and SQLObject has trouble identifying the&lt;br /&gt;
primary with a table that lives in a schema, or a table&lt;br /&gt;
in the default schema that has the same name than a&lt;br /&gt;
table in other schema.&lt;/p&gt;
&lt;p&gt;In pgconnection.py I patched the following code and&lt;br /&gt;
everything worked afterwards, but now I have to specify&lt;br /&gt;
the schema name even for the tables in the default one:&lt;/p&gt;
&lt;p&gt;primaryKeyQuery = """&lt;br /&gt;
SELECT pg_index.indisprimary,&lt;br /&gt;
pg_catalog.pg_get_indexdef(pg_index.indexrelid)&lt;br /&gt;
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2,&lt;br /&gt;
pg_catalog.pg_index AS pg_index&lt;br /&gt;
WHERE c.relname = %s&lt;br /&gt;
AND c.oid = pg_index.indrelid&lt;br /&gt;
AND pg_index.indexrelid = c2.oid&lt;br /&gt;
AND pg_index.indisprimary&lt;br /&gt;
AND pg_namespace.oid=c.relnamespace&lt;br /&gt;
AND %s=pg_namespace.nspname&lt;br /&gt;
"""&lt;/p&gt;
&lt;p&gt;keyData = self.queryAll(keyQuery %&lt;br /&gt;
self.sqlrepr(tableName))&lt;br /&gt;
keyRE = re.compile(r"\((.+)\) REFERENCES (.+)\(")&lt;br /&gt;
keymap = {}&lt;/p&gt;
&lt;p&gt;for (condef,) in keyData:&lt;br /&gt;
match = keyRE.search(condef)&lt;br /&gt;
if match:&lt;br /&gt;
field, reftable = match.groups()&lt;br /&gt;
keymap[field] = reftable.capitalize()&lt;br /&gt;
sqlrepr = self.sqlrepr(tableName)&lt;br /&gt;
table = "'"+sqlrepr[sqlrepr.find('.')+1:]&lt;br /&gt;
schema = sqlrepr[0:sqlrepr.find('.')]+"'"&lt;br /&gt;
primaryData = self.queryAll(primaryKeyQuery %&lt;br /&gt;
(table, schema))&lt;/p&gt;
&lt;p&gt;The code above parses the schema and the table name&lt;br /&gt;
from a sqlrepr as "public.user" and uses the schema for&lt;br /&gt;
a new where clause in the select query&lt;br /&gt;
("%s=pg_namespace.nspname") joining with the internal&lt;br /&gt;
table that maps oids with schema names&lt;br /&gt;
("pg_namespace.oid=c.relnamespace").&lt;/p&gt;
&lt;p&gt;I don't have a lot of experience with Python yet,&lt;br /&gt;
otherwise I would have sumbitted a patch.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Felipe Hoffa</dc:creator><pubDate>Wed, 02 Nov 2005 15:17:26 -0000</pubDate><guid>https://sourceforge.netb3c87c14f86913f87f932caef3dd9becf19a558b</guid></item></channel></rss>