sqlobject-discuss Mailing List for SQLObject (Page 22)
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
(2) |
Mar
(43) |
Apr
(204) |
May
(208) |
Jun
(102) |
Jul
(113) |
Aug
(63) |
Sep
(88) |
Oct
(85) |
Nov
(95) |
Dec
(62) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(38) |
Feb
(93) |
Mar
(125) |
Apr
(89) |
May
(66) |
Jun
(65) |
Jul
(53) |
Aug
(65) |
Sep
(79) |
Oct
(60) |
Nov
(171) |
Dec
(176) |
| 2005 |
Jan
(264) |
Feb
(260) |
Mar
(145) |
Apr
(153) |
May
(192) |
Jun
(166) |
Jul
(265) |
Aug
(340) |
Sep
(300) |
Oct
(469) |
Nov
(316) |
Dec
(235) |
| 2006 |
Jan
(236) |
Feb
(156) |
Mar
(229) |
Apr
(221) |
May
(257) |
Jun
(161) |
Jul
(97) |
Aug
(169) |
Sep
(159) |
Oct
(400) |
Nov
(136) |
Dec
(134) |
| 2007 |
Jan
(152) |
Feb
(101) |
Mar
(115) |
Apr
(120) |
May
(129) |
Jun
(82) |
Jul
(118) |
Aug
(82) |
Sep
(30) |
Oct
(101) |
Nov
(137) |
Dec
(53) |
| 2008 |
Jan
(83) |
Feb
(139) |
Mar
(55) |
Apr
(69) |
May
(82) |
Jun
(31) |
Jul
(66) |
Aug
(30) |
Sep
(21) |
Oct
(37) |
Nov
(41) |
Dec
(65) |
| 2009 |
Jan
(69) |
Feb
(46) |
Mar
(22) |
Apr
(20) |
May
(39) |
Jun
(30) |
Jul
(36) |
Aug
(58) |
Sep
(38) |
Oct
(20) |
Nov
(10) |
Dec
(11) |
| 2010 |
Jan
(24) |
Feb
(63) |
Mar
(22) |
Apr
(72) |
May
(8) |
Jun
(13) |
Jul
(35) |
Aug
(23) |
Sep
(12) |
Oct
(26) |
Nov
(11) |
Dec
(30) |
| 2011 |
Jan
(15) |
Feb
(44) |
Mar
(36) |
Apr
(26) |
May
(27) |
Jun
(10) |
Jul
(28) |
Aug
(12) |
Sep
|
Oct
|
Nov
(17) |
Dec
(16) |
| 2012 |
Jan
(12) |
Feb
(31) |
Mar
(23) |
Apr
(14) |
May
(10) |
Jun
(26) |
Jul
|
Aug
(2) |
Sep
(2) |
Oct
(1) |
Nov
|
Dec
(6) |
| 2013 |
Jan
(4) |
Feb
(5) |
Mar
|
Apr
(4) |
May
(13) |
Jun
(7) |
Jul
(5) |
Aug
(15) |
Sep
(25) |
Oct
(18) |
Nov
(7) |
Dec
(3) |
| 2014 |
Jan
(1) |
Feb
(5) |
Mar
|
Apr
(3) |
May
(3) |
Jun
(2) |
Jul
(4) |
Aug
(5) |
Sep
|
Oct
(11) |
Nov
|
Dec
(62) |
| 2015 |
Jan
(8) |
Feb
(3) |
Mar
(15) |
Apr
|
May
|
Jun
(6) |
Jul
|
Aug
(6) |
Sep
|
Oct
|
Nov
|
Dec
(19) |
| 2016 |
Jan
(2) |
Feb
|
Mar
(2) |
Apr
(4) |
May
(3) |
Jun
(7) |
Jul
(14) |
Aug
(13) |
Sep
(6) |
Oct
(2) |
Nov
(3) |
Dec
|
| 2017 |
Jan
(6) |
Feb
(14) |
Mar
(2) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
(4) |
Nov
(3) |
Dec
|
| 2018 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2019 |
Jan
|
Feb
(1) |
Mar
|
Apr
(44) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
(1) |
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
(1) |
| 2021 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
(3) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
(1) |
| 2023 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
(1) |
Nov
(2) |
Dec
|
| 2024 |
Jan
|
Feb
|
Mar
|
Apr
(4) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2025 |
Jan
|
Feb
(1) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(2) |
|
From: Daniel D. <dan...@ba...> - 2012-02-01 18:21:35
|
Oleg Broytman <ph...@ph...> writes:
> Aha, got it. You've stumbled upon a subtle bug in SQLiteConnection.
> SQLiteConnection uses a different (from its parent class DBAPI)
> implementation of .getConnection() and maintain its own pool -
> ._threadPool along with DBAPI._pool. But it doesn't clear the pool on
> .close().
>
> The quick-and-dirty solution for you is to clear the pool yourself:
>
> Rebuildd().sqlconnection.close()
> Rebuildd().sqlconnection._threadPool = {}
Thanks, this solve my issue.
> You preserve an old SQLiteConnection, so you don't need the
> following:
>
>> sqlobject.dbconnection.TheURIOpener.cachedURIs={}
Ok, I plan to change rebuildd code and avoid singletons, this will
permit to make each unit test in a separate context (and directory) to
avoid side effects.
At that time, I think I will be freed of all of this.
[...]
> And, BTW, this
>
>> os.unlink("/tmp/rebuildd-tests.db")
>
> is just
>
> Rebuildd().sqlconnection.dropDatabase()
Thanks a lot.
--
Daniel Dehennin
Récupérer ma clef GPG:
gpg --keyserver pgp.mit.edu --recv-keys 0x6A2540D1
|
|
From: Oleg B. <ph...@ph...> - 2012-02-01 15:50:11
|
On Wed, Feb 01, 2012 at 03:28:30PM +0100, Daniel Dehennin wrote:
> Rebuildd().sqlconnection.close()
Aha, got it. You've stumbled upon a subtle bug in SQLiteConnection.
SQLiteConnection uses a different (from its parent class DBAPI)
implementation of .getConnection() and maintain its own pool -
._threadPool along with DBAPI._pool. But it doesn't clear the pool on
.close().
The quick-and-dirty solution for you is to clear the pool yourself:
Rebuildd().sqlconnection.close()
Rebuildd().sqlconnection._threadPool = {}
I'll add a proper .close() to SQLiteConnection.
> sqlobject.sqlhub.processConnection = Rebuildd().sqlconnection
You preserve an old SQLiteConnection, so you don't need the
following:
> sqlobject.dbconnection.TheURIOpener.cachedURIs={}
The workaround is for the case when you want to create a new
SQLiteConnection like this:
Rebuildd().sqlconnection = connectionForURI(...)
And, BTW, this
> os.unlink("/tmp/rebuildd-tests.db")
is just
Rebuildd().sqlconnection.dropDatabase()
Oleg.
--
Oleg Broytman http://phdru.name/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|
|
From: Daniel D. <dan...@ba...> - 2012-02-01 14:28:42
|
Oleg Broytman <ph...@ph...> writes: > On Wed, Feb 01, 2012 at 02:53:20PM +0100, Daniel Dehennin wrote: >> I found a thread[4] on the list speaking about the same issue >> [4] http://thread.gmane.org/gmane.comp.python.sqlobject/5769 > > The thread has the answer, IMO. So, I should have not understand: #+begin_src test_init_job (TestJob.TestJob) ... E: setUp Cannot operate on a closed database. #+end_src I move the os.unlink fro the setUp() to tearDown() which call a new function: #+begin_src python def rebuildd_global_test_teardown(): try: Rebuildd().sqlconnection.close() sqlobject.sqlhub.processConnection = Rebuildd().sqlconnection sqlobject.dbconnection.TheURIOpener.cachedURIs={} os.unlink("/tmp/rebuildd-tests.db") except Exception, e: print "E: tearDown %s" % e pass #+end_src Regards. -- Daniel Dehennin Récupérer ma clef GPG: gpg --keyserver pgp.mit.edu --recv-keys 0x6A2540D1 |
|
From: Oleg B. <ph...@ph...> - 2012-02-01 14:15:00
|
On Wed, Feb 01, 2012 at 02:53:20PM +0100, Daniel Dehennin wrote: > I found a thread[4] on the list speaking about the same issue > [4] http://thread.gmane.org/gmane.comp.python.sqlobject/5769 The thread has the answer, IMO. > but I do not manage to fix my tests. What's up? Oleg. -- Oleg Broytman http://phdru.name/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
|
From: Daniel D. <dan...@ba...> - 2012-02-01 13:53:34
|
Hello, I'm looking at improving tests of rebuildd[1]. The test suite create and delete the database[2] for each test in the setUp()[3] method, but sqlobject don't like it. The first test is OK but all successives ones fail with "disk I/O error". I found a thread[4] on the list speaking about the same issue but I do not manage to fix my tests. Any hints? Regards. Footnotes: [1] http://packages.qa.debian.org/rebuildd [2] http://anonscm.debian.org/gitweb/?p=rebuildd/rebuildd.git;a=blob;f=tests/RebuilddTestSetup.py;h=d677d8e481baada9218d9f86687a818c87b28582;hb=HEAD [3] http://anonscm.debian.org/gitweb/?p=rebuildd/rebuildd.git;a=blob;f=tests/TestJob.py;h=20e81d6c3de9a50ddb4a95c04593d739f31dbec8;hb=HEAD#l16 [4] http://thread.gmane.org/gmane.comp.python.sqlobject/5769 -- Daniel Dehennin Récupérer ma clef GPG: gpg --keyserver pgp.mit.edu --recv-keys 0x6A2540D1 |
|
From: Oleg B. <ph...@ph...> - 2012-01-31 19:17:05
|
Hi!
On Tue, Jan 31, 2012 at 06:28:23PM +0100, Petr Jake?? wrote:
> With some luck I will check it this weekend (I can not promiss).
Eagerly waiting!
> It looks
> like it gives different results with different versions of Firebird.
> Actually I am trying to migrate TurboGears working application to an other
> machine. The Python, TurboGears, kinterbasdb, SQLObject are the same
> version. The only differences are version of Firebird and different Ubuntu
> version.
Good luck resolving this!
> I will check it. My feeling was it is not a problem to coerce str to int.
In 0.13.0 validators becomes event stricter:
* Validators became stricter: StringCol and UnicodeCol now accept only str,
unicode or an instance of a class that implements __unicode__ (but not
__str__ because every object has a __str__ method); BoolCol accepts only
bool or int or an instance of a class that implements __nonzero__; IntCol
accepts int, long or an instance of a class that implements __int__ or
__long__; FloatCol accepts float, int, long or an instance of a class
that implements __float__, __int__ or __long__.
But you can add a validator/converter to any column yourself:
from formencode.validators import Int
class MyTable(SQLobject):
column = IntCol(validator2=Int())
Oleg.
--
Oleg Broytman http://phdru.name/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|
|
From: Petr J. <pet...@tp...> - 2012-01-31 17:28:34
|
> That's ok. "fromDatabase" schema guessing in SQLObject is a bit > primitive. It works slightly better for The Big Three (MySQL, Postgres, > SQLite) but still far from ideal. > You have a chance to improve the machinery for Firebird - it is in > FirebirdConnection class, methods columnsFromSchema and guessClass. > With some luck I will check it this weekend (I can not promiss). It looks like it gives different results with different versions of Firebird. Actually I am trying to migrate TurboGears working application to an other machine. The Python, TurboGears, kinterbasdb, SQLObject are the same version. The only differences are version of Firebird and different Ubuntu version. > > > Before inserting/updating to the database it is necessary to check, if > the > > inserted value type is the same as declared in the table Class > definition > > That strange - it's the job of validators. > Yes, that is what I have found strange as well... > > > (it is not possible to send string in to the integer column for example). > > Strange. > > Well, that's that job - IntCol's validator doesn't allow strings but > allows any object that can be coerced to int. > > > Is there some way how to check/set/convert column type according to the > > Class definition? > > See the code in .set() that converts input values: > > for name, value in kw.items(): > from_python = getattr(self, '_SO_from_python_%s' % name, > None) > if from_python: > dbValue = from_python(value, self._SO_validatorState) > else: > dbValue = value > to_python = getattr(self, '_SO_to_python_%s' % name, None) > if to_python: > value = to_python(dbValue, self._SO_validatorState) > > I will check it. My feeling was it is not a problem to coerce str to int. OK, thanks a lot anyway. Petr |
|
From: Oleg B. <ph...@ph...> - 2012-01-30 09:33:53
|
On Mon, Jan 30, 2012 at 02:23:56AM +0100, Petr Jake?? wrote:
> It was necessary to define all the column names and column types manually
> in the table Class definition.
That's ok. "fromDatabase" schema guessing in SQLObject is a bit
primitive. It works slightly better for The Big Three (MySQL, Postgres,
SQLite) but still far from ideal.
You have a chance to improve the machinery for Firebird - it is in
FirebirdConnection class, methods columnsFromSchema and guessClass.
> Before inserting/updating to the database it is necessary to check, if the
> inserted value type is the same as declared in the table Class definition
That strange - it's the job of validators.
> (it is not possible to send string in to the integer column for example).
> Strange.
Well, that's that job - IntCol's validator doesn't allow strings but
allows any object that can be coerced to int.
> Is there some way how to check/set/convert column type according to the
> Class definition?
See the code in .set() that converts input values:
for name, value in kw.items():
from_python = getattr(self, '_SO_from_python_%s' % name, None)
if from_python:
dbValue = from_python(value, self._SO_validatorState)
else:
dbValue = value
to_python = getattr(self, '_SO_to_python_%s' % name, None)
if to_python:
value = to_python(dbValue, self._SO_validatorState)
Oleg.
--
Oleg Broytman http://phdru.name/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|
|
From: Petr J. <pet...@tp...> - 2012-01-30 01:24:03
|
Finally some small success... It was necessary to define all the column names and column types manually in the table Class definition. Before inserting/updating to the database it is necessary to check, if the inserted value type is the same as declared in the table Class definition (it is not possible to send string in to the integer column for example). Strange. Is there some way how to check/set/convert column type according to the Class definition? I know, it is crazy, it is bypassing of the SQLObject functionality.... But I did not find an other solution for the communication with the Firebird database. Regards Petr |
|
From: Petr J. <pet...@tp...> - 2012-01-30 00:20:24
|
> > ============= set method start ===============
> > <type 'str'> telKontaktniOsoby <type 'unicode'> +420734803579
> > <type 'str'> kontaktniOsobaPrijmeni <type 'unicode'> Zburn??k
> > <type 'str'> nazevKontaktMistaPoruchy <type 'unicode'> recepce
> >
> > ============ _SO_update start =====================
> > <type 'unicode'> tel_kontaktni_osoby <type 'unicode'> +420734803579
> > <type 'unicode'> kontaktni_osoba_prijmeni <type 'unicode'> Zburn??k
> > <type 'unicode'> nazev_kontakt_mista_poruchy <type 'unicode'> recepce
>
> You made all columns StringCol where I've advised you to make them
> all UnicodeCol.
>
>
Hmmm.... I am completely lost :(
I am testing the unicode type and replacing it with the utf-8 encoded
string before I am calling the .set() method:
for key, value in argumentsDict.items():
print type(key), key, type(value), value
if isinstance(value, unicode):
argumentsDict[key] = value.encode("utf-8")
It is throwing UnicodeDecodeError anyway.... Grrrr
============= set method start ===============
<type 'str'> telKontaktniOsoby value: <type 'str'> value repr:
'+420721870631'
<type 'str'> kontaktniOsobaPrijmeni value: <type 'str'> value repr:
'Kra\xc4\x8dmar'
<type 'str'> nazevKontaktMistaPoruchy value: <type 'str'> value repr:
'Vr\xc3\xa1tnice'
<type 'str'> psc value: <type 'str'> value repr: '46117'
<type 'str'> mesto value: <type 'str'> value repr: 'Liberec'
<type 'str'> geocodeAccuracy value: <type 'str'> value repr: 'Z'
<type 'str'> adresa2 value: <type 'str'> value repr: ''
<type 'str'> adresa1 value: <type 'str'> value repr: '17.listopadu 587/12'
<type 'str'> zemDelka value: <type 'str'> value repr: '15.089062'
<type 'str'> zemSirka value: <type 'str'> value repr: '50.770344'
<type 'str'> elektrinaZaRokBezDph value: <type 'str'> value repr: '2052'
<type 'str'> kontaktniOsobaJmeno value: <type 'str'> value repr:
'Zden\xc4\x9bk'
<type 'str'> cisloSignysPartnera value: <type 'str'> value repr: '8'
<type 'str'> telReseniPoruchy value: <type 'str'> value repr:
'+420485355217'
<type 'str'> nazevProdejnihoMista value: <type 'str'> value repr: 'Kolej
LBC E'
<type 'str'> dnuRokOtevreno value: <type 'str'> value repr: '340'
<type 'str'> najemZaRokBezDph value: <type 'str'> value repr: '6000'
============ _SO_update start =====================
<type 'unicode'> tel_kontaktni_osoby value: <type 'str'> value repr:
'+420721870631'
<type 'unicode'> kontaktni_osoba_prijmeni value: <type 'str'> value repr:
'Kra\xc4\x8dmar'
<type 'unicode'> nazev_kontakt_mista_poruchy value: <type 'str'> value
repr: 'Vr\xc3\xa1tnice'
<type 'unicode'> psc value: <type 'str'> value repr: '46117'
<type 'unicode'> mesto value: <type 'str'> value repr: 'Liberec'
<type 'unicode'> geocode_accuracy value: <type 'str'> value repr: 'Z'
<type 'unicode'> adresa2 value: <type 'str'> value repr: ''
<type 'unicode'> adresa1 value: <type 'str'> value repr: '17.listopadu
587/12'
<type 'unicode'> zem_delka value: <type 'str'> value repr: '15.089062'
<type 'unicode'> zem_sirka value: <type 'str'> value repr: '50.770344'
<type 'unicode'> elektrina_za_rok_bez_dph value: <type 'str'> value repr:
'2052'
<type 'unicode'> kontaktni_osoba_jmeno value: <type 'str'> value repr:
'Zden\xc4\x9bk'
<type 'unicode'> cislo_signys_partnera value: <type 'str'> value repr: '8'
<type 'unicode'> tel_reseni_poruchy value: <type 'str'> value repr:
'+420485355217'
<type 'unicode'> nazev_prodejniho_mista value: <type 'str'> value repr:
'Kolej LBC E'
<type 'unicode'> dnu_rok_otevreno value: <type 'str'> value repr: '340'
<type 'unicode'> najem_za_rok_bez_dph value: <type 'str'> value repr: '6000'
2012-01-30 01:13:08,807 cherrypy.msg INFO HTTP: Page handler: <bound method
ProdejniMista.ulozeniProdejnihoMista of <fantomas.controllers.ProdejniMista
instance at 0x23fd638>>
Traceback (most recent call last):
File
"/usr/lib/python2.5/site-packages/CherryPy-2.3.0-py2.5.egg/cherrypy/_cphttptools.py",
line 121, in _run
self.main()
File
"/usr/lib/python2.5/site-packages/CherryPy-2.3.0-py2.5.egg/cherrypy/_cphttptools.py",
line 264, in main
body = page_handler(*virtual_path, **self.params)
File "<string>", line 3, in ulozeniProdejnihoMista
File
"/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/controllers.py",
line 360, in expose
*args, **kw)
File "<string>", line 5, in run_with_transaction
File
"/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/database.py",
line 359, in so_rwt
retval = func(*args, **kw)
File "<string>", line 5, in _expose
File
"/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/controllers.py",
line 373, in <lambda>
mapping, fragment, args, kw)))
File
"/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/controllers.py",
line 410, in _execute_func
output = errorhandling.try_call(func, *args, **kw)
File
"/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/errorhandling.py",
line 77, in try_call
return func(self, *args, **kw)
File "/TG_web/fantomas/controllers.py", line 317, in
ulozeniProdejnihoMista
prodMisto.set(**slovnikArgumentu)
File
"/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/main.py",
line 1123, in set
self._connection._SO_update(self, args)
File
"/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/dbconnection.py",
line 509, in _SO_update
myQuery = "UPDATE %s SET %s WHERE %s = (%s)" % (so.sqlmeta.table, ",
".join(["%s = (%s)" % (dbName, self.sqlrepr(value)) for dbName, value in
values]), so.sqlmeta.idName, self.sqlrepr(so.id))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 4:
ordinal not in range(128)
Petr
|
|
From: Oleg B. <ph...@ph...> - 2012-01-29 22:36:17
|
On Sun, Jan 29, 2012 at 11:17:09PM +0100, Petr Jake?? wrote:
> File
> "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/dbconnection.py",
> line 329, in _executeRetry
> return cursor.execute(query)
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in
> position 101: ordinal not in range(128)
It seems Firebird DB API driver can't process unicode.
> ============= set method start ===============
> <type 'str'> telKontaktniOsoby <type 'unicode'> +420734803579
> <type 'str'> kontaktniOsobaPrijmeni <type 'unicode'> Zburn??k
> <type 'str'> nazevKontaktMistaPoruchy <type 'unicode'> recepce
>
> ============ _SO_update start =====================
> <type 'unicode'> tel_kontaktni_osoby <type 'unicode'> +420734803579
> <type 'unicode'> kontaktni_osoba_prijmeni <type 'unicode'> Zburn??k
> <type 'unicode'> nazev_kontakt_mista_poruchy <type 'unicode'> recepce
You made all columns StringCol where I've advised you to make them
all UnicodeCol.
Oleg.
--
Oleg Broytman http://phdru.name/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|
|
From: Petr J. <pet...@tp...> - 2012-01-29 22:17:16
|
I thing I am few steps farther but new problem arised:
File "/TG_web/fantomas/controllers.py", line 305, in
ulozeniProdejnihoMista
prodMisto.set(**slovnikArgumentu)
File
"/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/main.py",
line 1123, in set
self._connection._SO_update(self, args)
File
"/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/dbconnection.py",
line 512, in _SO_update
self.query(myQuery)
File
"/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/dbconnection.py",
line 683, in query
return self._dbConnection._query(self._connection, s)
File
"/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/dbconnection.py",
line 334, in _query
self._executeRetry(conn, conn.cursor(), s)
File
"/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/dbconnection.py",
line 329, in _executeRetry
return cursor.execute(query)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in
position 101: ordinal not in range(128)
============= set method start ===============
<type 'str'> telKontaktniOsoby <type 'unicode'> +420734803579
<type 'str'> kontaktniOsobaPrijmeni <type 'unicode'> Zburník
<type 'str'> nazevKontaktMistaPoruchy <type 'unicode'> recepce
<type 'str'> psc <type 'unicode'> 28835
<type 'str'> mesto <type 'unicode'> Nymburk
<type 'str'> geocodeAccuracy <type 'str'> Z
<type 'str'> adresa2 <type 'unicode'>
<type 'str'> adresa1 <type 'unicode'> Sportovní 1801
<type 'str'> zemDelka <type 'unicode'> 15.058984
<type 'str'> zemSirka <type 'unicode'> 50.178441
<type 'str'> elektrinaZaRokBezDph <type 'unicode'> 2356
<type 'str'> kontaktniOsobaJmeno <type 'unicode'> Tomáš
<type 'str'> cisloSignysPartnera <type 'unicode'> 34
<type 'str'> telReseniPoruchy <type 'unicode'> +420325517801
<type 'str'> nazevProdejnihoMista <type 'unicode'> SC Nymburk
<type 'str'> dnuRokOtevreno <type 'unicode'> 360
<type 'str'> najemZaRokBezDph <type 'unicode'> 10400
============ _SO_update start =====================
<type 'unicode'> tel_kontaktni_osoby <type 'unicode'> +420734803579
<type 'unicode'> kontaktni_osoba_prijmeni <type 'unicode'> Zburník
<type 'unicode'> nazev_kontakt_mista_poruchy <type 'unicode'> recepce
<type 'unicode'> psc <type 'unicode'> 28835
<type 'unicode'> mesto <type 'unicode'> Nymburk
<type 'unicode'> geocode_accuracy <type 'str'> Z
<type 'unicode'> adresa2 <type 'unicode'>
<type 'unicode'> adresa1 <type 'unicode'> Sportovní 1801
<type 'unicode'> zem_delka <type 'unicode'> 15.058984
<type 'unicode'> zem_sirka <type 'unicode'> 50.178441
<type 'unicode'> elektrina_za_rok_bez_dph <type 'unicode'> 2356
<type 'unicode'> kontaktni_osoba_jmeno <type 'unicode'> Tomáš
<type 'unicode'> cislo_signys_partnera <type 'unicode'> 34
<type 'unicode'> tel_reseni_poruchy <type 'unicode'> +420325517801
<type 'unicode'> nazev_prodejniho_mista <type 'unicode'> SC Nymburk
<type 'unicode'> dnu_rok_otevreno <type 'unicode'> 360
<type 'unicode'> najem_za_rok_bez_dph <type 'unicode'> 10400
print myQuery:
UPDATE prodejni_mista SET tel_kontaktni_osoby = ('+420734803579'),
kontaktni_osoba_prijmeni = ('Zburník'), nazev_kontakt_mista_poruchy =
('recepce'), psc = ('28835'), mesto = ('Nymburk'), geocode_accuracy =
('Z'), adresa2 = (''), adresa1 = ('Sportovní 1801'), zem_delka =
('15.058984'), zem_sirka = ('50.178441'), elektrina_za_rok_bez_dph =
('2356'), kontaktni_osoba_jmeno = ('Tomáš'), cislo_signys_partnera =
('34'), tel_reseni_poruchy = ('+420325517801'), nazev_prodejniho_mista =
('SC Nymburk'), dnu_rok_otevreno = ('360'), najem_za_rok_bez_dph =
('10400') WHERE id = (19)
print repr(myQuerry)
u"UPDATE prodejni_mista SET tel_kontaktni_osoby = ('+420734803579'),
kontaktni_osoba_prijmeni = ('Zburn\xedk'), nazev_kontakt_mista_poruchy =
('recepce'), psc = ('28835'), mesto = ('Nymburk'), geocode_accuracy =
('Z'), adresa2 = (''), adresa1 = ('Sportovn\xed 1801'), zem_delka =
('15.058984'), zem_sirka = ('50.178441'), elektrina_za_rok_bez_dph =
('2356'), kontaktni_osoba_jmeno = ('Tom\xe1\u0161'), cislo_signys_partnera
= ('34'), tel_reseni_poruchy = ('+420325517801'), nazev_prodejniho_mista =
('SC Nymburk'), dnu_rok_otevreno = ('360'), najem_za_rok_bez_dph =
('10400') WHERE id = (19)"
Can you send me your suggestions please?
Thanks
Petr
|
|
From: Petr J. <pet...@tp...> - 2012-01-29 21:29:22
|
>
>
> .set() converts fields to backend format using validators attached to
> the fields. UnicodeColumns are encoded to strings, but StringColumns are
> not, so when you've assigned a unicode object to a StringCol
> ._SO_update() received that unicode object which is wrong -
> ._SO_update() has to receive str. Do not assign unicode to StringCol.
>
>
Hmm... I am not getting it.
I am on the Firebird.
The database Default character set = UTF8
ALL text fields in in the table are varchar.
Why the SQLObject things some columns are UnicodeColumns and some columns
are StringColumns?
Bingo... it looks like "Mea Culpa":
Because of my laziness I am using fromDatabase = True.
But now, when I have inspected the table definitions, I have found I am
(accidentally) mixing two things together in one of the class/tables
definition (see the code bellow).
I will investigate this.
Thanks a lot.
Petr
class ProdejniMista(SQLObject):
class sqlmeta:
fromDatabase = True # -> nacte vse z databaze bez potreby
definice
# columnList = True
provozovatelMista = ForeignKey('ProvozovatelMista')
automaty = RelatedJoin('Automaty')
produkty = RelatedJoin('Produkty')
nazevProdejnihoMista = UnicodeCol(dbEncoding = "utf-8")
kontaktniOsobaJmeno = UnicodeCol(dbEncoding = "utf-8")
kontaktniOsobaPrijmeni = UnicodeCol(dbEncoding = "utf-8")
mesto = UnicodeCol(dbEncoding = "utf-8")
adresa1 = UnicodeCol(dbEncoding = "utf-8")
adresa2 = UnicodeCol(dbEncoding = "utf-8")
psc = UnicodeCol(dbEncoding = "utf-8")
zemDelka = UnicodeCol(dbEncoding = "utf-8")
zemSirka = UnicodeCol(dbEncoding = "utf-8")
telReseniPoruchy = UnicodeCol(dbEncoding = "utf-8")
telKontaktniOsoby = UnicodeCol(dbEncoding = "utf-8")
telKontaktniOsoby = UnicodeCol(dbEncoding = "utf-8")
automaty = RelatedJoin('Automaty')
|
|
From: Oleg B. <ph...@ph...> - 2012-01-29 21:05:12
|
On Sun, Jan 29, 2012 at 09:50:01PM +0100, Petr Jake?? wrote:
> ============= set method start ===============
> <type 'str'> telKontaktniOsoby <type 'unicode'> +420721870631
> <type 'str'> kontaktniOsobaPrijmeni <type 'unicode'> Kra??mar
> <type 'str'> nazevKontaktMistaPoruchy <type 'unicode'> Vr??tnice
[snip]
> ============ _SO_update start =====================
> <type 'str'> tel_kontaktni_osoby <type 'str'> +420721870631
> <type 'str'> kontaktni_osoba_prijmeni <type 'str'> Kra??mar
> <type 'unicode'> nazev_kontakt_mista_poruchy <type 'unicode'> Vr??tnice
[snip]
.set() converts fields to backend format using validators attached to
the fields. UnicodeColumns are encoded to strings, but StringColumns are
not, so when you've assigned a unicode object to a StringCol
._SO_update() received that unicode object which is wrong -
._SO_update() has to receive str. Do not assign unicode to StringCol.
Oleg.
--
Oleg Broytman http://phdru.name/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|
|
From: Petr J. <pet...@tp...> - 2012-01-29 20:50:08
|
> The error means there is at least one 8-bit str mixed with unicode. > If you are sure all values are str instances - what about dbNames? > _SO_update is called from set with dbNames from sqlmeta.columns: > > args = [(self.sqlmeta.columns[name].dbName, value) > for name, value in toUpdate.items()] > self._connection._SO_update(self, args) > > Make sure all dbNames are also str, not unicode. > It looks the type of some fields is changed somewhere during the code execution. When the set method is called, types of all fields are OK. When the SQLObject calls SO_update start, some of the fields and values types are changed (see the printout below). Any hints? Petr ============= set method start =============== <type 'str'> telKontaktniOsoby <type 'unicode'> +420721870631 <type 'str'> kontaktniOsobaPrijmeni <type 'unicode'> Kračmar <type 'str'> nazevKontaktMistaPoruchy <type 'unicode'> Vrátnice <type 'str'> psc <type 'unicode'> 46117 <type 'str'> mesto <type 'unicode'> Liberec <type 'str'> geocodeAccuracy <type 'str'> Z <type 'str'> adresa2 <type 'unicode'> <type 'str'> adresa1 <type 'unicode'> 17.listopadu 587/4 <type 'str'> zemDelka <type 'unicode'> 15.085940 <type 'str'> zemSirka <type 'unicode'> 50.770829 <type 'str'> elektrinaZaRokBezDph <type 'unicode'> 2052 <type 'str'> kontaktniOsobaJmeno <type 'unicode'> Zdeněk <type 'str'> cisloSignysPartnera <type 'unicode'> 8 <type 'str'> telReseniPoruchy <type 'unicode'> +420485355214 <type 'str'> nazevProdejnihoMista <type 'unicode'> Kolej LBC B <type 'str'> dnuRokOtevreno <type 'unicode'> 340 <type 'str'> najemZaRokBezDph <type 'unicode'> 5040 ============ _SO_update start ===================== <type 'str'> tel_kontaktni_osoby <type 'str'> +420721870631 <type 'str'> kontaktni_osoba_prijmeni <type 'str'> Kračmar <type 'unicode'> nazev_kontakt_mista_poruchy <type 'unicode'> Vrátnice <type 'str'> psc <type 'str'> 46117 <type 'str'> mesto <type 'str'> Liberec <type 'unicode'> geocode_accuracy <type 'str'> Z <type 'str'> adresa2 <type 'str'> <type 'str'> adresa1 <type 'str'> 17.listopadu 587/4 <type 'str'> zem_delka <type 'str'> 15.085940 <type 'str'> zem_sirka <type 'str'> 50.770829 <type 'unicode'> elektrina_za_rok_bez_dph <type 'unicode'> 2052 <type 'str'> kontaktni_osoba_jmeno <type 'str'> Zdeněk <type 'unicode'> cislo_signys_partnera <type 'unicode'> 8 <type 'str'> tel_reseni_poruchy <type 'str'> +420485355214 <type 'str'> nazev_prodejniho_mista <type 'str'> Kolej LBC B <type 'unicode'> dnu_rok_otevreno <type 'unicode'> 340 <type 'unicode'> najem_za_rok_bez_dph <type 'unicode'> 5040 |
|
From: Oleg B. <ph...@ph...> - 2012-01-29 19:29:15
|
Hello!
On Sun, Jan 29, 2012 at 11:06:31AM +0100, Petr Jake?? wrote:
> File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/main.py",
> line 1120, in set
> self._connection._SO_update(self, args)
> File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/dbconnection.py",
> line 509, in _SO_update
> for dbName, value in values]),
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
> 33: ordinal not in range(128)
The error means there is at least one 8-bit str mixed with unicode.
If you are sure all values are str instances - what about dbNames?
_SO_update is called from set with dbNames from sqlmeta.columns:
args = [(self.sqlmeta.columns[name].dbName, value)
for name, value in toUpdate.items()]
self._connection._SO_update(self, args)
Make sure all dbNames are also str, not unicode.
Oleg.
--
Oleg Broytman http://phdru.name/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|
|
From: Petr J. <pet...@tp...> - 2012-01-29 10:06:39
|
I am lost,
trying to find solution whole night long.
all attempts to call the set method (see bellow) are finishing:
Page handler: <bound method ProdejniMista.ulozeniProdejnihoMista of
<fantomas.controllers.ProdejniMista instance at 0x2ac67a0>>
Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/CherryPy-2.3.0-py2.5.egg/cherrypy/_cphttptools.py",
line 121, in _run
self.main()
File "/usr/lib/python2.5/site-packages/CherryPy-2.3.0-py2.5.egg/cherrypy/_cphttptools.py",
line 264, in main
body = page_handler(*virtual_path, **self.params)
File "<string>", line 3, in ulozeniProdejnihoMista
File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/controllers.py",
line 360, in expose
*args, **kw)
File "<string>", line 5, in run_with_transaction
File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/database.py",
line 359, in so_rwt
retval = func(*args, **kw)
File "<string>", line 5, in _expose
File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/controllers.py",
line 373, in <lambda>
mapping, fragment, args, kw)))
File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/controllers.py",
line 410, in _execute_func
output = errorhandling.try_call(func, *args, **kw)
File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/errorhandling.py",
line 77, in try_call
return func(self, *args, **kw)
File "/TG_web/fantomas/controllers.py", line 305, in ulozeniProdejnihoMista
prodMisto.set(**slovnikArgumentu)
File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/main.py",
line 1120, in set
self._connection._SO_update(self, args)
File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/dbconnection.py",
line 509, in _SO_update
for dbName, value in values]),
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
33: ordinal not in range(128)
I have tried all possible combination to decode/encode the field values and
I am really sure all filelds are unicode fields when i am trying call the
set method.
automat.set(**slovnikArgumentu)
automat.set(telKontaktniOsoby =
slovnikArgumentu[telKontaktniOsoby].encode("utf-8"),
najemZaRokBezDph =
slovnikArgumentu[najemZaRokBezDph].encode("utf-8"),
kontaktniOsobaPrijmeni =
slovnikArgumentu[kontaktniOsobaPrijmeni].encode("utf-8"),
nazevKontaktMistaPoruchy =
slovnikArgumentu[nazevKontaktMistaPoruchy].encode("utf-8"),
psc = slovnikArgumentu[psc].encode("utf-8"),
mesto = slovnikArgumentu[mesto].encode("utf-8"),
adresa2 = slovnikArgumentu[adresa2].encode("utf-8"),
adresa1 = slovnikArgumentu[adresa1].encode("utf-8"),
zemDelka = slovnikArgumentu[zemDelka].encode("utf-8"),
zemSirka = slovnikArgumentu[zemSirka].encode("utf-8"),
elektrinaZaRokBezDph =
slovnikArgumentu[elektrinaZaRokBezDph].encode("utf-8"),
cisloSignysPartnera =
slovnikArgumentu[cisloSignysPartnera].encode("utf-8"),
pmid = slovnikArgumentu[pmid].encode("utf-8"),
telReseniPoruchy =
slovnikArgumentu[telReseniPoruchy].encode("utf-8"),
nazevProdejnihoMista =
slovnikArgumentu[nazevProdejnihoMista].encode("utf-8"),
dnuRokOtevreno =
slovnikArgumentu[dnuRokOtevreno].encode("utf-8"),
kontaktniOsobaJmeno =
slovnikArgumentu[kontaktniOsobaJmeno].encode("utf-8"))
My Environment:
Ubuntu Hardy Heron 64bit minimal server install
vs2521:/TG_web# yolk -l
Cheetah - 2.4.4 - active
CherryPy - 2.3.0 - active
DecoratorTools - 1.8 - active
Extremes - 1.1.1 - active
FormEncode - 1.2.4 - active
Markdown - 2.1.1 - active
PIL - 1.1.6 - active
Paste - 1.7.5.1 - active
PasteDeploy - 1.5.0 - active
PasteScript - 1.7.5 - active
PyProtocols - 1.0a0dev-r2302 - active
Python - 2.5.2 - active development
(/usr/lib/python2.5/lib-dynload)
RuleDispatch - 0.5a1.dev-r2506 - active
SQLObject - 0.10.1 - active
TurboCheetah - 1.0 - active
TurboGears - 1.0.10 - non-active
TurboGears - 1.0.8 - active development
(/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg)
TurboJson - 1.1.4 - active
TurboKid - 1.0.5 - active
configobj - 4.7.2 - active
egenix-mx-base - 3.2.2 - active
kid - 0.9.6 - active
kinterbasdb - 3.3.0 - active
pip - 1.0.2 - active
pygooglechart - 0.3.0 - active
setuptools - 0.6c11 - non-active
setuptools - 0.6c12dev-r88846 - active
setuptools - 0.6c8 - non-active
simplejson - 2.3.2 - active
wsgiref - 0.1.2 - active development (/usr/lib/python2.5)
yolk - 0.4.1 - active
Thanks for your hints
Petr
|
|
From: Oleg B. <ph...@ph...> - 2011-12-30 12:26:38
|
Well, her I am, sorry for the late answer.
On Wed, Dec 28, 2011 at 10:30:28PM +0100, Timo wrote:
> class DVD(SQLObject):
> status = ???? # Should be sold or onloan data
> # ... special "dvd" data
>
> class Sold(SQLObject):
> dvd = ForeignKey('DVD')
> # ... special "sold" data
>
> class OnLoan(SQLObject):
> dvd = ForeignKey('DVD')
> # ... special "on loan" data
1. If you insist on having a separate table for an every status you
stuck with a setup that ain't supported by SQL. You can emulate joins
using SQLObject but you have to understand once you move operations to
the client side you will always have to do all processing on the client
side. In that case I recommend to add 2 columns and a calculated
attribute:
class DVD(SQLObject):
status_string = StringCol()
status_id = KeyCol() # No, not ForeignKey
# Attribute '.status_row'
def _get_status_row(self):
if self.status_string == 'on loan':
return OnLoan.get(self.status_id)
elif self.status_string == 'sold':
return Sold.get(self.status_id)
...etc...
To simplify the code you can create and use a static dict:
_status_dict = {
'on loan': OnLoan,
'sold': Sold,
}
def _get_status_row(self):
return self._status_dict[self.status_string].get(self.status_id)
2. If you want to use the power of SQL you have to combine all statuses
in one table. For example, make it wide:
class Status(SQLObject):
dvd = ForeignKey('DVD')
# Attributes for status 'on load'
...
# Attributes for status 'sold'
...
class DVD(SQLObject):
status = ForeignKey('DVD')
Here you can do SQL-wise joins and filter them on the server side.
Oleg.
--
Oleg Broytman http://phdru.name/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|
|
From: Timo <tim...@gm...> - 2011-12-30 10:37:52
|
2011/12/29 Oleg Broytman <ph...@ph...> > On Thu, Dec 29, 2011 at 03:48:09PM +0100, Frank Wagner wrote: > > http://sqlobject.org/Inheritance.html > Thanks Frank for pointing that out. I usually go directly to the documentation page on the website, so I overlooked this. > > Please be warned this kind of inheritance in SQLObject is very > limited. The page mentioned above lists some limitations. > > Timo, I'm going to write a more detailed answer a bit later. > That would be great! I'm eager to learn more about SQLObject and create a decent database model for my application. Greets, Timo > > Oleg. > -- > Oleg Broytman http://phdru.name/ ph...@ph... > Programmers don't die, they just GOSUB without RETURN. > > > ------------------------------------------------------------------------------ > Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex > infrastructure or vast IT resources to deliver seamless, secure access to > virtual desktops. With this all-in-one solution, easily deploy virtual > desktops for less than the cost of PCs and save 60% on VDI infrastructure > costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox > _______________________________________________ > sqlobject-discuss mailing list > sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss > |
|
From: Oleg B. <ph...@ph...> - 2011-12-29 18:35:28
|
On Thu, Dec 29, 2011 at 03:48:09PM +0100, Frank Wagner wrote: > http://sqlobject.org/Inheritance.html Please be warned this kind of inheritance in SQLObject is very limited. The page mentioned above lists some limitations. Timo, I'm going to write a more detailed answer a bit later. Oleg. -- Oleg Broytman http://phdru.name/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
|
From: Frank W. <fra...@no...> - 2011-12-29 15:01:51
|
Hi, i think the way to do this is described in: http://sqlobject.org/Inheritance.html class Status(InheritableSQLObject): # ... general status info class Sold(Status): #... sold-specific info class OnLoan(Status): #... onloan-specific info class DVD(SQLObject): status = ForeignKey("Status") # ... special "dvd" data does this help? Regards, Frank On Thu, Dec 29, 2011 at 15:25, Timo <tim...@gm...> wrote: > > 2011/12/29 Petr Jakeš <pet...@tp...> >> >> >>> But your example got me thinking. Is something like the following valid? >>> (working example) >>> from sqlobject import * >>> >> If it is working, then it is (IMHO) valid :D >> The DB structure is completely up to you of course. But think twice about >> the DB model. When the production data is in the database already, it is a >> pain to change the DB structure. > > Hehe, that was what I meant with "valid". I wrote this application about 2 > years ago (without SQLObject), and has become a great mess. So I'm trying to > start over and do /the right thing/. > >> >> >>> >>> >>> >>> But then I should handle the inShelve bool value whenever self.sold or >>> self.onLoan are changed. >> >> >> To keep the logic in the database is up to you. Of course you can >> automatize it some way (directly in the DB, using DB machinery - computed >> columns in the Firebird for example, which is IMHO not the best way to go >> but it works) >> >> Or maybe you can try something using: > > I think I'm going for the _set_status() and _get_status() approach. Write > some code which gets and sets the correct table in these methods, so I can > set/get the status in the program without hassle. > > Thanks for your help, > Timo > >> >> >> def _set_soldCarefully(self, value): >> self.sold = True >> self.onLoan = False >> self.inShelve = False >> >> Regards >> >> Petr >> >> >> >> >> > > > ------------------------------------------------------------------------------ > Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex > infrastructure or vast IT resources to deliver seamless, secure access to > virtual desktops. With this all-in-one solution, easily deploy virtual > desktops for less than the cost of PCs and save 60% on VDI infrastructure > costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox > _______________________________________________ > sqlobject-discuss mailing list > sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss > |
|
From: Timo <tim...@gm...> - 2011-12-29 14:25:14
|
2011/12/29 Petr Jakeš <pet...@tp...> > > But your example got me thinking. Is something like the following valid? >> (working example) >> from sqlobject import * >> >> If it is working, then it is (IMHO) valid :D > The DB structure is completely up to you of course. But think twice about > the DB model. When the production data is in the database already, it is a > pain to change the DB structure. > Hehe, that was what I meant with "valid". I wrote this application about 2 years ago (without SQLObject), and has become a great mess. So I'm trying to start over and do /the right thing/. > > >> >> >> But then I should handle the inShelve bool value whenever self.sold or >> self.onLoan are changed. >> > > To keep the logic in the database is up to you. Of course you can > automatize it some way (directly in the DB, using DB machinery - computed > columns in the Firebird for example, which is IMHO not the best way to go > but it works) > > Or maybe you can try something using: > I think I'm going for the _set_status() and _get_status() approach. Write some code which gets and sets the correct table in these methods, so I can set/get the status in the program without hassle. Thanks for your help, Timo > > def _set_soldCarefully(self, value): > self.sold = True > self.onLoan = False > self.inShelve = False > > Regards > > Petr > > > > > |
|
From: Petr J. <pet...@tp...> - 2011-12-29 05:05:33
|
> But your example got me thinking. Is something like the following valid?
> (working example)
> from sqlobject import *
>
> If it is working, then it is (IMHO) valid :D
The DB structure is completely up to you of course. But think twice about
the DB model. When the production data is in the database already, it is a
pain to change the DB structure.
>
>
> But then I should handle the inShelve bool value whenever self.sold or
> self.onLoan are changed.
>
To keep the logic in the database is up to you. Of course you can
automatize it some way (directly in the DB, using DB machinery - computed
columns in the Firebird for example, which is IMHO not the best way to go
but it works)
Or maybe you can try something using:
def _set_soldCarefully(self, value):
self.sold = True
self.onLoan = False
self.inShelve = False
Regards
Petr
|
|
From: Timo <tim...@gm...> - 2011-12-28 23:26:06
|
Sorry, forwarding to list. Overlooked the reply-all button in Gmail
interface.
2011/12/28 Petr Jakeš <pet...@tp...>
>
> I'm stuck at a part of my program, but I'm not sure if this is the right
>> place to ask. Excuses if it's not.
>>
>> I have a DVD object which can have different statusses, like "on loan",
>> "sold", etc... A dvd can only have 1 status at the time, but I'm confused
>> about how to link it to 1 table only so I can access the correct status
>> with dvd.status .
>>
>> Here's an example:
>>
>> class DVD(SQLObject):
>> status = ???? # Should be sold or onloan data
>> # ... special "dvd" data
>>
>> class Sold(SQLObject):
>> dvd = ForeignKey('DVD')
>> # ... special "sold" data
>>
>> class OnLoan(SQLObject):
>> dvd = ForeignKey('DVD')
>> # ... special "on loan" data
>>
>> Why not just one table and the sqlmeta<http://sqlobject.org/SQLObject.html#using-sqlmeta?>?
>
>
> connection = connectionForURI('sqlite:/:memory:')
>
> class DVD(SQLObject):
> _connection = connection
> title = StringCol(default="")
> inShelve = BoolCol(default=True)
> sold = BoolCol(default=False)
> onLoan = BoolCol(default=False)
> def _get_statuss(self):
> if self.sold:
> return "sold"
> elif self.onLoan:
> return "onLoan"
> elif self.inShelf:
> return "inShelf"
> DVD.createTable()
> myFirstDVD = DVD(title="Timo")
> print myFirstDVD.statuss
>
>
The statusses have all kind of information too, like price and buyer for
sold dvd's and return date for example in the loaned status.
But your example got me thinking. Is something like the following valid?
(working example)
from sqlobject import *
connection = connectionForURI('sqlite:/:memory:')
class Sold(SQLObject):
_connection = connection
dvd = ForeignKey('DVD')
buyer = StringCol(default="")
class OnLoan(SQLObject):
_connection = connection
dvd = ForeignKey('DVD')
returnDate = DateCol(default=None)
class DVD(SQLObject):
_connection = connection
title = StringCol(default="")
inShelve = BoolCol(default=True)
sold = SingleJoin('Sold', joinColumn='dvd')
onLoan = SingleJoin('OnLoan', joinColumn='dvd')
def _get_statuss(self):
if self.inShelf:
return
elif self.sold is not None:
return self.sold
elif self.onLoan is not None:
return self.onLoan
DVD.createTable()
Sold.createTable()
OnLoan.createTable()
myFirstDVD = DVD(title="Timo")
s = Sold(dvd=myFirstDVD)
print myFirstDVD.statuss
But then I should handle the inShelve bool value whenever self.sold or
self.onLoan are changed.
Greets and thanks,
Timo
> HTH
>
> Petr
>
|
|
From: Petr J. <pet...@tp...> - 2011-12-28 22:34:30
|
> I'm stuck at a part of my program, but I'm not sure if this is the right
> place to ask. Excuses if it's not.
>
> I have a DVD object which can have different statusses, like "on loan",
> "sold", etc... A dvd can only have 1 status at the time, but I'm confused
> about how to link it to 1 table only so I can access the correct status
> with dvd.status .
>
> Here's an example:
>
> class DVD(SQLObject):
> status = ???? # Should be sold or onloan data
> # ... special "dvd" data
>
> class Sold(SQLObject):
> dvd = ForeignKey('DVD')
> # ... special "sold" data
>
> class OnLoan(SQLObject):
> dvd = ForeignKey('DVD')
> # ... special "on loan" data
>
> Why not just one table and the sqlmeta<http://sqlobject.org/SQLObject.html#using-sqlmeta?>?
connection = connectionForURI('sqlite:/:memory:')
class DVD(SQLObject):
_connection = connection
title = StringCol(default="")
inShelve = BoolCol(default=True)
sold = BoolCol(default=False)
onLoan = BoolCol(default=False)
def _get_statuss(self):
if self.sold:
return "sold"
elif self.onLoan:
return "onLoan"
elif self.inShelf:
return "inShelf"
DVD.createTable()
myFirstDVD = DVD(title="Timo")
print myFirstDVD.statuss
HTH
Petr
|