pike.git
/
lib
/
modules
/
Sql.pmod
/
mysql.pike
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/lib/modules/Sql.pmod/mysql.pike:398:
//! //! @param s //! String to quote. string quote(string s) { return replace(s, ({ "\\", "\"", "\0", "\'", "\n", "\r" }), ({ "\\\\", "\\\"", "\\0", "\\\'", "\\n", "\\r" })); }
-
string latin1_to_utf8 (string s)
+
string latin1_to_utf8 (string s
, int extended
)
//! Converts a string in MySQL @expr{latin1@} format to UTF-8. { return string_to_utf8 (replace (s, ([ "\x80": "\u20AC", /*"\x81": "\u0081",*/ "\x82": "\u201A", "\x83": "\u0192", "\x84": "\u201E", "\x85": "\u2026", "\x86": "\u2020", "\x87": "\u2021", "\x88": "\u02C6", "\x89": "\u2030", "\x8a": "\u0160", "\x8b": "\u2039", "\x8c": "\u0152", /*"\x8d": "\u008D",*/ "\x8e": "\u017D", /*"\x8f": "\u008F",*/ /*"\x90": "\u0090",*/ "\x91": "\u2018", "\x92": "\u2019", "\x93": "\u201C", "\x94": "\u201D", "\x95": "\u2022", "\x96": "\u2013", "\x97": "\u2014", "\x98": "\u02DC", "\x99": "\u2122", "\x9a": "\u0161", "\x9b": "\u203A", "\x9c": "\u0153", /*"\x9d": "\u009D",*/ "\x9e": "\u017E", "\x9f": "\u0178",
-
])));
+
]))
, extended
);
}
-
string utf8_encode_query (string q, function(string:string) encode_fn)
+
string utf8_encode_query (string q,
+
function(string
, mixed|void...
:string) encode_fn
,
+
mixed ... extras
)
//! Encodes the appropriate sections of the query with @[encode_fn]. //! Everything except strings prefixed by an introducer (i.e. //! @expr{_something@} or @expr{N@}) is encoded. { // We need to find the segments that shouldn't be encoded. string e = ""; while (1) { sscanf(q, "%[^\'\"]%s", string prefix, string suffix);
-
e += encode_fn (prefix);
+
e += encode_fn (prefix
, @extras
);
if (suffix == "") break; string quote = suffix[..0]; int start = 1; int end; while ((end = search(suffix, quote, start)) >= 0) { if (suffix[end-1] == '\\') { // Count the number of preceding back-slashes. // if odd, continue searching after the quote.
pike.git/lib/modules/Sql.pmod/mysql.pike:518:
else encoding = "utf8"; // Gotta be "N". s = s[1..<1]; if (sizeof (s) > 40) s = sprintf ("%O...", s[..37]); else s = sprintf ("%O", s); predef::error ("A string in the query should be %s encoded " "but it is wide: %s\n", encoding, s); } e += s; } else {
-
e += encode_fn (suffix[..end]);
+
e += encode_fn (suffix[..end]
, @extras
);
} q = suffix[end+1..]; } return e; } // The following time conversion functions assumes the SQL server // handles time in this local timezone. They map the special zero // time/date spec to 0.
pike.git/lib/modules/Sql.pmod/mysql.pike:664:
} \ \ else if (send_charset) { \ string new_send_charset = send_charset; \ \ if (utf8_mode & LATIN1_UNICODE_ENCODE_MODE) { \ if (String.width (query) == 8) \ new_send_charset = "latin1"; \ else { \ CH_DEBUG ("Converting (mysql-)latin1 query to utf8.\n"); \
-
query = utf8_encode_query (query, latin1_to_utf8);
\
+
query = utf8_encode_query (query, latin1_to_utf8
, 2
); \
new_send_charset = "utf8"; \ } \ } \ \ else { /* utf8_mode & UTF8_UNICODE_ENCODE_MODE */ \ /* NB: The send_charset may only be upgraded from \ * "latin1" to "utf8", not the other way around. \ * This is to avoid extraneous charset changes \ * where the charset is changed from query to query. \ */ \ if ((send_charset == "utf8") || !_can_send_as_latin1(query)) { \ CH_DEBUG ("Converting query to utf8.\n"); \
-
query = utf8_encode_query (query, string_to_utf8);
\
+
query = utf8_encode_query (query, string_to_utf8
, 2
); \
new_send_charset = "utf8"; \ } \ } \ \ if (new_send_charset != send_charset) { \ CH_DEBUG ("Switching charset from %O to %O.\n", \ send_charset, new_send_charset); \ if (mixed err = catch { \ ::big_query ("SET character_set_client=" + new_send_charset); \ /* Can't be changed automatically - has side effects. /mast */ \