Main   Products   Offshore Outsourcing   Customers   Partners   ContactUs  
JDBC Databases
  HXTT Access v7.1
  HXTT Cobol v5.0
  HXTT DBF v7.1
 
  Buy Now
  Support
  Download
  Document
  FAQ
  HXTT Excel v6.1
  HXTT Json v1.0
  HXTT Paradox v7.1
  HXTT PDF v2.0
  HXTT Text(CSV) v7.1
  HXTT Word v1.1
  HXTT XML v4.0
Offshore Outsourcing
Free Resources
  Firewall Tunneling
  Search Indexing Robot
  Conditional Compilation
  Password Recovery for MS Access
  Password Recovery for Corel Paradox
  Checksum Tool for MD5
  Character Set Converter
  Pyramid - Poker of ZYH
   
   
   
Heng Xing Tian Tai Lab of Xi'an City (abbr, HXTT)

HXTT DBF
Precision Lost
Fernando Hartmann
2008-12-10 11:13:00


We have a strange problem happening here, if We execute the following command using the last version available o HXTT

SELECT sum(F8)/sum(F5) as VAL, f4 FROM tablex WHERE F4 = 'ROGER VARGAS' group by f4

We get the following response

1.0303073128547828

With the following command (same but without the group by)

SELECT sum(F8)/sum(F5) as VAL FROM tablex WHERE F4 = 'ROGER VARGAS'

We get the following result

1.03


The precision of the division was lost !

The structure of the DBF is

F4 Character 20 Asc Machine Yes
F5 Numeric 15 2 Yes
F8 Numeric 12 2 Yes


You can see the problem running the following code

package javaapplication1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;

public class RoundError {

public static void execute(String label, Connection con, String sql) throws SQLException, ParseException {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
System.out.println("\n"+label+"\n--------------------------------------------------------------");
for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
System.out.print(rs.getMetaData().getColumnName(i + 1) + "(" + rs.getMetaData().getColumnTypeName(i + 1) + ")\t");
}
System.out.println("\n--------------------------------------------------------------");
while (rs.next()) {
for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
System.out.print(rs.getObject(i+1)+"\t");
}
System.out.println("");
}
System.out.println("--------------------------------------------------------------");
stmt.close();
}

public static void main(String[] args) throws Exception {
String connectionUrl;
Connection con;
connectionUrl = "jdbc:DBF:/C:/temp";
Class.forName("com.hxtt.sql.dbf.DBFDriver");
con = DriverManager.getConnection(connectionUrl);
String sql = "SELECT sum(F8)/sum(F5) as VAL FROM tablex WHERE F4 = 'ROGER VARGAS'";
execute("without group by", con, sql);
sql = "SELECT sum(F8)/sum(F5) as VAL, f4 FROM tablex WHERE F4 = 'ROGER VARGAS' group by f4";
execute("with group by", con, sql);
con.close();
}
}




The result is


without group by
--------------------------------------------------------------
VAL(DOUBLE)
--------------------------------------------------------------
1.03
--------------------------------------------------------------

with group by
--------------------------------------------------------------
VAL(DOUBLE) F4(VARCHAR)
--------------------------------------------------------------
1.0303073128547828 ROGER VARGAS
--------------------------------------------------------------


Thanks for your attention













Re:Precision Lost
HXTT Support
2008-12-11 01:30:59
Checked. That was resulted by using the column precision information. Fixed. Please download the latest package. Thanks.
Re:Re:Precision Lost
Fernando Hartmann
2008-12-11 08:53:30
Just tried the new version, and now its work right.
Thanks for your quick help.

Search Key   Search by Last 50 Questions




Google
 

Email: webmaster@hxtt.com
Copyright © 2003-2019 Heng Xing Tian Tai Lab of Xi'an City. | All Rights Reserved. | Privacy | Legal | Refund | Sitemap