Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7903355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:43:43+00:00 2026-06-03T09:43:43+00:00

I keep getting an error saying my value is not positioned on a valid

  • 0

I keep getting an error saying my value is not positioned on a valid record. I’ve executed my query successfully in MySQL, but I think I’m overlooking something in my code.

query = QtSql.QSqlQuery("select patient_id," +
                        "(SUM(IF(uom_id = 1, value, 0)) / SUM(IF(uom_id = 1, 1, 0))) AS `Average radius`," +
                        "(SUM(IF(uom_id = 2, value, 0)) / SUM(IF(uom_id = 2, 1, 0))) AS `Average Volume`," +
                        "(SUM(IF(uom_id = 3, value, 0)) / SUM(IF(uom_id = 3, 1, 0))) AS `Average SA`" +
                        "from measurements" +
                        "WHERE image_id = " + self.dbImage.id.toString() +
                        "AND status = 'A'" +
                        "GROUP BY patient_id", self.db)
query.next()

radius_acc = query.value(1).toDouble()
volume_acc = query.value(2).toDouble()
SA_acc = query.value(3).toDouble()

print('average of previously accepted measurements includes ' +
      'radius = ' + str(radius_acc) +
      'volume = ' + str(volume_acc) +
      'SA = ' + str(SA_acc))

Specifically I want to know if there is something wrong with the way I input the query to QSqlQuery? Or maybe I am trying to use the value(n) method incorrectly?

If neither of those appear to be the case I’ll bet I’m using the wrong parameter for self.dbImage.id.toString() in my query, in which case I’ll just ask a coworker tomorrow.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:43:44+00:00Added an answer on June 3, 2026 at 9:43 am

    To iterate over the result set you usually use a while loop:

     while(query.next()){
         // do whatever you need with query.value()
     }
    

    If you’re interested only in the first row, you can use first(), again with a while loop:

     while(query.first()){
         // do whatever you need with query.value()
     }
    

    Edit: Sorry, misunderstood your problem. Now I see that you possibly forgot to put some spaces in some strings:

     "from measurements"
    

    to

     " from measurements "
     #^ Here   and here ^^
    

    Without these spaces, your query will look something like

      "...d = 3, 1, 0))) AS `Average SA`from measurementsWHERE image_id = ..."
    

    which of course it’s not a valid query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to code some stuff for a game but I keep getting error
Keep getting this error after inserting a subdatasheet into a query and trying to
Keep getting the error Arguments are not sufficiently instantiated for the multiplication by addition
I keep getting this error when I try to commit a group of executed
I keep getting the error saying that the application.css isn't compiled. I tried: rake
I'm trying to call the dist() method however I keep getting a error saying
I can't find any info on this... I keep getting some error saying I
I'm trying to send an image via bluetooth, i keep getting an error saying
I keep getting an error saying that a specific column, doesn't exist for b.BookCode
With the following code, I keep getting error C2535 when I compile. It's complaining

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.