×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Oct 2007
    Location
    Brasil
    Posts
    39

    Python and database

    What is the correct way to write a SQL statement that returns only one record after a query. The line below me returning this error in a Python script.

    Exemple code:

    def searchdb():
    autor = appuifw.query(u"Insira Nome Autor","text")
    all_books = e32db.Db_view()
    all_books.prepare(db, u"SELECT * FROM books WHERE author ='autor'")
    all_books.first_line()
    for k in range(all_books.count_line()):
    all_books.get_line()
    print all_books.col(1),
    print all_books.col(2)
    all_books.next_line()



  2. #2
    Regular Contributor
    Join Date
    Apr 2007
    Location
    Lublin, Poland
    Posts
    81

    Re: Python and database

    So what exactly is the error? Can you paste it?

    The EXACT code like this certainly won't work, but SQL itself seems technically OK.
    A bit of advice,
    - paste your code in [ CODE ] tags, just select your code and click '#' from the menu in the editor,
    - you can keep the discussion on one thread, for example your first one
    whatever happens happens

  3. #3
    Registered User
    Join Date
    Oct 2007
    Location
    Brasil
    Posts
    39

    Question Re: Python and database

    Quote Originally Posted by janekw_ View Post
    So what exactly is the error? Can you paste it?

    The EXACT code like this certainly won't work, but SQL itself seems technically OK.
    A bit of advice,
    - paste your code in [ CODE ] tags, just select your code and click '#' from the menu in the editor,
    - you can keep the discussion on one thread, for example your first one
    ================

    The query does not return any results .... (! ?) Thanks

    def searchdb():
    autor = appuifw.query(u"Insira Nome Autor","text")
    all_books = e32db.Db_view()
    all_books.prepare(db, u"SELECT * FROM books WHERE author ='autor'")
    all_books.first_line()
    for k in range(all_books.count_line()):
    all_books.get_line()
    print all_books.col(1),
    print all_books.col(2)
    all_books.next_line()

  4. #4
    Regular Contributor
    Join Date
    Apr 2007
    Location
    Lublin, Poland
    Posts
    81

    Re: Python and database

    OK the most obvious is you're looking for an author named 'author' and not what you have in variable author So your prepare line should look like this:
    Code:
    all_books.prepare(db, u"SELECT * FROM books WHERE author='%s'" % author)
    whatever happens happens

  5. #5
    Registered User
    Join Date
    Oct 2007
    Location
    Brasil
    Posts
    39

    Thumbs up Re: Python and database

    Thanks, now that the consultation returning the expected result ..

  6. #6
    Registered User
    Join Date
    Nov 2007
    Posts
    2

    Question Re: Python and database

    I've also got a small problem with dbms. I'm trying to use like search condition:

    _tag=u"%" + _tag + u"%"
    querry = u"SELECT * FROM tags WHERE tag LIKE '%s'" % (_tag)
    bazaview.prepare(baza, querry)

    and it returns 0 rows :|
    the data is fine, it contains what i'm looking for
    when I print the querry it seems fine
    any ideas what might be the problem?

  7. #7
    Regular Contributor
    Join Date
    Apr 2007
    Location
    Lublin, Poland
    Posts
    81

    Re: Python and database

    Use '*' wildcard instead of '%'.
    like-predicate : column-name [ NOT ] LIKE pattern-value pattern-value : string-literal

    Test whether or not a text column matches a pattern string. The wildcard characters used in the pattern-value are not standard SQL, instead the wildcard characters are used: ? for matching any single character and * for matching zero or more characters. See the description of the TDesC::Match() function.
    whatever happens happens

  8. #8
    Registered User
    Join Date
    Nov 2007
    Posts
    2

    Re: Python and database

    thanks, now it works fine

  9. #9
    Registered User
    Join Date
    Oct 2007
    Location
    Brasil
    Posts
    39

    Question Re: Python and database

    Hello,

    What is the correct syntax for SQL statement below:


    autor = appuifw.query(u"Insira Nome Autor","text")
    all_books = e32db.Db_view()
    all_books.prepare(db, u"SELECT * FROM books WHERE author LIKE '%s'" % autor)
    all_books.first_line()
    ....

    Thanks
    Last edited by aldosilva; 2007-12-09 at 01:14.

Similar Threads

  1. Python and database
    By aldosilva in forum Symbian
    Replies: 3
    Last Post: 2008-03-26, 16:46
  2. python samples or tutorials?
    By francute in forum Symbian
    Replies: 2
    Last Post: 2006-08-03, 16:54
  3. python and database
    By xcode3x in forum Symbian
    Replies: 1
    Last Post: 2006-08-03, 06:02
  4. Replies: 1
    Last Post: 2006-05-30, 12:39
  5. how to begin with the database
    By ellamae in forum Symbian
    Replies: 4
    Last Post: 2006-03-23, 12:06

Posting Permissions

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