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)
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))
db_xml.define_table('test', Field('NAME', 'string'), Field('FILE', 'string'))
db_xml.test.insert(NAME='something', FILE='somthing')
db_xml.define_table('bin_files', Field('id','integer'), Field('PARENT'), Field('SRC_FILENAME'), Field('DATA', 'blob'), primarykey=['id','PARENT'], migrate=False )
img = db_app(db_app.doc_images.person=='{0} {1} {2}'.format(session.abit_f,session.abit_i,session.abit_o)).select(db_app.doc_images.file) filepath = os.path.join(request.folder,'uploads') for i in img: stream=open(filepath + '\\' + i.file, 'rb') s=base64.encodestring(stream.read()) db_xml.executesql("""INSERT INTO bin_files (PARENT,SRC_FILENAME,DATA) VALUES ({0},'{1}','{2}')""".format(entrant_id[0][0],i.file,s)) db_xml.commit()
db_xml.bin_files.insert(PARENT=entrant_id[0][0],SRC_FILENAME=i.file,DATA=stream.read())
db_xml.define_table('bin_files', Field('id','integer'), Field('PARENT'), Field('SRC_FILENAME'), Field('DATA', 'blob'), primarykey=['id','PARENT'], migrate=False )
load_img = db_xml.bin_files.insert(PARENT=entrant_id[0][0],SRC_FILENAME=i.file,DATA='something')
filepath = os.path.join(request.folder,'uploads')
img = db_app(db_app.doc_images.person=='{0} {1} {2}'.format(session.abit_f,session.abit_i,session.abit_o)).select()
for i in img:
stream=open(filepath + '\\' + i.file, 'rb')
load_img = db_xml.bin_files.insert(PARENT=entrant_id[0][0],SRC_FILENAME=i.file,DATA=stream.read())
from gluon import DAL,Fielddef testdb():uri = 'sqlite://storage.sqlite' # start of model codetry: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 codeimgstream = 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 scriptretrieved_img = db_xml(db_xml.bin_files.id==stored_img).select().first()assert retrieved_img.DATAblob == bin_data # the storage and retrieval workedif __name__ == "__main__":testdb()
stream=open(filepath + '\\' + i.file, 'rb')
stream.read()
INSERT INTO bin_files (PARENT, SRC_FILENAME, DATA) VALUES (33,'name.jpg','very very long base64 string').
Nico de Groot, thank you for example and attention! I already have crud form and that form work. It load files in folder 'uploads'. I want to save that files in database now. I sure that
stream=open(filepath + '\\' + i.file, 'rb')
andmade a long base64 string because I saw it on site. Then I decoded it and got picture.
stream.read()Also I tried to save that file as usual SQL request in Firebird and web2py interfaces, where field DATA conteined string in base64. Like that:After that Firebird has hanged. Web2py given an error message.
INSERT INTO bin_files (PARENT, SRC_FILENAME, DATA) VALUES (33,'name.jpg','very very long base64 string').Just in case, are there between names 'DATA' and 'DATAblob'?
Yesterday and today I can't test all again because it's day off.
--Raul Monares, thank you too! I cheked file that contain string in base64 and it's sise 440kb. It's more then size of file in the beginning (name.jpg - 322kb). What should I do in that case, after all blob field can store large files.
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/_MVVu9PF0xk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
(self=<fdb.fbcore.PreparedStatement object>, operation='SELECT gen_id(genid_test, 0) FROM rdb$database', cursor=<fdb.fbcore.Cursor object>, internal=True)
db_xml.define_table('test',
Field('id', 'integer'),
Field('XYZ'), Field('IOP'), primarykey=['id'], migrate=False
)
db_xml.define_table('bin_files',
Field('id','integer'), Field('PARENT'), Field('SRC_FILENAME'), Field('DATA', 'blob'), primarykey=['id','PARENT'], migrate=False)