diff options
author | Marko Kreen | 2011-12-22 11:00:14 +0000 |
---|---|---|
committer | Marko Kreen | 2011-12-22 11:00:14 +0000 |
commit | 9f937c7a3e212a0dcced0dd473a3969491405580 (patch) | |
tree | 68527f22bb1b1e9ee1a5123bc91f24f42cf448a4 /python/skytools/dbservice.py | |
parent | 865c520e2a86f9e9dafbdc759feffefcf0889f07 (diff) |
dbservice.make_record: convert list to pgarray
This makes the behaviour compatible with 8.3 plpython,
with did not know arrays and returned text strings.
More general solution would be to use urlenc arrays (same key repeats),
except that not general enough - there is no transparent way
to encode lists with 0 and 1 elements. So caller must always
be aware whether a key is list or not. Thus no advantages
over this pgarray solution and disadvantaga is incompatibility.
Diffstat (limited to 'python/skytools/dbservice.py')
-rwxr-xr-x | python/skytools/dbservice.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/python/skytools/dbservice.py b/python/skytools/dbservice.py index 931d514e..ee06a872 100755 --- a/python/skytools/dbservice.py +++ b/python/skytools/dbservice.py @@ -103,17 +103,28 @@ def get_record_lists(tbl, field): dict.setdefault( id, [] ).append(rec) return dict +def _make_record_convert(row): + """Converts complex values.""" + d = row.copy() + for k, v in d.items(): + if isinstance(v, list): + d[k] = skytools.make_pgarray(v) + return skytools.db_urlencode(d) + def make_record(row): """ Takes record as dict and returns it as urlencoded string. Used to send data out of db service layer.or to fake incoming calls """ + for v in row.values(): + if isinstance(v, list): + return _make_record_convert(row) return skytools.db_urlencode(row) def make_record_array(rowlist): """ Takes list of records got from plpy execute and turns it into postgers aray string. Used to send data out of db service layer. """ - return '{' + ','.join( map(skytools.db_urlencode, rowlist) ) + '}' + return '{' + ','.join( map(make_record, rowlist) ) + '}' def get_result_items(list, name): """ Get return values from result |