Uploaded image for project: 'MariaDB Connector/C++'
  1. MariaDB Connector/C++
  2. CONCPP-96

PreparedStatement SetDouble Drops Significant Digits

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 1.0.1, 1.1.0
    • 1.0.2, 1.1.2
    • General
    • None
    • Tested with mariadbcpp versions 1.0.1 and 1.0.0 on ubuntu 20.04

    Description

      Table for testing:

      CREATE TABLE `contracts` (
        `cost_as_dbl` decimal(15,4) NOT NULL DEFAULT 0.0000,
        `cost_as_str` varchar(20) NOT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
      

      C++ code for testing:

      #include "mariadb/conncpp.hpp"
      #include <memory>
       
      int
      main()
      {
        sql::Driver* driver = sql::mariadb::get_driver_instance();
        sql::SQLString url("jdbc:mariadb://localhost:3306/*****");
        sql::Properties properties(
          { { "user", "******" }, { "password", "********" } });
       
         std::unique_ptr<sql::Connection> conn(driver->connect(url, properties));
       
        double cost(98.765432109);
       
        std::unique_ptr<sql::PreparedStatement> pstmnt(
          conn->prepareStatement("INSERT INTO contracts (cost_as_dbl, cost_as_str) VALUES (?, ?);"));
       
        do {
          pstmnt->setDouble(1, cost);
          pstmnt->setString(2, std::to_string(cost));
          pstmnt->executeQuery();
          cost *= 10.0;
        } while (cost < 1000000000);
      }
      

      Query Output:

      MariaDB [test]> select * from contracts;
      +----------------+------------------+
      | cost_as_dbl    | cost_as_str      |
      +----------------+------------------+
      |        98.7654 | 98.765432        |
      |       987.6540 | 987.654321       |
      |      9876.5400 | 9876.543211      |
      |     98765.4000 | 98765.432109     |
      |    987654.0000 | 987654.321090    |
      |   9876540.0000 | 9876543.210900   |
      |  98765400.0000 | 98765432.109000  |
      | 987654000.0000 | 987654321.090000 |
      +----------------+------------------+
      8 rows in set (0.000 sec)
      

      pstmnt->setDouble only processes the first 6 significant digits and zeros the remaining.

      Attachments

        Activity

          People

            Lawrin Lawrin Novitsky
            jncox Joe C
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.