15.2.103. camcops_server.cc_modules.cc_convert


Copyright (C) 2012, University of Cambridge, Department of Psychiatry. Created by Rudolf Cardinal (rnc1001@cam.ac.uk).

This file is part of CamCOPS.

CamCOPS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CamCOPS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.

Miscellaneous conversion functions.

camcops_server.cc_modules.cc_convert.br_html(text: str) str[source]

Filter that escapes text safely whilst also converting n to <br>.

camcops_server.cc_modules.cc_convert.decode_single_value(v: str) Any[source]

Takes a string representing an SQL value. Returns the value. Value types/examples:


35, -12




'hello, here''s an apostrophe' (starts and ends with a quote)


NULL (case-insensitive)


X'4D7953514C' (hex-encoded; matches MySQL method; https://dev.mysql.com/doc/refman/5.0/en/hexadecimal-literals.html)


64'TXlTUUw=' (base-64-encoded; this notation is my invention)


  • we use ISO-8601 text for dates/times

In the C++ client, the client-side counterpart to this function is toSqlLiteral() in lib/convert.cpp.

camcops_server.cc_modules.cc_convert.decode_values(valuelist: str) List[Any][source]

Takes a SQL CSV value list and returns the corresponding list of decoded values.

camcops_server.cc_modules.cc_convert.encode_single_value(v: Any, is_blob=False) str[source]

Encodes a value for incorporation into an SQL CSV value string.

Note that this also escapes newlines. That is not necessary when receiving data from tablets, because those data arrive in CGI forms, but necessary for the return journey to the tablet/webclient, because those data get sent in a one-record-one-line format.

In the C++ client, the client-side counterpart to this function is fromSqlLiteral() in lib/convert.cpp.