How do I get the equivalent SQLAlchemy statement for this SQL query?
select CONVERT(blobby USING utf8) as blobby from myTable where CONVERT(blobby USING utf8)="Hello";
Where blobby is a blob type field that has to be unblobbed to a string.
I tried this
DBSession.query(myTable).filter(myTable.blobby.encode(utf-8)="Hello").first()
But doesn't work. Gives out a queer error
AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with myTable.blobby has an attribute 'encode'
Moreover, I tried inserting into the database as follows:
que=myTable(blobby=str(x.blobby))
DBSession.add(que)
This also returns an error that says
(ProgrammingError) You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.
This error goes away if I insert like
que=myTable(blobby=str(x))
But the inserted entries look like ('hello',),('hi',) and so on..
EDIT:-
This is what I am trying to do :
I have a list of utf-8 strings. The sqlalchemy column which I am
trying to insert my string has the property "convert_unicode" set to
true. Now, I have to insert these strings into my database without
loss of data. I need to preserve my multilingual characters which
worked fine when I fetched them as utf-8 from my Mysql database.
Trouble here is inserting them into SQLite using SQLalchemy.
Please help. Thanks and Regards.
Aucun commentaire:
Enregistrer un commentaire