×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    7

    Reading user input to database..

    In the following link shows the inserting and retrieving of values to database,...

    http://wiki.forum.nokia.com/index.ph...n_Python_PyS60

    But I am asking whether i can insert value which is inputted through by asking to the user That is by any means of appuifw.query reading the values and inserting it into the database??? Plz reply if it can be done...

    Thank u

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Reading user input to database..

    Code:
    name = appuifw.query(u'Enter name', 'text')
    #From the article, slightly modified:
    db.execute(u"INSERT INTO test_table (name) VALUES ('%s')" % name)
    Last edited by bogdan.galiceanu; 2011-02-04 at 13:11.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    7

    Re: Reading user input to database..

    But showing error
    Could not insert data: <attribute 'args' of 'exceptions.BaseException' objects>
    <type 'exceptions.SymbianError'>
    [Errno -6] KErrArgument
    <traceback object at 0x19d87d8>

    what is the prob?? checked several possibilities,..
    thank u..

  4. #4
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Reading user input to database..

    Please post your code for creating the table and inserting into it.

  5. #5
    Registered User
    Join Date
    Oct 2010
    Posts
    7

    Re: Reading user input to database..

    I here post the entire code ,, I also checked by making the variable as global,.. but no way<<<>>
    Code:
    import e32db,sys,traceback,e32,appuifw
    
    #initiate db access
    db=e32db.Dbms()
    dbv=e32db.Db_view()
    dbname = u'e:\\python\\details.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 list (id counter, name 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
    def add():
    	try:
    		nme = appuifw.query(u'Enter name', 'text')
    		#From the article, slightly modified:
    		db.execute(u"INSERT INTO list (name) VALUES (%s)" % nme)
    		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
    def view():
    	try:
    		dbv.prepare(db,u'SELECT * FROM list')
    		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
    			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]
    def quit():
    	db.close() # close the database
    	app_lock.signal()
     
    appuifw.app.exit_key_handler=quit
    appuifw.app.menu = [(u"ADD", add),(u"VIEW", view), (u"Exit", quit)]#MENU
    app_lock=e32.Ao_lock()
    app_lock.wait()
    Last edited by shabiksd; 2011-02-04 at 16:20.

  6. #6
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Reading user input to database..

    Most likely the problem is the fact that, when being inserted into a table, a string needs to be surrounded by (single) quotes.
    Code:
    db.execute(u"INSERT INTO list (name) VALUES ('%s')" % nme)

  7. #7
    Registered User
    Join Date
    Oct 2010
    Posts
    7

    Re: Reading user input to database..

    ERROR in adding more than one parameters....

    Code:
                    nme = appuifw.query(u"Name:", 'text')
    		dtls = appuifw.query(u"Details :", 'text')
    		plc = appuifw.query(u"Place:", 'text')
    		#From the article, slightly modified:
    		db.execute(u"INSERT INTO list (name,details,place) VALUES ('%s','%s','%s')" % nme % dtls % plc )
    comma seperation not working,.....plz give any references where i can refer, if there,...
    THANK U VERY MUCH<>>>>
    Last edited by shabiksd; 2011-02-05 at 10:19.

  8. #8
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Reading user input to database..

    It should be ('%s','%s','%s')" % (nme, dtls, plc)

    This is a pretty basic thing about the Python language. The book "Beginning Python: From Novice to Professional" from Apress discusses it at length and has plenty of examples. And I'm sure you can find tutorials online too.

  9. #9
    Registered User
    Join Date
    Oct 2010
    Posts
    7

    Re: Reading user input to database..

    I have already checked this possibility also,.. It wont works, gives same error as i mentioned above,...

    Thank u,...

Similar Threads

  1. Can user input to simpletablemodel ???
    By gengisme in forum Mobile Java General
    Replies: 2
    Last Post: 2010-05-26, 03:36
  2. want to get user input
    By lokesh_kumar_s in forum Symbian
    Replies: 2
    Last Post: 2009-12-07, 08:37
  3. Appending user input to url
    By camilia90 in forum Symbian
    Replies: 1
    Last Post: 2009-11-10, 13:34
  4. How to input string from user?
    By RT22 in forum Symbian User Interface
    Replies: 4
    Last Post: 2008-05-07, 06:43

Posting Permissions

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