19.1.11. camcops_server.cc_modules.cc_convert¶
Copyright (C) 2012-2018 Rudolf Cardinal (rudolf@pobox.com).
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 <http://www.gnu.org/licenses/>.
-
camcops_server.cc_modules.cc_convert.
br_html
(text: str) → str[source]¶ Filter that esscapes 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:
int 35
,-12
float 7.23
str 'hello, here''s an apostrophe'
(starts and ends with a quote)NULL NULL
(case-insensitive)BLOB X'4D7953514C'
(hex-encoded; matches MySQL method; http://dev.mysql.com/doc/refman/5.0/en/hexadecimal-literals.html)BLOB 64'TXlTUUw='
(base-64-encoded; this notation is my invention)But
- we use ISO-8601 text for dates/times
The client-side counterpart to this function is SQLite’s QUOTE() function (see getRecordByPK_lowmem() in lib/dbsqlite.js), except in the case of BLOBs (when it’s getEncodedBlob() in table/Blob.js); see lib/dbupload.js.
-
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 (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.
The client-side counterpart to this function is decode_single_sql_literal() in lib/conversion.js.
-
camcops_server.cc_modules.cc_convert.
get_tsv_header_from_dict
(d: Dict) → str[source]¶ Returns a TSV header line from a dictionary.
-
camcops_server.cc_modules.cc_convert.
get_tsv_line_from_dict
(d: Dict) → str[source]¶ Returns a TSV data line from a dictionary.