From fa18de081dc7476b4d87f9160a0eada966ad9478 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 7 Jan 2009 07:30:48 +0000 Subject: [PATCH] add testcode to show UTF problem. See email for details bzr-revno: 278 --- testdb/danish.sqlite | Bin 0 -> 16384 bytes testdbcode.py | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 testdb/danish.sqlite create mode 100644 testdbcode.py diff --git a/testdb/danish.sqlite b/testdb/danish.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..646e37d820c865e50e76e78c7bc3d8f8651b88e7 GIT binary patch literal 16384 zcmeI3K~Eb;6o7ZU27?nfL{Vj-i1Z;2u^S5o2vw_IYN$m}z)<6)a4A~Y@p|j^uCueY z%F$G6Z>^Lck$=#iQ>ho{)HJt5QG4i{on3nuW0Xq}GP4*w``(**?|n04J?}1i-))&5 zg_`3wH4j#lq(X@D4S=F3x9~T5%-~5PA|R3Wh0O`n67^qh^ND!7&|E4d0ZHIe2;4|! z&<|1nQt%}YNk9@9GXnR>gmVA(d~p%>-s;q4p8K|0TpYB;{(rBi@5d~0nT{kN35+H% zK~#c=*#9pS^~GpYsgVREfy*NBDp_$1pqmCjCY?!tfMF)xwy_cbonl7(tGNQKVb(l~Qt(Vv&1cdZmf32dk!E?I zp~B-=2*6>`>Oluv9r|M-lSbFnW<0E#OPiX`4Y0!CW1x1Ut@|N2G+TrnhKl3!pY0%U z-!8}kyIqtd_S|XuL18!;mrGdzoW8{9aliErMxwW&uDM`29gLlJOv8gC%DkTYweKN> zH!8OCIM&*h?m=4*(?C~@S{?2m^X^a^C&s40&>7`!P>w`7l195$LnJ&X!=lY5f<>{9 zko9!LqnjQ$u8#OEzXKm(aV!X$V3~Xh2D3VtX}w(lhLkvtj$oo$7DaT8SFU9m1)S;T zE5qZhHea470~gOSY2<^baZp^3eDODX(9kTM_x0)~SB#q3tGnv>4!*1pnZ6(Hk*I$w z_>zYtAPI~yfji0jgv71{5F+;f8%2FH#)-?+Bmqf)6PQWP6Ee8^7w-Reiuz6hk_04y zYeHZud7GC4;`$%n^p}SuAPHPU0{r^F-2c~b;$_N`021K)KS^FIJBddJg_EULA=y5q9oEwNrH6{{tv7T2~)5C|bB8m11Lf=611i z08dH>c!Ay@!q%D;o)s(WkBgPuqlbAY?^L1ubZe^sH4~pXIrI%WntP1*WVk^AEbSa| z{)a>=yRbmIsvjS7Y$J#x(o|z{Mij%b^4klxF^E0iT~$-rY?hpE_8l;8!jeOSGRVa{ z#}nr|&-AQ8-e1J>woY90n8DiC&RT@VvC~4iQTI%{=JbgzudX5yMm-c8Y!Gh0V}3vB z&s#TT;$4uR1e2uz&14YzX8GIFelQ_R;MixU(4T|i-g-gwLpOMm_wP8!`hSc!y-ZCK z7)?Od|D)MRjU+Jc1TyM>%9QellK4FFbK+06s=g$@5J16IKFph`>}PYNyWp2Yyc9cf zoW^q4n2A+Hp>&zoMB#}j?s%`mR{O{@SskB0;l)vCa2V7_`VHY~Hs)$6G`n@KE5G~- zO(L%PC0M8ny>#c(sqEYwIsLR>m-5&`v&>L+%C(V!F<8^~C_WVfyRO;P+!J_0Pk2I5 zd|KVvEaL#%rE*mi#D3btC3)yALL^eM=f9s2HRwd723-zn&{PbA5c<3WJ>&-U{!j_J zKRI07t^^&Y&KYF_-Q&8#~Edgk6gf>`RcStMD^MGZkI&RH)DW= shVv2HFs1&&^Tpw+!!4ea_5W4=pp&sl0w0%v-2We!uN++xxXJ|n2S8&+L;wH) literal 0 HcmV?d00001 diff --git a/testdbcode.py b/testdbcode.py new file mode 100644 index 000000000..b90ccb8db --- /dev/null +++ b/testdbcode.py @@ -0,0 +1,58 @@ +""" + + encoding='utf-8' - the encoding to use for all Unicode translations, both by engine-wide unicode conversion as well as the Unicode type object. +[Tue Jan 6 2009] [21:06:02] convert_unicode=False - if set to True, all String/character based types will convert Unicode values to raw byte values going into the database, and all raw byte values to Python Unicode coming out in result sets. This is an engine-wide method to provide unicode conversion across the board. For unicode conversion on a column-by-column level, use the Unicode column type instead, described in The +[Tue Jan 6 2009] [21:06:09] Types System. +[Tue Jan 6 2009] [21:06:14] assert_unicode=False - When set to True alongside convert_unicode=True, asserts that incoming string bind parameters are instances of unicode, otherwise raises an error. Only takes effect when convert_unicode==True. This flag is also available on the String type and its descendants. New in 0.4.2. +[Tue Jan 6 2009] [21:06:46] So, try "encoding='latin1'", then 'iso-8859-1', then 'iso-8859-15' +[Tue Jan 6 2009] [21:06:56] If none of those work, fiddle with the other unicode settings. +[Tue Jan 6 2009] [21:08:36] Tried the other settings but will try the encoding ones thanks. +""" + +from sqlalchemy import * +from sqlalchemy.sql import select +from sqlalchemy.orm import sessionmaker, mapper +from sqlalchemy.types import Text, Unicode +import sqlite3 + +from openlp.plugins.songs.lib.songtable import Author + +metadata = MetaData() + +author_table = Table('authors', metadata, + Column('authorid', Integer, primary_key=True), + Column('authorname', Unicode(length=40)), + Column('first_name', Unicode(length=40)), + Column('last_name',Unicode(length=40)), +) + +#mapper(Author,author_table) +class test0(): + def __init__(self): + self.conn = sqlite3.connect("testdb/danish.sqlite") + self.conn.text_factory = str + + def test1(self): + c = self.conn.cursor() + text = c.execute("""select * from authors""") .fetchall() + print text + +class test1(): + def __init__(self): + self.db = create_engine("sqlite:///testdb/danish.sqlite", encoding='latin1' , convert_unicode=False, assert_unicode=False) + self.db.echo = True + self.db.convert_unicode=False + metadata.bind = self.db + metadata.bind.echo = True + self.Session = sessionmaker(autoflush=True, autocommit=False) + self.Session.configure(bind=self.db) + + def test1(self): + session = self.Session() + print session.query(Author).order_by(Author.authorname).all() + +if __name__ == '__main__': + app = test0() + app.test1() + app = test1() + app.test1()