×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    18

    More database querys!

    Hi all,
    Another question about databases, I've a programme which recives a value that is a wieght via bluetooth and stores it in a database, the scales are my own creation and send the wieght in kgs, at the moment in this format "000.0" ie 1kg would be "001.0" this is stored in my dmbs database as a varchar string. Previous to this I had been entering the wieght manualy into the phone using the 'number' format, this was stored as a varchar in the database but obviously only to 1kg resolution.
    When I acess the database's I can sort the manualy entered numbers but not ones recived via bluetooth? The programme throws a strop and closes, is my problem the 0's infront the number or the '.' ? I can remove the dot but would then need to change the recived string into a interger and /10 to get the correct value. Can anyone shed any light on this?
    Ps, the bluetooth numbers can be viewed if you look at the whole database but not if you try to sort them!
    Thanks Geoff

  2. #2
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    200

    Re: More database querys!

    So you have custom database? You are not giving too much information to work with. I would check some basics such as character encoding and if you are missing some delimeter/field seprator from database

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    18

    Re: More database querys!

    Thanks for reply,
    Sorry if I was a little vauge? Yes I have a custom database, basicaly I'm wanting to record animal id's and weights along with the date, I then want to be able to sort by wieght, ie animals between x kg and y kg. My first attempt involved using a bluetooth rfid reader to send the animal id to the phone, date via localtime and manualy entering the wieght when I read it from mechanical scales. I used the appuifw.query(u"Enter weight","number") function to enter the weight. Everything was saved in the database as a varchar type. This worked fine and I'm able to 'pick' animals from the database by weight. Its very longwinded to do though. So I put a load cell on the scales and sent the wieght to the phone via bluetooth, at the moment the scales send 5 asci characters ie 000.0 for 0kg. I'm able to save this in the database and view it if I look at the whole database, however if I try to sort by wieght it throws a wobbly! The only change to the programme is the removal of the query and replacement with a bluetooth input. I've stripped the input so the newline and any whitespace should be gone, is it because of the '.'? If no one realy knows I may have to play around with it for a while and try different ways of sending the wieght from my scales?

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,748

    Re: More database querys!

    Although I have no idea about what is crashing (is it crashing), the emphasis on 0-s and .-s can not matter. varchar stores strings, so ordering varchar data is expected to work on anything, including ' ', '0', '000.0', 'geoffers', 'mikkovtr', 'a.0', '0.a', '..', '00'. It just does not matter.
    Do you get any kind of error message, code, anything? Are you sure about that the sort operation dies?
    Unfortunately I do not know Python (reading this board only because it was moved here, into Symbian C++), but surrounding the line with some printing+fake input lines would be an approach to find out if the application really dies on that line.
    Other direction: have you limited the length of that varchar field in the database definition?

  5. #5
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    200

    Re: More database querys!

    hmm, I was supposed to ask if you are running a custom database engine but it appears that you are using e32db. Quite important detail I would say
    http://www.developer.nokia.com/Commu...ht=#post882606

    Are you running the program in python shell? Then you should get detailed error message that you could send here.

  6. #6
    Registered User
    Join Date
    Feb 2012
    Posts
    18

    Re: More database querys!

    Hi,
    Sorry I misunderstood you, yes thats right I'm using the e32db, I'm using the script shell to run the programme on a n70, when I try my search code the phone jumps back to the main menu, ie exits the script shell and the programme so I get no error message?
    Code:
    def sort():
        spc=(u" ")
        taglist=[]
        miny=appuifw.query(u"Min weight:","number")
        maxy=appuifw.query(u"Max weight:","number")
        db.open(u"e:\\Weight3.db")
        dbv.prepare(db,u"select * from weigh where weight >='%s' and weight<='%s'" %(miny,maxy))
        for i in range(1,dbv.count_line()+1):
                dbv.get_line()
                ear=(dbv.col(1))
                ear=ear.replace("826","")
                kg= (dbv.col(2))
                ear=ear+spc+kg
                taglist.append(ear)
                dbv.next_line()
        lentag=len(taglist)
        appuifw.popup_menu(taglist,u"No of animals:"+str(lentag))
        db.close()
    This is the bit of code I'm using to search.
    I wonder if it could be a bug in the n70? I also have a x6 so might try on that. Your quite right I removed the '.' and it made no difference.
    So I should be able to sort a list of strings into numerical order. No I havnt limeted the length of the vachar.
    Thanks to you both for looking
    Last edited by wizard_hu_; 2012-04-19 at 14:25. Reason: [CODE][/CODE] for preserving indentation

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,748

    Re: More database querys!

    You should develop incrementally, that is the preferred style for scripting languages anyway.
    First forget both the where clause and the loop, prepare a simple "select * from weigh", and try a single get_line, then print what comes from col(1). If it still works, try with col(2). If it does not work, you may consider a dbv.first_line().
    If it works, you can try a for loop, still with printing. Then add the where clause. It may be a good idea actually printing the select itself.

  8. #8
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    200

    Re: More database querys!

    By python shell I mean program which is installed from PythonScriptShell_2.0.0_XXX.sis and is shown as Python2.0.0 in menu. But do as wizard_hu says, try first the most basic version as possible and then increment.

  9. #9
    Registered User
    Join Date
    Feb 2012
    Posts
    18

    Re: More database querys!

    Thanks for looking again, sorry if I havn't made myself clear but the only difference in the two ways I have created the database's is in the first case I entered the value of the wieght manualy, using the phone keypad and appuifw.query(u"","number") function to create my database. The piece of code I posted works in this case. Ie I'm able to 'sort' my database and show only animals between a min and max wieght.
    In the second case I have put a wiegh cell on my scales, used a pic to interprate it and sent the data to the phone using a bluetooth module. Creating the database this way also works, ie I can view the database as a whole and know all my data is their. When I try to 'sort' the database if I enter 0 for the min a say 50 for the max (as long as no values are over 50) It shows the whole database. As soon as the min or max values are either min higher than 0 or max lower than the max wieght stored, the phone goes to the main menu. No error messages!
    I've been thinking about it today, to use the bluetooth readline function you have to send a newline character, as I now understand it the strip function only removes whitespace? Do I need to remove the newline character before the data is stored in the database?
    Thanks again, I am new to this so some of my explenations might not be very good!

  10. #10
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    200

    Re: More database querys!

    Quote Originally Posted by geoffers View Post
    In the second case I have put a wiegh cell on my scales, used a pic to interprate it and sent the data to the phone using a bluetooth module. Creating the database this way also works, ie I can view the database as a whole and know all my data is their. When I try to 'sort' the database if I enter 0 for the min a say 50 for the max (as long as no values are over 50) It shows the whole database. As soon as the min or max values are either min higher than 0 or max lower than the max wieght stored, the phone goes to the main menu. No error messages!
    The point was that you should simplify the program until it works. You can see it as one way of debugging.

    One question: Does the query return any line in the use case where program crashes? Add some debug prints directly after the query to see what you get. If your data type is varchar it's going to use alphabetical order and then anything 00XX is going to be before "normal" numbers. Wouldn't it be simpler to use numbers in database (integers, floats, doubles)? The you could do real sorting easily too.

    Quote Originally Posted by geoffers View Post
    I've been thinking about it today, to use the bluetooth readline function you have to send a newline character, as I now understand it the strip function only removes whitespace? Do I need to remove the newline character before the data is stored in the database?
    newlines are also whitespace.

  11. #11
    Registered User
    Join Date
    Feb 2012
    Posts
    18

    Re: More database querys!

    Thanks, I'll pop in some prints and try to find out where the programme crashes. Initialy I wanted to use a 'float' type for the wieght. I was unsure how to convert my ascii string into a interger though? I tried the int() function but got a exception, looked through the pys60 documentation but don't think I found any detials on it? It would be easy for me to change my pic programme to send the data as a 16bit number but I'm unsure how to handle that in python? Ascii seemed to be the best way to do it. I'm much more familiar with MPASM for the pics than python so it might be easier for me to change the format the data is sent in?
    Thanks again Geoff

  12. #12
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    200

    Re: More database querys!

    Language is still Python so use Python documentation and refer to pyS60 documentation when there are symbian specific things.

    http://docs.python.org/library/functions.html#float


    Code:
    >>> a = float("0002.2")
    >>> a 
    2.2

  13. #13
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,748

    Re: More database querys!

    Still no experience, but reading the documentation I have the impression that there are standard (I mean C/C++-like) format strings, like %05.1f (perhaps 6, I will never learn if the decimal dot counts or not).

  14. #14
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    200

    Re: More database querys!


  15. #15
    Registered User
    Join Date
    Feb 2012
    Posts
    18

    Re: More database querys!

    I've been fiddling again, the problem is two fold! I think I need to convert the data to a float before its saved, the select function doesn't like the two different types, if min=0 and max=1 I get the whole table, if min>0 I get nothing. This is the first problem.
    The second is in this line;
    for i in range(1,dbv.count_line()+1):
    If dbv.count_line() is 0 ie no lines selected, the programme crashes. I put a try: except: clause around it,

    try:
    for i in range(1,dbv.count_line()+1):
    dbv.get_line()
    ear=(dbv.col(1))
    ear=ear.replace("826","")
    kg= (dbv.col(2))
    ear=ear+spc+kg
    taglist.append(ear)
    dbv.next_line()
    lentag=len(taglist)
    appuifw.popup_menu(taglist,u"No of animals:"+str(lentag))
    db.close()
    except:
    appuifw.note(u"No record found")

    It still crashes! Should I be checking if dbv.count_line() is >0 before the loop? It would seem to be the only way around it?
    Regarding the float problem, this line gets the data from the bluetooth:

    msg = tag.readline() #gets tag from bt connection
    msg=msg.strip()
    Can I use the float function like this;

    msg=float(msg)

    or should it be

Similar Threads

  1. Replies: 28
    Last Post: 2011-04-20, 11:13
  2. difference between event database and todo database?
    By gracy in forum Mobile Java General
    Replies: 1
    Last Post: 2011-01-26, 10:44
  3. Replies: 4
    Last Post: 2009-12-19, 15:35
  4. How to communicate with a web database to read/write data from/to database.
    By kuddy_abc in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2009-08-08, 20:45
  5. Replies: 1
    Last Post: 2007-09-05, 10:53

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×