fix optimisation with super session that may lead to integrity loss
at some point I've decided to stop ensuring ?1 cardinality was respected
when adding a new relation using a super session, to avoid the cost of
the delete query. That was yet discussable because it introduced unexpected
difference between execute and unsafe_execute, which is imo not worth it.
Also, now that rql() in migration script default to unsafe_execute, we
definitly don't want that implicit behaviour change (which already cause
bug when for instance adding another default workflow for an entity type:
without that fix we end up with *two* default workflows while the schema
tells we can have only one.
IMO we should go to the direction that super session skip all security
check, but nothing else, unless explicitly asked.
/* -*- sql -*-
postgres specific registered procedures for the Bytes File System storage,
require the plpythonu language installed
*/
CREATE OR REPLACE FUNCTION _fsopen(bytea) RETURNS bytea AS $$
fpath = args[0]
if fpath:
try:
data = file(fpath, 'rb').read()
#/* XXX due to plpython bug we have to replace some characters... */
return data.replace("\\", r"\134").replace("\000", r"\000").replace("'", r"\047") #'
except Exception, ex:
plpy.warning('failed to get content for %s: %s', fpath, ex)
return None
$$ LANGUAGE plpythonu
/* WITH(ISCACHABLE) XXX does postgres handle caching of large data nicely */
;;
/* fspath(eid, entity type, attribute) */
CREATE OR REPLACE FUNCTION fspath(bigint, text, text) RETURNS bytea AS $$
pkey = 'plan%s%s' % (args[1], args[2])
try:
plan = SD[pkey]
except KeyError:
#/* then prepare and cache plan to get versioned file information from a
# version content eid */
plan = plpy.prepare(
'SELECT X.cw_%s FROM cw_%s as X WHERE X.cw_eid=$1' % (args[2], args[1]),
['bigint'])
SD[pkey] = plan
return plpy.execute(plan, [args[0]])[0]
$$ LANGUAGE plpythonu
/* WITH(ISCACHABLE) XXX does postgres handle caching of large data nicely */
;;