QStringParser::formatArg bug

Discuss anything related to product development
Post Reply
seasoned_geek
Posts: 254
Joined: Thu Jun 11 2020 12:18 pm

QStringParser::formatArg bug

Post by seasoned_geek »

While you don't need the entirety of the code this:

Code: Select all

    cmd = "INSERT INTO THEME_COLORS( THEME_NAME, STYLE_NO, FONT_NAME, POINT_SIZE, WEIGHT, ITALIC, "
          "UNDERLINE, FORE_RED, FORE_BLUE, FORE_GREEN, FORE_ALPHA, BACK_RED, BACK_BLUE, BACK_GREEN, BACK_ALPHA, "
          "EOL_FILLED, DISPLAYED_CASE, VISIBLE, CHANGEABLE) "
          "VALUES( '%1', %2, '%3', %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14, %14, %15, %16, %17, %18, %19 ) "
          "ON CONFLICT DO UPDATE SET FONT_NAME = '%3', POINT_SIZE = %4, WEIGHT = %5, ITALIC = %6, UNDERLINE = %7, "
          "FORE_RED = %8, FORE_BLUE = %9, FORE_GREEN = %10, FORE_ALPHA = %11, BACK_RED = %12, BACK_BLUE = %13, "
          "BACK_GREEN = %14, BACK_ALPHA = %15, EOL_FILLED = %16, DISPLAYED_CASE = %17, VISIBLE = %18, "
          "CHANGEABLE = %19 ;";

    cmd = QStringParser::formatArg( cmd, m_ui->themeCB->currentText() );
    cmd = QStringParser::formatArg( cmd, style );
    cmd = QStringParser::formatArg( cmd, m_ui->fontNameLE->text() );
    cmd = QStringParser::formatArg( cmd, m_ui->pointSpin->value() );

    if ( m_ui->boldCKB->isChecked() )
    {
        cmd = QStringParser::formatArg( cmd, 700 );
    }
    else
    {
        cmd = QStringParser::formatArg( cmd, 400 );
    }

    cmd = QStringParser::formatArg( cmd, m_ui->italicCKB->isChecked() );
    cmd = QStringParser::formatArg( cmd, m_ui->underlineCKB->isChecked() );
With the rest of the values naturally filled in will product this:

Code: Select all

INSERT INTO THEME_COLORS( THEME_NAME, STYLE_NO, FONT_NAME, POINT_SIZE, WEIGHT, ITALIC, UNDERLINE, FORE_RED, FORE_BLUE, FORE_GREEN, FORE_ALPHA, BACK_RED, BACK_BLUE, BACK_GREEN, BACK_ALPHA, EOL_FILLED, DISPLAYED_CASE, VISIBLE, CHANGEABLE) VALUES( 'COBALT', 6, '', %444444444444444444, %555555555555555555, %666666666666666666, %777777777777777777, %888888888888888888, %999999999999999999, 1770000000, 25511111111, 255222222222, 2553333333333, 25544444444444, 25544444444444, 255555555555555, 06666666666666, 077777777777777, 0888888888888888, 19999999999999999) ON CONFLICT DO UPDATE SET FONT_NAME = '', POINT_SIZE = 10, WEIGHT = 400, ITALIC = 0, UNDERLINE = 0, FORE_RED = 54, FORE_BLUE = 16, FORE_GREEN = 177, FORE_ALPHA = 255, BACK_RED = 255, BACK_BLUE = 255, BACK_GREEN = 255, BACK_ALPHA = 255, EOL_FILLED = 0, DISPLAYED_CASE = 0, VISIBLE = 0, CHANGEABLE = 1 ;
I'm having to cheat with QStringParser because of the previously reported QSqlQuery::Prepare bug and string handling.

According to this doc:
https://www.copperspice.com/docs/cs_api/class_qstringparser.html#af594bd3f83799c05b5143bb3e1c242d9

It is supposed to support up to 99 elements and support them repeating. It looks like only the first 3 can successfully repeat and after that the wheels come off the cart.
ansel
Posts: 153
Joined: Fri Apr 10 2015 8:23 am

Re: QStringParser::formatArg bug

Post by ansel »

You are correct that you can have placeholders with numbers between 1 and 99. However, our documentation does not say anything about supporting duplicate or repeated usage of placeholder numbers. When we implemented QStringParser this was not a feature we considered implementing. We are happy to file this as a feature request if you would like.
Ansel Sermersheim
CopperSpice Cofounder
barbara
Posts: 452
Joined: Sat Apr 04 2015 2:32 am
Contact:

Re: QStringParser::formatArg bug

Post by barbara »

Interesting update on this issue! We found a different problem when specifying "%2 %1" and correcting for this added support for having repeated usage of a place holder like "%1 %2 %3 %4 %3".

This change was added at the eleventh hour and is in the new CS 1.7.4 release which came out yesterday, on April 27 2022.

Barbara
seasoned_geek
Posts: 254
Joined: Thu Jun 11 2020 12:18 pm

Re: QStringParser::formatArg bug

Post by seasoned_geek »

Thank you.

Duplicates were always allowed in Qt. They seemed to work up to 3 in CopperSpice. Nice to know they work once again.
Post Reply