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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:03:03+00:00 2026-05-27T22:03:03+00:00

I have firmware version strings into my table (like 4.2.2 or 4.2.16) How can

  • 0

I have firmware version strings into my table (like “4.2.2” or “4.2.16”)

How can I compare, select or sort them ?

I cannot use standard strings comparison : “4.2.2” is a seen by SQL greater than “4.2.16”

As version strings, I would like 4.2.16 to be greater than 4.2.2

I would like to consider that firmware version can have chars in them : 4.24a1, 4.25b3 … for this, usually, the subfield with chars has a fixed length.

how to proceed ?

  • 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-27T22:03:03+00:00Added an answer on May 27, 2026 at 10:03 pm

    Finally, I found another way to sort version strings.

    I just justify the string before storing into de database in a way it is sortable.
    As I am using the python Django framework, I just have created a VersionField that ‘encode’ the version string while storing and ‘decode’ it while reading, so that it is totally transparent for the application :

    Here my code :

    The justify function :
    
    def vjust(str,level=5,delim='.',bitsize=6,fillchar=' '):
        """
        1.12 becomes : 1.    12
        1.1  becomes : 1.     1
        """
        nb = str.count(delim)
        if nb < level:
            str += (level-nb) * delim
        return delim.join([ v.rjust(bitsize,fillchar) for v in str.split(delim)[:level+1] ])
    
    The django VersionField :
    
    class VersionField(models.CharField) :
    
        description = 'Field to store version strings ("a.b.c.d") in a way it is sortable'
    
        __metaclass__ = models.SubfieldBase
    
        def get_prep_value(self, value):
            return vjust(value,fillchar=' ')
    
        def to_python(self, value):
            return re.sub('\.+$','',value.replace(' ',''))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a firmware for an USB module I can already control by visual
I have this query: $sql = SELECT * FROM tutorials WHERE ( device LIKE
I have an iPhone running the 3.1.2 firmware and would like to build applications
I need help with PHP PDO and SQLITE3. I have table device like CREATE
Any assembly interpreters out there? What I'm looking for: I have some assembly firmware
I finally have a hardware guy that is insterested in controlling the firmware. This
We have a Windows CE 6.0 based product that allows for firmware upgrades through
Have firmware disassmbled with IDA (ARM920 Core).. most is Thumb mode....some is ARM mode
I am working on C firmware project. I have a union that is defined
I have written a powerful trig calculator, but I want to use the linen

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.