Minimal example using web2py DAL as a script. I'm not using firebird but
your example with the string shows that the storage in a blob is working in
firebird (Note that a python string is saved as binary data in a blob). In
a webapp, move code to model file and to a controller, or use a form to
upload an image, see
https://stackoverflow.com/questions/34999878/upload-image-in-web2py-to-database-from-default-controller-following-image-blog
from gluon import DAL,Field
def testdb():
uri = 'sqlite://storage.sqlite' # start of model code
try:
db_xml = DAL(uri,
folder='test',
check_reserved=['all'],
migrate=True,
fake_migrate=False,
migrate_enabled=True,
fake_migrate_all=False)
except Exception as e:
print "database {} could not be opened. {}".format(uri, e)
db_xml.define_table('bin_files',
Field('DATAblob', 'blob'),
migrate=True
)
# controller code
imgstream = open(u'/users/ncdegroot/pictures/pasfotos/photo.jpg', 'rb')
bin_data = imgstream.read()
stored_img = db_xml.bin_files.insert(DATAblob=bin_data)
db_xml.commit() # needed in a script
retrieved_img = db_xml(db_xml.bin_files.id==stored_img).select().first()
assert retrieved_img.DATAblob == bin_data # the storage and retrieval
worked
if __name__ == "__main__":
testdb()
Nico
On Friday, April 27, 2018 at 12:27:48 PM UTC+2, Константин Комков wrote:
>
> Hello! I'm trying add data in my table.
> tables.py
> db_xml.define_table('xml_files',
> Field('F'),
> Field('I'),
> Field('O'),
> Field('IS_IMPORTED'),
> Field('XML_FILE'),
> format='%(id)s %(F)s %(I)s %(O)s %(IS_IMPORTED)s %(XML_FILE)s',
> migrate=False)
> default.py
>
> db_xml.xml_files.insert(F='Castle', I='Rick' O='Middlename' IS_IMPORTED='0'
> XML_FILE='<mytag>something</mytag>')
>
> DatabaseError: ('Error while preparing SQL statement:\n- SQLCODE: -104\n-
> invalid request BLR at offset 51\n- generator GENID_XML_FILES is not
> defined', -104, 335544343)
>
> <class 'fdb.fbcore.DatabaseError'>(('Error while preparing SQL statement:\n-
> SQLCODE: -104\n- invalid request BLR at offset 51\n- generator
> GENID_XML_FILES is not defined', -104, 335544343))
>
>
> <https://lh3.googleusercontent.com/-RrHcXMOa-rw/WuL6wcaGruI/AAAAAAAAAIQ/sN64uARvcY4yw6EqTsLmxedtz0InheHtwCLcBGAs/s1600/Er.png>
>
>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
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 [email protected].
For more options, visit https://groups.google.com/d/optout.