<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
I'll totally agree about the automatic encoding bit.&nbsp; The design
problem is that while I _never_ do any collation or sorting of strings
in the database (eg. no ORDER BY employee_title), it however is handy
to do from time to time when you're debugging and testing from the sql
command line.<br>
<br>
[don't over generalize the examples, they're for example purposes]<br>
<br>
Thus, one is faced with this dilema -- use VARBINARY for all of your
columns which give you RawStr and make the python code simple:<br>
&nbsp;&nbsp;&nbsp; find(..., employee_title == 'CEO') <br>
which is a bit more natural than saying employee_title is unicode thus:<br>
&nbsp;&nbsp;&nbsp; find(..., employee_title == u'CEO')<br>
<br>
Now python says:<br>
&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; print u'CEO' == 'CEO'<br>
&nbsp;&nbsp;&nbsp; True<br>
<br>
While the UnicodeVariable() requires type == unicode, which doesn't
allow for the natural promotion of str to unicode.<br>
<br>
--koblas<br>
<br>
Christopher Armstrong wrote:
<blockquote
 cite="mid:60ed19d40806130156h7a920c01n9cfe28058e98ee8d@mail.gmail.com"
 type="cite">
  <blockquote type="cite">
    <pre wrap="">David Koblas <a class="moz-txt-link-rfc2396E" href="mailto:koblas@...">&lt;koblas@...&gt;</a> writes:
    </pre>
    <blockquote type="cite">
      <pre wrap="">I'm finding it a bit tidious to constantly be casting from str(...) to
unicode(...) to keep the database happy.  Is there really a best
practice for how to have VARCHAR columns that are should be treated as
RawStr() for purposes of development?
      </pre>
    </blockquote>
  </blockquote>
  <pre wrap=""><!---->
There is a best practice: It's to never rely on automatic encoding or
decoding of str and unicode objects. On all I/O boundaries (web input
/ output, email input / output, file I/O, etc), you need to explicitly
encode and decode with the appropriate encoding (utf-8, ascii, utf-16,
etc) for the given transport.

If you do end up using automatic encoding and decoding, then your app
will most likely break some time when a user comes along and decides
to enter characters that don't fit in ASCII.

  </pre>
</blockquote>
</body>
</html>