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 8660409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:14:47+00:00 2026-06-12T16:14:47+00:00

I have nearly successfully made a query for MySQL via Python that shows the

  • 0

I have nearly successfully made a query for MySQL via Python that shows the most frequent datasets given the brand. The problem I am having is when I try to run the print row[1], row[2] command, it returns productnum instead of the space I want like product num. I tried doing print row[1], " ", row[2] but it doesn’t satisfy the test cases. Is there another way to get around this problem. I know this may not sound like an important question but it has been bugging me and it is this problem that is not passing the tests. The full code is below.

  • 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-12T16:14:48+00:00Added an answer on June 12, 2026 at 4:14 pm

    Please don’t create your SQL by concatenating strings. Pretend I’m an attacker and I call your function like:

    inject = "'; SELECT name,cardnum FROM credit_cards; --"
    most_popular(inject, 'LOL')
    

    Your code will helpfully expand that to:

    SELECT DISTINCT brand, product, COUNT(*) AS num FROM table1 WHERE brand = ''; SELECT * FROM credit_cards; --'" "GROUP BY product ORDER BY num desc, product asc LIMIT LOL
    

    and now your customers are suing you. Always, always use parameterized queries instead of building queries yourself. Change that cursor.execute() like to look like:

     cursor.execute("SELECT DISTINCT brand, product, COUNT(*) AS num FROM table1 WHERE brand = %s GROUP BY product ORDER BY num desc, product asc LIMIT %s", (brands, num_frequency))
    

    I’ve been writing DB libraries for years and the idea of trying to get this stuff right still terrifies me, mainly because the penalties for screwing it up are so severe. Let your database library do the hard work for you.

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

Sidebar

Related Questions

I have made a game which is nearly identical to Popcap's Atomica. ( http://www.popcap.com/gamepopup.php?theGame=atomica
I have nearly 45 UIButton s in my view, i know that the buttons
i have nearly 1 million data, which i definitely don't want to query all
I have a couple classes that have nearly identical code. Only a string or
I have created one project successfully with Cordova2.0 on iOS. That was the first
I have an application that I've been using xVal successfully on for quite some
In a recent project I have nearly completed we used an architecture that as
I have made nearly 20 PNG screen captures. I wish to glue them into
I have nearly 100 HTML files that uses the <tt> tag to markup inline
I have nearly completed my .htaccess file now so that my urls all work

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.