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

  • Home
  • SEARCH
  • 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 3331870
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:37:43+00:00 2026-05-17T23:37:43+00:00

I am very new to working with SQL queries. Any suggestions to improve this

  • 0

I am very new to working with SQL queries. Any suggestions to improve this bit of code:
(by the way, I really don’t care about sql security here; this is a bit of code that will be in a pyexe file connecting to a local sqlite file – so it doesnt make sense to worry about security of the query here).

def InitBars(QA = "GDP1POP1_20091224_gdp", QB = "1 pork", reset = False):
    global heights, values
    D, heights, values, max, = [], {}, {}, 0.0001

    if reset: GHolder.remove()

    Q = "SELECT wbcode, Year, "+QA+" FROM DB WHERE commodity='"+QB+"' and "+QA+" IS NOT 'NULL'"  

    for i in cursor.execute(Q): 
        D.append((str(i[0]) + str(i[1]), float(i[2])))
        if float(i[2]) > max: max = float(i[2])

    for (i, n) in D: heights[i] = 5.0 / max * n; values[i] = n
    Gui["YRBox_Slider"].set(0.0)  
    Gui["YRBox_Speed"].set(0.0)

after following the advices, this is what I got:

def InitBars(QA = "GDP1POP1_20091224_gdp", QB = "1 pork", reset = False):
    global heights, values; D, heights, values, max, = [], {}, {}, 0.0001
    if reset: GHolder.remove()

    Q = "SELECT wbcode||Year, %s FROM DB WHERE commodity='%s' and %s IS NOT 'NULL'" % (QA, QB, QA) 
    for a, b in cursor.execute(Q): 
        if float(b) > max: max = float(b)
        values[a] = float(b)

    for i in values: heights[i] = 5.0 / max * values[i]

    Gui["YRBox_Slider"].set(0.0); Gui["YRBox_Speed"].set(0.0)
  • 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-05-17T23:37:43+00:00Added an answer on May 17, 2026 at 11:37 pm

    If this is a one-off script where you totally trust all of the input data and you just need to get a job done, then fine.

    If this is part of a system, and this is indicative of the kind of code in it, there are several problems:

    1. Don’t construct SQL queries by appending strings. You said that you don’t care about security, but this is such a big problem and so easily solved, then really — you should do it right all of the time

    2. This function seems to use and manipulate global state. Again, if this is a small one-time use script, then go for it — in systems that span just a few files, this becomes impossible to maintain.

    3. Naming conventions — not following any consistency in capitalization

    4. Names of things are not helpful at all. QA, D, QB, — QA and QB don’t even seem to be the same kind of thing — one is a field, and the other is a value.

    5. All kinds of questionable things are uncommented — why is max .0001? What the heck is GHolder? What could that loop be doing at the end? Really, the code should be clearer, but if not, throw the maintainer a bone.

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

Sidebar

Related Questions

I still very new using Subversion. Is it possible to have a working copy
Im very new to SQL but need to write a query to do the
Warning - I am very new to NHibernate. I know this question seems simple
I'm very new to silverlight and I'm thikning which way to go. I'm in
I know that NoSQL databases are very new. I am also new in this
I'm working with SQL Server Reporting Services 2008, which is somewhat new to me,
I'm working on a database heavy project, where the Microsoft SQL databases are very
I'm very new to MySQL, although I've used SQL databases in other contexts before.
I'm very very new on ActionScript 3.0 development for Blackberry Playbook. I'm working with
Im very new to the WPF and MVVM (this is my 1st project in

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.