[Zope-DB] Problem selecting Oracle LOB's
Matthew T. Kromer
matt@zope.com
Tue, 19 Mar 2002 10:30:14 -0500
Jorge O. Martinez wrote:
> (I am resubmitting this question because I had initially sent it with
> the wrong subject, and figured people would think it's the same
> subject. Sorry about that).
>
> Hi:
>
> I have been able to install Zope, DCOracle2, and was able to make a
> connection to the DB, and execute simple queries displaying results
> just fine.
>
> However, I have not been able to get LOB's to work. I am following the
> examples from Peterb in:
>
> http://www.zope.org/Members/peterb/oracle_lobs
>
> I am trying to do a select blob, and I get the template to display the
> id (which is the argument I pass), but don't get anything for the
> knowledge_text (the LOB, which is only text), this is what I am getting:
>
> KNOWLEDGE ID KNOWLEDGE TEXT
> 44
I bet if you view source, you'll see the tag <LobLocator ...> as the 2nd
argument, which the browser is hiding because it thinks its a tag.
>
> SQL used:
> SELECT
> knowledge_id, knowledge_text
> FROM
> knowledge
> where
> knowledge_id = 44
>
>
> I know it must be my error because I think I am not calling the
> "select" Python script correctly; I've tried several different ways,
> and get all kinds of errors. Anybody outthere knows what is the
> correct way to call it from the Z SQL Method? This is what I have in
> my Z SQL Method:
>
> ------------
>
> SELECT
> knowledge_id, knowledge_text
> FROM
> knowledge
> <dtml-sqlgroup where>
> <dtml-sqltest knowledge_id op=eq type=int optional>
> </dtml-sqlgroup>
Because you test something named knowledge_id, you have to pass it in as
a parameter... see below
>
> <dtml-in select>
> <dtml-var sequence-item>
> </dtml-in>
>
> ** I am including 1 of the ways how I tried to call the 'select'
> script but it does not work**
>
> ------------
>
> And this is the code in the select Python script (same from the sample
> code). I've tried many different ways, this is just the latest:
>
> # Manually iterate over whole result set, copy into list of dicts just
> # like dictionaries()
> # except we also read all BLOBs in their entirety and put in the
> value, # not the LobLocator
>
> result = []
> for row in container.sql_select_blob(id=id):
> lob = row['blob']
> result.append({'id': row['id'], 'blob': lob.read()})
> return result
You want
for row in container.sql_select_block(knowledge_id=id)
... presuming ID is the value you want to search for. It has to match
the definition of the SQL method.
Otherwise what you're doing is correct.
Note that the latest DCOracle2 is "most correct" in CVS; I can't
remember if there was a broken-ness to the LOB support in PR1.
>
> ** Note, I've tried this way, and also replacing the 'id=id' for
> 'id=knowledge_id', but it did not work, also I replaced the 'blob' for
> 'knowledge_text' (my blob), but it doesn't like it **
>
> I am new to Python and Zope, hence this basic question. I am sure it
> must be something simple, so thanks for your patience,
>
> Regards,
>
> Jorge M.
>
>
--
Matt Kromer
Zope Corporation http://www.zope.com/