[web2py] Re: retrieving blobs from legacy (oracle) database

2013-04-02 Thread Martin Barnard
I forgot to mention I have to use the MyDAL version as I have to connect to 
different oracle schemas. Not fun! For anybody in a similar situation, this 
was my solution

In the Model

odb=MyDAL(my_connection_string, migrate=False, fake_migrate_all=True)
odb.define_table('player_photo',[
Field('link_id', 'integer'),
Field('photo', type=SQLCustomType(type='string', native='blob')),
primarykey=['link_id'],
table_class=MyTable, # from MyDAL
migrate=True, fake_migrate=True, 
 )


 
*As I only have read-only access to the data, and I am under strict 
instructions to not load the oracle server, my strategy is to check local 
storage first, to see if we have a local copy of the image, which isn't too 
old, which means that I only hit the oracle db when I have either an old 
(2 months) image, or no image at all.*

*Controller:*

def player_image():
 import os, 
 from datetime import datetime
 rows=None
 img_url=None
 mem=int(request.args(0))
 if mem:
loc=os.path.join(request.folder, 'static','player_images', '%d.jpg' % mem) # 
dump spot for images
img_url='/our_app/static/player_images/%d.jpg' % mem
if os.path.exists(loc):
ct=os.path.getctime(loc)
if datetime.fromtimestamp(ct)  request.now - timedelta(days=60):
rows=odb(odb.player_photo.link_id==mem).select(limitby=(0,1))
if rows:
img=rows[0].photo.read()
f=open(loc,'wb')
f.write(img)
f.close()
  return dict(img_url=img_url)


*The View*

{{=IMG(_src=img_url, _width='90px')}}




I also had to slightly tweak the MyDAL oracle adapter class by importing 
SQLCustomType: 
changed *from gluon.dal import DAL, MySQLAdapter, OracleAdapter, 
PostgreSQLAdapter, Expression, Table, Field, Query* to *from gluon.dal 
import DAL, MySQLAdapter, OracleAdapter, PostgreSQLAdapter, Expression, 
Table, Field, SQLCustomType*

Thanks for the help, guys!

Martin

On Monday, April 1, 2013 2:26:23 AM UTC+3, Massimo Di Pierro wrote:

 This should do it:

 Field('photo',type=SQLCustomType(type ='string', native ='blob'))




 On Friday, 29 March 2013 21:26:32 UTC-5, Martin Barnard wrote:

 Hi, I have read-only access to a legacy oracle database which is storing 
 image files as blobs.

 I cannot modify the model to include a 'filename' field, or alter the 
 table in any way. How can I display returned images as a stream?

 I.e. model looks like this:
 odb.define_table('player_photo',
 Field('link_id','integer'),
 Field('photo','blob')
 )


 So, without a filename field, I cannot figure out how to stream the photo 
 to the server.

 Any suggestions would be greatly appreciated.

 Thanking you in advance.

 Martin



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: retrieving blobs from legacy (oracle) database

2013-03-31 Thread Massimo Di Pierro
This should do it:

Field('photo',type=SQLCustomType(type ='string', native ='blob'))




On Friday, 29 March 2013 21:26:32 UTC-5, Martin Barnard wrote:

 Hi, I have read-only access to a legacy oracle database which is storing 
 image files as blobs.

 I cannot modify the model to include a 'filename' field, or alter the 
 table in any way. How can I display returned images as a stream?

 I.e. model looks like this:
 odb.define_table('player_photo',
 Field('link_id','integer'),
 Field('photo','blob')
 )


 So, without a filename field, I cannot figure out how to stream the photo 
 to the server.

 Any suggestions would be greatly appreciated.

 Thanking you in advance.

 Martin


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.