select method

11 views
Skip to first unread message

GuoGuo

unread,
Oct 30, 2009, 2:22:24 AM10/30/09
to buzhug
in sql, i can select records like this,
'select * from table limit 100'
how to write it in buzhug?

Pierre Quentel

unread,
Nov 2, 2009, 6:52:02 AM11/2/09
to buzhug
Hi,
There is no built-in argument like 'limit' in buzhug, but you can get
the same result with :

records = []
for i,rec in enumerate(db):
records.append(rec)
if i>99:
break

郭明哲

unread,
Nov 4, 2009, 8:50:52 PM11/4/09
to buz...@googlegroups.com
Hello,
     i have put a script on device,which based on arm9.A busy box system.i used buzhug TS_Base and made it to storing message.
And everyday,some time i send the message to a server,5000 messages at a time,and when i delete them from database a error happen.the code is:

          db.open()
           record = []
           for i,rec in enumerate(db):
              record.append(rec)
               if i > 5000:
                    break
          db.close()
          if len(record) > 0:
                thread.start_new_thread(sendHisData,(record,))

    def sendHisData(self,record):
        try:
            db.open()
            sock = SockClient(host,port)
            sock.connect()
            for r in record:
                sock_cmd = '@'.join([r.DeviceId,r.Monitor,r.Value,r.isAlarm ,'2',str(r.time)])
                sock.send(sock_cmd)
            delete(record)
            commit()
            cleanup()
            db.close()
            sock.close()
        except Exception,e:
            errlog.debug(traceback.format_exc())

the error message is :

[2009-11-05 09:34:14,611] DEBUG : Traceback (most recent call last):
  File "/mnt/mmc/energy/start.py", line 89, in sendHisData
    self.main.db.cleanup()
  File "e:\soft\python\buzhug\buzhug.py", line 664, in cleanup
IOError: [Errno 28] No space left on device

i don't know to solution.will u help me?

GuoGuo

unread,
Nov 5, 2009, 2:42:34 AM11/5/09
to buzhug
i find that the cleanup method make this error
my db has stored great many messages, when i use cleanup the error was
happened.

is there some usefull solution?

Pierre Quentel

unread,
Nov 5, 2009, 3:59:38 PM11/5/09
to buzhug
Hi,
The error message prints a statement self.main.db.cleanup() that I
don't find in your code extract

Could you copy and paste your original code ?

- Pierre

GuoGuo

unread,
Nov 6, 2009, 2:10:35 AM11/6/09
to buzhug
def sendHisData(self,record):
try:
self.main.db.open()
sock = SockClient
(self.main.config.host,self.main.config.port)
sock.connect()
for r in record:
sock_cmd = '@'.join
([r.DeviceId,r.Monitor,r.Value,r.isAlarm ,'2',str(r.time)])
sock.send(sock_cmd)
self.main.db.delete(record)
self.main.db.commit()
self.main.db.cleanup()
self.main.db.close()
sock.close()
except Exception,e:
errlog.debug(traceback.format_exc())
finally:
self.main.setFlag()

self.main.db.open()
record = []
for i,rec in enumerate(self.main.db):
record.append(rec)
if i > 5000:
break
self.main.db.close()
if len(record) > 0:
thread.start_new_thread(self.sendHisData,
(record,))

first i select from the database,put results into the record,and
second i start a thread of function sendHisData,also put the record
into it.
then i got that error.

i have made annother test.i telnet on the busybox system(arm9),and
start python
on the prompt,i input
>>> from buzhug import Base
>>> db = Base('data.db')
>>> db.open()
>>> db.cleanup()
then it also tell me the error 'IOError: [Errno 28] No space left on
device'

my busybox system device is little device that has less memory,
so i guess maybe the method of cleanup will loading the whole database
files into the memory.
that will making the error.

so i am puzzled.
any advice?

Pierre Quentel

unread,
Nov 6, 2009, 3:48:27 AM11/6/09
to buzhug
Hi,
> > - Pierre- Masquer le texte des messages précédents -
>
> - Afficher le texte des messages précédents -

Thanks for the explanation. The cleanup() method uses temporary files,
one for each field, and fills them with the records that are not
marked as deleted in the database. Then it replaces the database files
by the temporary files. The disk space needed by cleanup() is almost
the same as the one used by the database itself

Can you check how much space your database takes on the device, and
how much space is free ? If the values are roughly the same, this
explains the problem you have

I'm afraid I don't see any obvious solution to this problem. buzhug is
optimized for speed of requests, especially selections, and this
requires disk space (which is rarely a problem on PCs)

- Pierre

郭明哲

unread,
Nov 6, 2009, 4:11:19 AM11/6/09
to buz...@googlegroups.com
Hi,
  thank u, i have checked,that is the problem.maybe i have to think the better solution.

2009/11/6 Pierre Quentel <quentel...@wanadoo.fr>
Reply all
Reply to author
Forward
0 new messages