×

Discussion Board

Results 1 to 5 of 5

Thread: database error

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    21

    database error

    i am using this code to insert values

    a=19.77777034
    b=72.99903340
    into database

    I'm getting a base exception error...how to handle that??
    thnx in advance

    i also tried by using number insted of varchar in creating table part of the code
    but dint worked
    how to enter such big values into database plz help

    Code:
    import e32db,sys,traceback
     
    #initiate db access
    db=e32db.Dbms()
    dbv=e32db.Db_view()
     
    # name of the database file
    dbname = u'e:\\python\\testdatabase.db'
     
    #open database, if it does not exist, then create it
    try:
      db.open(dbname)
    except:
      db.create(dbname)
      db.open(dbname)
     
     
    #Create the database table
    try:
      # note that the id field is auto-incremented when new rows are added
      db.execute(u"CREATE TABLE test_table (id counter, forename VARCHAR, surname VARCHAR)")
      print "Table Created"
    except SymbianError:
      print "Error Creating table: "
      #print traceback.format_exception(*sys.exc_info())
      print sys.exc_info()[0]
      print sys.exc_info()[1]
      print sys.exc_info()[2]
     
    # attempt to insert data
    try:
      # note that the id field is NOT required, as it auto-increments
      a=19.77777034
      b=72.99903340
      db.execute(u"INSERT INTO test_table (forename, surname) VALUES(a,b)")
      print "Data Inserted"
    except SymbianError:
      print "Could not insert data: ", SymbianError.args
      print sys.exc_info()[0]
      print sys.exc_info()[1]
      print sys.exc_info()[2]
     
     
     
     
    #to fetch the whole dataset
    try:
      dbv.prepare(db,u'SELECT * FROM test_table')
      for i in range(1,dbv.count_line()+1): #1 to number of rows
        dbv.get_line() #grabs the current row
        for i in range(1,dbv.col_count()+1):
          print dbv.col(i) #prints each column data
          if dbv.col(i)=='joe':
             print ' i am joe'
        dbv.next_line() #move to the next rowset[[Category:Entertainment]]
    except SymbianError:
      print "failed to read database: "
      print sys.exc_info()[0]
      print sys.exc_info()[1]
      print sys.exc_info()[2]
     
    # close the database
    db.close()

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: database error

    Could you please post the exact error message?

    If I had to guess, Id' say the problem is in the line
    Code:
    db.execute(u"INSERT INTO test_table (forename, surname) VALUES(a,b)")
    It should be
    Code:
    db.execute(u"INSERT INTO test_table (forename, surname) VALUES(" + str(a) + "," + str(b) +")")

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    21

    Re: database error

    ok i will try this but this will store values as strings
    i want it to be numbrs only because in my futrher part i want to compare those values
    so my main question is that using the code mentioned below how can i insert values like 12.99990003
    into data base

  4. #4
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: database error

    Try it. I think it will insert the numbers

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    21

    Re: database error

    i tried it but it gives error like

    Table Created
    Could not insert data
    <attribute 'args' of 'exceptions.BaseException' objects>
    <type 'exceptions.SymbianError'>
    [Errno -2 ] KErrGeneral
    <traceback object at 0x1767418>

Similar Threads

  1. Database Create Error
    By deepak59 in forum Symbian C++
    Replies: 7
    Last Post: 2010-03-17, 12:02
  2. Perst database : Error
    By rasmi in forum Mobile Java General
    Replies: 1
    Last Post: 2009-11-18, 01:59
  3. database error
    By lopesrohan1988 in forum Symbian User Interface
    Replies: 3
    Last Post: 2009-02-23, 09:39
  4. Database error meaning
    By yajuvendra in forum Symbian C++
    Replies: 5
    Last Post: 2006-03-13, 04:20
  5. database key error
    By mayankkedia in forum Symbian C++
    Replies: 0
    Last Post: 2004-09-24, 09:21

Posting Permissions

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