#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    13
    Rep Power
    0

    Python function to query database


    Hi,

    I'm starting to learn python and just finished my hello world version of the Flask framework a few days ago.

    Right now, I'm trying to create a simple web app that queries a database using sqlalchemy to count the total number. I'm relatively new to sqlalchemy and seem to be having trouble writing the queries.

    Let's use this example table, please take a look at the screenshot below:


    Normally, I would use this query in sql server to get what I want:

    So I'm trying to write a function that will give me the same results.. This is what I have so far, but its giving me sql errors...

    Note: I don't exactly remember what those errors are since the last time I ran them was in the school's computer center. I don't have the linux environment set up on my personal laptop yet. I will post them up when I have a chance!

    So I was hoping there is someone here who is familiar enough with python2.7 to see what I'm doing wrong (e.g syntax, etc)

    I hope it is okay to ask this type of question here
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,839
    Rep Power
    480
    Summary: did you assign a value to Device_os ? To Total_devices ?

    Welcome! Your code is syntax error free. I'm unfamiliar with sqlalchemy.

    You'll probably need to post more code. The most likely trouble is that
    Device_os
    hasn't been assigned a value yet. No way to tell without understanding a sufficient amount of the code leading up to your snippet.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    13
    Rep Power
    0
    I assigned values to the test database for Device_os.

    I've included a screenshot of table but for some reason it's not showing up in my post.

    edit: got the query to work

IMN logo majestic logo threadwatch logo seochat tools logo